diff mbox

[variant,1] drm: make drm_get_format_name atomic/irq safe again

Message ID 20161104173322.20594-1-eric.engestrom@imgtec.com (mailing list archive)
State New, archived
Headers show

Commit Message

Eric Engestrom Nov. 4, 2016, 5:33 p.m. UTC
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 mbox

Patch

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);