All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Engestrom <eric.engestrom@imgtec.com>
To: Colin King <colin.king@canonical.com>
Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/atomic: fix memory leak when fetching format name
Date: Fri, 11 Nov 2016 17:17:49 +0000	[thread overview]
Message-ID: <20161111171749.GA6891@imgtec.com> (raw)
In-Reply-To: <20161111162622.21119-1-colin.king@canonical.com>

On Friday, 2016-11-11 16:26:22 +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> drm_get_format_name allocates memory that is not currently free'd
> when printing the state. Fix this by kfree'ing the memory after
> use.

You are correct, but there are more cases of this, and another fix
has been chosen. See this patch [1] for the fix and the rest of that
thread [2] for the discussion.

I'll send v4 (rebase and a missed `const`) as soon as I have the time,
but the usage will remain the same as in v3.

Cheers,
  Eric

[1] https://lists.freedesktop.org/archives/dri-devel/2016-November/123250.html
[2] https://lists.freedesktop.org/archives/dri-devel/2016-November/thread.html#122845

> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/gpu/drm/drm_atomic.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index f5ea7db..1d5e86a 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -917,9 +917,10 @@ static void drm_atomic_plane_print_state(struct drm_printer *p,
>  	if (state->fb) {
>  		struct drm_framebuffer *fb = state->fb;
>  		int i, n = drm_format_num_planes(fb->pixel_format);
> +		char *format_name = drm_get_format_name(fb->pixel_format);
>  
> -		drm_printf(p, "\t\tformat=%s\n",
> -				drm_get_format_name(fb->pixel_format));
> +		drm_printf(p, "\t\tformat=%s\n", format_name);
> +		kfree(format_name);
>  		drm_printf(p, "\t\tsize=%dx%d\n", fb->width, fb->height);
>  		drm_printf(p, "\t\tlayers:\n");
>  		for (i = 0; i < n; i++) {
> -- 
> 2.10.2
> 
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

WARNING: multiple messages have this Message-ID (diff)
From: Eric Engestrom <eric.engestrom@imgtec.com>
To: Colin King <colin.king@canonical.com>
Cc: David Airlie <airlied@linux.ie>,
	<dri-devel@lists.freedesktop.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] drm/atomic: fix memory leak when fetching format name
Date: Fri, 11 Nov 2016 17:17:49 +0000	[thread overview]
Message-ID: <20161111171749.GA6891@imgtec.com> (raw)
In-Reply-To: <20161111162622.21119-1-colin.king@canonical.com>

On Friday, 2016-11-11 16:26:22 +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> drm_get_format_name allocates memory that is not currently free'd
> when printing the state. Fix this by kfree'ing the memory after
> use.

You are correct, but there are more cases of this, and another fix
has been chosen. See this patch [1] for the fix and the rest of that
thread [2] for the discussion.

I'll send v4 (rebase and a missed `const`) as soon as I have the time,
but the usage will remain the same as in v3.

Cheers,
  Eric

[1] https://lists.freedesktop.org/archives/dri-devel/2016-November/123250.html
[2] https://lists.freedesktop.org/archives/dri-devel/2016-November/thread.html#122845

> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/gpu/drm/drm_atomic.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index f5ea7db..1d5e86a 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -917,9 +917,10 @@ static void drm_atomic_plane_print_state(struct drm_printer *p,
>  	if (state->fb) {
>  		struct drm_framebuffer *fb = state->fb;
>  		int i, n = drm_format_num_planes(fb->pixel_format);
> +		char *format_name = drm_get_format_name(fb->pixel_format);
>  
> -		drm_printf(p, "\t\tformat=%s\n",
> -				drm_get_format_name(fb->pixel_format));
> +		drm_printf(p, "\t\tformat=%s\n", format_name);
> +		kfree(format_name);
>  		drm_printf(p, "\t\tsize=%dx%d\n", fb->width, fb->height);
>  		drm_printf(p, "\t\tlayers:\n");
>  		for (i = 0; i < n; i++) {
> -- 
> 2.10.2
> 

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

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-11 16:26 [PATCH] drm/atomic: fix memory leak when fetching format name Colin King
2016-11-11 17:17 ` Eric Engestrom [this message]
2016-11-11 17:17   ` Eric Engestrom

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=20161111171749.GA6891@imgtec.com \
    --to=eric.engestrom@imgtec.com \
    --cc=colin.king@canonical.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.