dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Eric Engestrom <eric.engestrom@imgtec.com>
To: linux-kernel@vger.kernel.org
Cc: "Ville Syrjälä" <ville.syrjala@linux.intel.com>,
	"Rob Clark" <robdclark@gmail.com>,
	"Eric Engestrom" <eric.engestrom@imgtec.com>,
	"David Airlie" <airlied@linux.ie>,
	dri-devel@lists.freedesktop.org
Subject: [PATCH variant 1] drm: make drm_get_format_name atomic/irq safe again
Date: Fri, 4 Nov 2016 17:33:22 +0000	[thread overview]
Message-ID: <20161104173322.20594-1-eric.engestrom@imgtec.com> (raw)
In-Reply-To: <20161104173224.GJ25290@imgtec.com>

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

  reply	other threads:[~2016-11-04 17:33 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-04 15:32 [PATCH] drm: make drm_get_format_name atomic/irq safe again Rob Clark
2016-11-04 15:45 ` Rob Clark
2016-11-04 16:27 ` Ville Syrjälä
2016-11-04 17:12   ` Rob Clark
2016-11-04 17:32     ` Eric Engestrom
2016-11-04 17:33       ` Eric Engestrom [this message]
2016-11-04 17:50       ` Rob Clark
2016-11-04 18:13         ` Ville Syrjälä
2016-11-05  1:23         ` Eric Engestrom
2016-11-05  1:33           ` [PATCH] drm: move allocation out of drm_get_format_name() Eric Engestrom
2016-11-05  6:56             ` Thomas Hellstrom
2016-11-05 12:11             ` Christian König
2016-11-05 16:38               ` Eric Engestrom
2016-11-05 16:49                 ` Rob Clark
2016-11-06  9:47                   ` Christian König
2016-11-06 13:03                     ` Rob Clark
2016-11-07  0:47                       ` Eric Engestrom
2016-11-07  0:48                         ` [PATCH v2] " Eric Engestrom
2016-11-07  7:46                           ` Christian König
2016-11-07  8:10                           ` Jani Nikula
2016-11-07 17:12                             ` Eric Engestrom
2016-11-07 17:38                               ` Jani Nikula
2016-11-08 10:15                                 ` [Intel-gfx] " Daniel Vetter
2016-11-09  0:17                                   ` [PATCH v3] " Eric Engestrom
2016-11-09  1:09                                     ` [Intel-gfx] " Daniel Vetter
2016-11-09  1:13                                       ` Daniel Vetter
2016-11-09 11:42                                         ` Eric Engestrom
2016-11-09 13:13                                           ` [Intel-gfx] " Daniel Vetter
2016-11-09 16:59                                             ` Eric Engestrom
2016-11-10 10:03                                               ` Laurent Pinchart
2016-11-10 10:30                                                 ` [Intel-gfx] " Jani Nikula
2016-11-10 10:59                                                   ` Laurent Pinchart
2016-11-10 11:03                                                     ` Jani Nikula
2016-11-11  9:26                                               ` Daniel Vetter
2016-11-12  1:12                                                 ` [PATCH v4] " Eric Engestrom
2016-11-07 14:45                           ` [PATCH v2] " Rob Clark
2016-11-07 18:12                           ` Sinclair Yeh
2016-11-05  1:52           ` [PATCH] drm: make drm_get_format_name atomic/irq safe again Rob Clark

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161104173322.20594-1-eric.engestrom@imgtec.com \
    --to=eric.engestrom@imgtec.com \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robdclark@gmail.com \
    --cc=ville.syrjala@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).