All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Deucher, Alexander" <Alexander.Deucher@amd.com>
To: "Wentland, Harry" <Harry.Wentland@amd.com>,
	Yongzhi Liu <lyz_cs@pku.edu.cn>,
	"Li, Sun peng (Leo)" <Sunpeng.Li@amd.com>,
	"Siqueira, Rodrigo" <Rodrigo.Siqueira@amd.com>,
	"Koenig, Christian" <Christian.Koenig@amd.com>,
	"Pan, Xinhui" <Xinhui.Pan@amd.com>,
	"airlied@linux.ie" <airlied@linux.ie>,
	"daniel@ffwll.ch" <daniel@ffwll.ch>,
	"Lipski, Mikita" <Mikita.Lipski@amd.com>,
	"Lin, Wayne" <Wayne.Lin@amd.com>,
	"Kazlauskas, Nicholas" <Nicholas.Kazlauskas@amd.com>,
	"Zuo, Jerry" <Jerry.Zuo@amd.com>,
	"Anson.Jacob@amd.com" <Anson.Jacob@amd.com>,
	"eryk.brol@amd.com" <eryk.brol@amd.com>,
	"Pillai, Aurabindo" <Aurabindo.Pillai@amd.com>,
	"Das, Nirmoy" <Nirmoy.Das@amd.com>
Cc: "dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"amd-gfx@lists.freedesktop.org" <amd-gfx@lists.freedesktop.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] drm/amd/display: Fix memory leak
Date: Fri, 21 Jan 2022 20:51:21 +0000	[thread overview]
Message-ID: <BL1PR12MB51446C0B85C39EFC113FED14F75B9@BL1PR12MB5144.namprd12.prod.outlook.com> (raw)
In-Reply-To: <51258cfb-c3d4-ade3-0195-54835445d321@amd.com>

[-- Attachment #1: Type: text/plain, Size: 9598 bytes --]

[Public]

Applied.  Thanks!
________________________________
From: Wentland, Harry <Harry.Wentland@amd.com>
Sent: Friday, January 21, 2022 2:03 PM
To: Yongzhi Liu <lyz_cs@pku.edu.cn>; Li, Sun peng (Leo) <Sunpeng.Li@amd.com>; Siqueira, Rodrigo <Rodrigo.Siqueira@amd.com>; Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian <Christian.Koenig@amd.com>; Pan, Xinhui <Xinhui.Pan@amd.com>; airlied@linux.ie <airlied@linux.ie>; daniel@ffwll.ch <daniel@ffwll.ch>; Lipski, Mikita <Mikita.Lipski@amd.com>; Lin, Wayne <Wayne.Lin@amd.com>; Kazlauskas, Nicholas <Nicholas.Kazlauskas@amd.com>; Zuo, Jerry <Jerry.Zuo@amd.com>; Anson.Jacob@amd.com <Anson.Jacob@amd.com>; eryk.brol@amd.com <eryk.brol@amd.com>; Pillai, Aurabindo <Aurabindo.Pillai@amd.com>; Das, Nirmoy <Nirmoy.Das@amd.com>
Cc: amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>; dri-devel@lists.freedesktop.org <dri-devel@lists.freedesktop.org>; linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] drm/amd/display: Fix memory leak

On 2022-01-21 06:26, Yongzhi Liu wrote:
> [why]
> Resource release is needed on the error handling path
> to prevent memory leak.
>
> [how]
> Fix this by adding kfree on the error handling path.
>
> Signed-off-by: Yongzhi Liu <lyz_cs@pku.edu.cn>

Reviewed-by: Harry Wentland <harry.wentland@amd.com>

Harry

