mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH variant 1] drm: make drm_get_format_name atomic/irq safe again
       [not found] <20161104173224.GJ25290@imgtec.com>
@ 2016-11-04 17:33 ` Eric Engestrom
  0 siblings, 0 replies; only message in thread
From: Eric Engestrom @ 2016-11-04 17:33 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ville Syrjälä,
	Rob Clark, Eric Engestrom, David Airlie, dri-devel

Fixes: 90844f00049e9f42573fd31d7c32e8fd31d3fd07

    drm: make drm_get_format_name thread-safe

    Signed-off-by: Eric Engestrom <eric@engestrom.ch>
    [danvet: Clarify that the returned pointer must be freed with
    kfree().]
    Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>

Note (Rob Clark):
I think we need to be a bit careful about follow-up audits of callers of
this..  now that you need to kfree the return value I think it is fairly
easy for new patches to introduce new callers which leak the return
value.  We probably should have left the function as-is and introduce
a new variant, or something like that.

Suggested-by: Rob Clark <robdclark@gmail.com> (GFP_ATOMIC)
Suggested-by: Ville Syrjälä <ville.syrjala@linux.intel.com> (kasprintf)
Signed-off-by: Eric Engestrom <eric.engestrom@imgtec.com>
---

I'll send another variant tonight that moves the allocation to the
callers (sounds cleaner to me, although there'll be some code
duplication and more opportunities to make mistakes I guess).

---
 drivers/gpu/drm/drm_fourcc.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index 29c56b4..66dcf21 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -87,9 +87,7 @@ EXPORT_SYMBOL(drm_mode_legacy_fb_format);
  */
 char *drm_get_format_name(uint32_t format)
 {
-	char *buf = kmalloc(32, GFP_KERNEL);
-
-	snprintf(buf, 32,
+	return kasprintf(GFP_ATOMIC,
 		 "%c%c%c%c %s-endian (0x%08x)",
 		 printable_char(format & 0xff),
 		 printable_char((format >> 8) & 0xff),
@@ -97,8 +95,6 @@ char *drm_get_format_name(uint32_t format)
 		 printable_char((format >> 24) & 0x7f),
 		 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
 		 format);
-
-	return buf;
 }
 EXPORT_SYMBOL(drm_get_format_name);
 
-- 
Cheers,
  Eric

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-11-04 17:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20161104173224.GJ25290@imgtec.com>
2016-11-04 17:33 ` [PATCH variant 1] drm: make drm_get_format_name atomic/irq safe again Eric Engestrom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome