<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#008000;margin:15pt;" align="Left">
[Public]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Applied. Thanks!<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Wentland, Harry <Harry.Wentland@amd.com><br>
<b>Sent:</b> Friday, January 21, 2022 2:03 PM<br>
<b>To:</b> 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><br>
<b>Cc:</b> 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><br>
<b>Subject:</b> Re: [PATCH] drm/amd/display: Fix memory leak</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">On 2022-01-21 06:26, Yongzhi Liu wrote:<br>
> [why]<br>
> Resource release is needed on the error handling path<br>
> to prevent memory leak.<br>
> <br>
> [how]<br>
> Fix this by adding kfree on the error handling path.<br>
> <br>
> Signed-off-by: Yongzhi Liu <lyz_cs@pku.edu.cn><br>
<br>
Reviewed-by: Harry Wentland <harry.wentland@amd.com><br>
<br>
Harry<br>
<br>
> ---<br>
> .../drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 80 ++++++++++++++++------<br>
> 1 file changed, 60 insertions(+), 20 deletions(-)<br>
> <br>
> 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<br>
> index ded64d0..e463d46 100644<br>
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c<br>
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c<br>
> @@ -227,8 +227,10 @@ static ssize_t dp_link_settings_read(struct file *f, char __user *buf,<br>
> break;<br>
> <br>
> r = put_user(*(rd_buf + result), buf);<br>
> - if (r)<br>
> + if (r) {<br>
> + kfree(rd_buf);<br>
> return r; /* r = -EFAULT */<br>
> + }<br>
> <br>
> buf += 1;<br>
> size -= 1;<br>
> @@ -389,8 +391,10 @@ static ssize_t dp_phy_settings_read(struct file *f, char __user *buf,<br>
> break;<br>
> <br>
> r = put_user((*(rd_buf + result)), buf);<br>
> - if (r)<br>
> + if (r) {<br>
> + kfree(rd_buf);<br>
> return r; /* r = -EFAULT */<br>
> + }<br>
> <br>
> buf += 1;<br>
> size -= 1;<br>
> @@ -1359,8 +1363,10 @@ static ssize_t dp_dsc_clock_en_read(struct file *f, char __user *buf,<br>
> break;<br>
> }<br>
> <br>
> - if (!pipe_ctx)<br>
> + if (!pipe_ctx) {<br>
> + kfree(rd_buf);<br>
> return -ENXIO;<br>
> + }<br>
> <br>
> dsc = pipe_ctx->stream_res.dsc;<br>
> if (dsc)<br>
> @@ -1376,8 +1382,10 @@ static ssize_t dp_dsc_clock_en_read(struct file *f, char __user *buf,<br>
> break;<br>
> <br>
> r = put_user(*(rd_buf + result), buf);<br>
> - if (r)<br>
> + if (r) {<br>
> + kfree(rd_buf);<br>
> return r; /* r = -EFAULT */<br>
> + }<br>
> <br>
> buf += 1;<br>
> size -= 1;<br>
> @@ -1546,8 +1554,10 @@ static ssize_t dp_dsc_slice_width_read(struct file *f, char __user *buf,<br>
> break;<br>
> }<br>
> <br>
> - if (!pipe_ctx)<br>
> + if (!pipe_ctx) {<br>
> + kfree(rd_buf);<br>
> return -ENXIO;<br>
> + }<br>
> <br>
> dsc = pipe_ctx->stream_res.dsc;<br>
> if (dsc)<br>
> @@ -1563,8 +1573,10 @@ static ssize_t dp_dsc_slice_width_read(struct file *f, char __user *buf,<br>
> break;<br>
> <br>
> r = put_user(*(rd_buf + result), buf);<br>
> - if (r)<br>
> + if (r) {<br>
> + kfree(rd_buf);<br>
> return r; /* r = -EFAULT */<br>
> + }<br>
> <br>
> buf += 1;<br>
> size -= 1;<br>
> @@ -1731,8 +1743,10 @@ static ssize_t dp_dsc_slice_height_read(struct file *f, char __user *buf,<br>
> break;<br>
> }<br>
> <br>
> - if (!pipe_ctx)<br>
> + if (!pipe_ctx) {<br>
> + kfree(rd_buf);<br>
> return -ENXIO;<br>
> + }<br>
> <br>
> dsc = pipe_ctx->stream_res.dsc;<br>
> if (dsc)<br>
> @@ -1748,8 +1762,10 @@ static ssize_t dp_dsc_slice_height_read(struct file *f, char __user *buf,<br>
> break;<br>
> <br>
> r = put_user(*(rd_buf + result), buf);<br>
> - if (r)<br>
> + if (r) {<br>
> + kfree(rd_buf);<br>
> return r; /* r = -EFAULT */<br>
> + }<br>
> <br>
> buf += 1;<br>
> size -= 1;<br>
> @@ -1912,8 +1928,10 @@ static ssize_t dp_dsc_bits_per_pixel_read(struct file *f, char __user *buf,<br>
> break;<br>
> }<br>
> <br>
> - if (!pipe_ctx)<br>
> + if (!pipe_ctx) {<br>
> + kfree(rd_buf);<br>
> return -ENXIO;<br>
> + }<br>
> <br>
> dsc = pipe_ctx->stream_res.dsc;<br>
> if (dsc)<br>
> @@ -1929,8 +1947,10 @@ static ssize_t dp_dsc_bits_per_pixel_read(struct file *f, char __user *buf,<br>
> break;<br>
> <br>
> r = put_user(*(rd_buf + result), buf);<br>
> - if (r)<br>
> + if (r) {<br>
> + kfree(rd_buf);<br>
> return r; /* r = -EFAULT */<br>
> + }<br>
> <br>
> buf += 1;<br>
> size -= 1;<br>
> @@ -2088,8 +2108,10 @@ static ssize_t dp_dsc_pic_width_read(struct file *f, char __user *buf,<br>
> break;<br>
> }<br>
> <br>
> - if (!pipe_ctx)<br>
> + if (!pipe_ctx) {<br>
> + kfree(rd_buf);<br>
> return -ENXIO;<br>
> + }<br>
> <br>
> dsc = pipe_ctx->stream_res.dsc;<br>
> if (dsc)<br>
> @@ -2105,8 +2127,10 @@ static ssize_t dp_dsc_pic_width_read(struct file *f, char __user *buf,<br>
> break;<br>
> <br>
> r = put_user(*(rd_buf + result), buf);<br>
> - if (r)<br>
> + if (r) {<br>
> + kfree(rd_buf);<br>
> return r; /* r = -EFAULT */<br>
> + }<br>
> <br>
> buf += 1;<br>
> size -= 1;<br>
> @@ -2145,8 +2169,10 @@ static ssize_t dp_dsc_pic_height_read(struct file *f, char __user *buf,<br>
> break;<br>
> }<br>
> <br>
> - if (!pipe_ctx)<br>
> + if (!pipe_ctx) {<br>
> + kfree(rd_buf);<br>
> return -ENXIO;<br>
> + }<br>
> <br>
> dsc = pipe_ctx->stream_res.dsc;<br>
> if (dsc)<br>
> @@ -2162,8 +2188,10 @@ static ssize_t dp_dsc_pic_height_read(struct file *f, char __user *buf,<br>
> break;<br>
> <br>
> r = put_user(*(rd_buf + result), buf);<br>
> - if (r)<br>
> + if (r) {<br>
> + kfree(rd_buf);<br>
> return r; /* r = -EFAULT */<br>
> + }<br>
> <br>
> buf += 1;<br>
> size -= 1;<br>
> @@ -2217,8 +2245,10 @@ static ssize_t dp_dsc_chunk_size_read(struct file *f, char __user *buf,<br>
> break;<br>
> }<br>
> <br>
> - if (!pipe_ctx)<br>
> + if (!pipe_ctx) {<br>
> + kfree(rd_buf);<br>
> return -ENXIO;<br>
> + }<br>
> <br>
> dsc = pipe_ctx->stream_res.dsc;<br>
> if (dsc)<br>
> @@ -2234,8 +2264,10 @@ static ssize_t dp_dsc_chunk_size_read(struct file *f, char __user *buf,<br>
> break;<br>
> <br>
> r = put_user(*(rd_buf + result), buf);<br>
> - if (r)<br>
> + if (r) {<br>
> + kfree(rd_buf);<br>
> return r; /* r = -EFAULT */<br>
> + }<br>
> <br>
> buf += 1;<br>
> size -= 1;<br>
> @@ -2289,8 +2321,10 @@ static ssize_t dp_dsc_slice_bpg_offset_read(struct file *f, char __user *buf,<br>
> break;<br>
> }<br>
> <br>
> - if (!pipe_ctx)<br>
> + if (!pipe_ctx) {<br>
> + kfree(rd_buf);<br>
> return -ENXIO;<br>
> + }<br>
> <br>
> dsc = pipe_ctx->stream_res.dsc;<br>
> if (dsc)<br>
> @@ -2306,8 +2340,10 @@ static ssize_t dp_dsc_slice_bpg_offset_read(struct file *f, char __user *buf,<br>
> break;<br>
> <br>
> r = put_user(*(rd_buf + result), buf);<br>
> - if (r)<br>
> + if (r) {<br>
> + kfree(rd_buf);<br>
> return r; /* r = -EFAULT */<br>
> + }<br>
> <br>
> buf += 1;<br>
> size -= 1;<br>
> @@ -3459,8 +3495,10 @@ static ssize_t dcc_en_bits_read(<br>
> dc->hwss.get_dcc_en_bits(dc, dcc_en_bits);<br>
> <br>
> rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);<br>
> - if (!rd_buf)<br>
> + if (!rd_buf) {<br>
> + kfree(dcc_en_bits);<br>
> return -ENOMEM;<br>
> + }<br>
> <br>
> for (i = 0; i < num_pipes; i++)<br>
> offset += snprintf(rd_buf + offset, rd_buf_size - offset,<br>
> @@ -3473,8 +3511,10 @@ static ssize_t dcc_en_bits_read(<br>
> if (*pos >= rd_buf_size)<br>
> break;<br>
> r = put_user(*(rd_buf + result), buf);<br>
> - if (r)<br>
> + if (r) {<br>
> + kfree(rd_buf);<br>
> return r; /* r = -EFAULT */<br>
> + }<br>
> buf += 1;<br>
> size -= 1;<br>
> *pos += 1;<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>