> ---
>  .../drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c  | 80 ++++++++++++++++------
>  1 file changed, 60 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
> index ded64d0..e463d46 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
> @@ -227,8 +227,10 @@ static ssize_t dp_link_settings_read(struct file *f, char __user *buf,
>                        break;
>
>                r = put_user(*(rd_buf + result), buf);
> -             if (r)
> +             if (r) {
> +                     kfree(rd_buf);
>                        return r; /* r = -EFAULT */
> +             }
>
>                buf += 1;
>                size -= 1;
> @@ -389,8 +391,10 @@ static ssize_t dp_phy_settings_read(struct file *f, char __user *buf,
>                        break;
>
>                r = put_user((*(rd_buf + result)), buf);
> -             if (r)
> +             if (r) {
> +                     kfree(rd_buf);
>                        return r; /* r = -EFAULT */
> +             }
>
>                buf += 1;
>                size -= 1;
> @@ -1359,8 +1363,10 @@ static ssize_t dp_dsc_clock_en_read(struct file *f, char __user *buf,
>                                break;
>        }
>
> -     if (!pipe_ctx)
> +     if (!pipe_ctx) {
> +             kfree(rd_buf);
>                return -ENXIO;
> +     }
>
>        dsc = pipe_ctx->stream_res.dsc;
>        if (dsc)
> @@ -1376,8 +1382,10 @@ static ssize_t dp_dsc_clock_en_read(struct file *f, char __user *buf,
>                        break;
>
>                r = put_user(*(rd_buf + result), buf);
> -             if (r)
> +             if (r) {
> +                     kfree(rd_buf);
>                        return r; /* r = -EFAULT */
> +             }
>
>                buf += 1;
>                size -= 1;
> @@ -1546,8 +1554,10 @@ static ssize_t dp_dsc_slice_width_read(struct file *f, char __user *buf,
>                                break;
>        }
>
> -     if (!pipe_ctx)
> +     if (!pipe_ctx) {
> +             kfree(rd_buf);
>                return -ENXIO;
> +     }
>
>        dsc = pipe_ctx->stream_res.dsc;
>        if (dsc)
> @@ -1563,8 +1573,10 @@ static ssize_t dp_dsc_slice_width_read(struct file *f, char __user *buf,
>                        break;
>
>                r = put_user(*(rd_buf + result), buf);
> -             if (r)
> +             if (r) {
> +                     kfree(rd_buf);
>                        return r; /* r = -EFAULT */
> +             }
>
>                buf += 1;
>                size -= 1;
> @@ -1731,8 +1743,10 @@ static ssize_t dp_dsc_slice_height_read(struct file *f, char __user *buf,
>                                break;
>        }
>
> -     if (!pipe_ctx)
> +     if (!pipe_ctx) {
> +             kfree(rd_buf);
>                return -ENXIO;
> +     }
>
>        dsc = pipe_ctx->stream_res.dsc;
>        if (dsc)
> @@ -1748,8 +1762,10 @@ static ssize_t dp_dsc_slice_height_read(struct file *f, char __user *buf,
>                        break;
>
>                r = put_user(*(rd_buf + result), buf);
> -             if (r)
> +             if (r) {
> +                     kfree(rd_buf);
>                        return r; /* r = -EFAULT */
> +             }
>
>                buf += 1;
>                size -= 1;
> @@ -1912,8 +1928,10 @@ static ssize_t dp_dsc_bits_per_pixel_read(struct file *f, char __user *buf,
>                                break;
>        }
>
> -     if (!pipe_ctx)
> +     if (!pipe_ctx) {
> +             kfree(rd_buf);
>                return -ENXIO;
> +     }
>
>        dsc = pipe_ctx->stream_res.dsc;
>        if (dsc)
> @@ -1929,8 +1947,10 @@ static ssize_t dp_dsc_bits_per_pixel_read(struct file *f, char __user *buf,
>                        break;
>
>                r = put_user(*(rd_buf + result), buf);
> -             if (r)
> +             if (r) {
> +                     kfree(rd_buf);
>                        return r; /* r = -EFAULT */
> +             }
>
>                buf += 1;
>                size -= 1;
> @@ -2088,8 +2108,10 @@ static ssize_t dp_dsc_pic_width_read(struct file *f, char __user *buf,
>                                break;
>        }
>
> -     if (!pipe_ctx)
> +     if (!pipe_ctx) {
> +             kfree(rd_buf);
>                return -ENXIO;
> +     }
>
>        dsc = pipe_ctx->stream_res.dsc;
>        if (dsc)
> @@ -2105,8 +2127,10 @@ static ssize_t dp_dsc_pic_width_read(struct file *f, char __user *buf,
>                        break;
>
>                r = put_user(*(rd_buf + result), buf);
> -             if (r)
> +             if (r) {
> +                     kfree(rd_buf);
>                        return r; /* r = -EFAULT */
> +             }
>
>                buf += 1;
>                size -= 1;
> @@ -2145,8 +2169,10 @@ static ssize_t dp_dsc_pic_height_read(struct file *f, char __user *buf,
>                                break;
>        }
>
> -     if (!pipe_ctx)
> +     if (!pipe_ctx) {
> +             kfree(rd_buf);
>                return -ENXIO;
> +     }
>
>        dsc = pipe_ctx->stream_res.dsc;
>        if (dsc)
> @@ -2162,8 +2188,10 @@ static ssize_t dp_dsc_pic_height_read(struct file *f, char __user *buf,
>                        break;
>
>                r = put_user(*(rd_buf + result), buf);
> -             if (r)
> +             if (r) {
> +                     kfree(rd_buf);
>                        return r; /* r = -EFAULT */
> +             }
>
>                buf += 1;
>                size -= 1;
> @@ -2217,8 +2245,10 @@ static ssize_t dp_dsc_chunk_size_read(struct file *f, char __user *buf,
>                                break;
>        }
>
> -     if (!pipe_ctx)
> +     if (!pipe_ctx) {
> +             kfree(rd_buf);
>                return -ENXIO;
> +     }
>
>        dsc = pipe_ctx->stream_res.dsc;
>        if (dsc)
> @@ -2234,8 +2264,10 @@ static ssize_t dp_dsc_chunk_size_read(struct file *f, char __user *buf,
>                        break;
>
>                r = put_user(*(rd_buf + result), buf);
> -             if (r)
> +             if (r) {
> +                     kfree(rd_buf);
>                        return r; /* r = -EFAULT */
> +             }
>
>                buf += 1;
>                size -= 1;
> @@ -2289,8 +2321,10 @@ static ssize_t dp_dsc_slice_bpg_offset_read(struct file *f, char __user *buf,
>                                break;
>        }
>
> -     if (!pipe_ctx)
> +     if (!pipe_ctx) {
> +             kfree(rd_buf);
>                return -ENXIO;
> +     }
>
>        dsc = pipe_ctx->stream_res.dsc;
>        if (dsc)
> @@ -2306,8 +2340,10 @@ static ssize_t dp_dsc_slice_bpg_offset_read(struct file *f, char __user *buf,
>                        break;
>
>                r = put_user(*(rd_buf + result), buf);
> -             if (r)
> +             if (r) {
> +                     kfree(rd_buf);
>                        return r; /* r = -EFAULT */
> +             }
>
>                buf += 1;
>                size -= 1;
> @@ -3459,8 +3495,10 @@ static ssize_t dcc_en_bits_read(
>        dc->hwss.get_dcc_en_bits(dc, dcc_en_bits);
>
>        rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
> -     if (!rd_buf)
> +     if (!rd_buf) {
> +             kfree(dcc_en_bits);
>                return -ENOMEM;
> +     }
>
>        for (i = 0; i < num_pipes; i++)
>                offset += snprintf(rd_buf + offset, rd_buf_size - offset,
> @@ -3473,8 +3511,10 @@ static ssize_t dcc_en_bits_read(
>                if (*pos >= rd_buf_size)
>                        break;
>                r = put_user(*(rd_buf + result), buf);
> -             if (r)
> +             if (r) {
> +                     kfree(rd_buf);
>                        return r; /* r = -EFAULT */
> +             }
>                buf += 1;
>                size -= 1;
>                *pos += 1;


[-- Attachment #2: Type: text/html, Size: 24952 bytes --]

      reply	other threads:[~2022-01-21 20:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-21 11:26 [PATCH] drm/amd/display: Fix memory leak Yongzhi Liu
2022-01-21 11:26 ` Yongzhi Liu
2022-01-21 19:03 ` Harry Wentland
2022-01-21 19:03   ` Harry Wentland
2022-01-21 20:51   ` Deucher, Alexander [this message]

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=BL1PR12MB51446C0B85C39EFC113FED14F75B9@BL1PR12MB5144.namprd12.prod.outlook.com \
    --to=alexander.deucher@amd.com \
    --cc=Anson.Jacob@amd.com \
    --cc=Aurabindo.Pillai@amd.com \
    --cc=Christian.Koenig@amd.com \
    --cc=Harry.Wentland@amd.com \
    --cc=Jerry.Zuo@amd.com \
    --cc=Mikita.Lipski@amd.com \
    --cc=Nicholas.Kazlauskas@amd.com \
    --cc=Nirmoy.Das@amd.com \
    --cc=Rodrigo.Siqueira@amd.com \
    --cc=Sunpeng.Li@amd.com \
    --cc=Wayne.Lin@amd.com \
    --cc=Xinhui.Pan@amd.com \
    --cc=airlied@linux.ie \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=eryk.brol@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lyz_cs@pku.edu.cn \
    /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.