From: Luben Tuikov <luben.tuikov@amd.com>
To: Yang Wang <kevinyang.wang@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdgpu: fix memory leak in amdgpu_fru_get_product_info()
Date: Fri, 22 Sep 2023 16:58:38 -0400 [thread overview]
Message-ID: <17d92228-b0a2-408e-a233-e7faf4d056b7@amd.com> (raw)
In-Reply-To: <20230922052753.1922483-1-kevinyang.wang@amd.com>
On 2023-09-22 01:27, Yang Wang wrote:
> fix a memory leak that occurs when csum is 0,
> the origin function will return directly and forgets to free 'pia' resource.
>
> Fixes: 0dbf2c562625 ("drm/amdgpu: Interpret IPMI data for product information (v2)")
>
> CC: Luben Tuikov <luben.tuikov@amd.com>
> Signed-off-by: Yang Wang <kevinyang.wang@amd.com>
Ah, yes, we should free "pia". Good catch!
Reviewed-by: Luben Tuikov <luben.tuikov@amd.com>
Regards,
Luben
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_fru_eeprom.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fru_eeprom.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fru_eeprom.c
> index 401651f28ba2..50b6eb447726 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fru_eeprom.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fru_eeprom.c
> @@ -111,7 +111,7 @@ int amdgpu_fru_get_product_info(struct amdgpu_device *adev)
> {
> unsigned char buf[8], *pia;
> u32 addr, fru_addr;
> - int size, len;
> + int size, len, ret = 0;
> u8 csum;
>
> if (!is_fru_eeprom_supported(adev, &fru_addr))
> @@ -171,16 +171,17 @@ int amdgpu_fru_get_product_info(struct amdgpu_device *adev)
> /* Read the whole PIA. */
> len = amdgpu_eeprom_read(adev->pm.fru_eeprom_i2c_bus, addr, pia, size);
> if (len != size) {
> - kfree(pia);
> DRM_ERROR("Couldn't read the Product Info Area: %d", len);
> - return len < 0 ? len : -EIO;
> + ret = len < 0 ? len : -EIO;
> + goto Out;
> }
>
> for (csum = 0; size > 0; size--)
> csum += pia[size - 1];
> if (csum) {
> DRM_ERROR("Bad Product Info Area checksum: 0x%02x", csum);
> - return -EIO;
> + ret = -EIO;
> + goto Out;
> }
>
> /* Now extract useful information from the PIA.
> @@ -220,7 +221,7 @@ int amdgpu_fru_get_product_info(struct amdgpu_device *adev)
> adev->serial[sizeof(adev->serial) - 1] = '\0';
> Out:
> kfree(pia);
> - return 0;
> + return ret;
> }
>
> /**
--
Regards,
Luben
next prev parent reply other threads:[~2023-09-22 20:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-22 5:27 [PATCH] drm/amdgpu: fix memory leak in amdgpu_fru_get_product_info() Yang Wang
2023-09-22 17:21 ` Alex Deucher
2023-09-22 20:58 ` Luben Tuikov [this message]
2023-09-22 21:12 ` Luben Tuikov
2023-09-22 21:09 ` Luben Tuikov
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=17d92228-b0a2-408e-a233-e7faf4d056b7@amd.com \
--to=luben.tuikov@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=kevinyang.wang@amd.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