From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Denis Orlov <denorl2009@gmail.com>, barebox@lists.infradead.org
Subject: Re: [PATCH 1/2] usb: storage: fix missing calls to free()
Date: Fri, 30 Jun 2023 07:54:10 +0200 [thread overview]
Message-ID: <ffaf0eea-7a33-27eb-e9d7-a7ae4fe37171@pengutronix.de> (raw)
In-Reply-To: <20230629195718.14416-2-denorl2009@gmail.com>
On 29.06.23 21:52, Denis Orlov wrote:
> Memory allocated with xzalloc() was not actually being freed in a few
> functions, resulting in memory leaks.
>
> Signed-off-by: Denis Orlov <denorl2009@gmail.com>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> drivers/usb/storage/usb.c | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
> index dda7131960..6cdcc348e4 100644
> --- a/drivers/usb/storage/usb.c
> +++ b/drivers/usb/storage/usb.c
> @@ -169,7 +169,7 @@ static int read_capacity_16(struct us_blk_dev *usb_blkdev)
>
> if (ret < 0) {
> dev_warn(dev, "Read Capacity(16) failed\n");
> - return ret;
> + goto fail;
> }
>
> /* Note this is logical, not physical sector size */
> @@ -181,13 +181,17 @@ static int read_capacity_16(struct us_blk_dev *usb_blkdev)
>
> if ((data[12] & 1) == 1) {
> dev_warn(dev, "Protection unsupported\n");
> - return -ENOTSUPP;
> + ret = -ENOTSUPP;
> + goto fail;
> }
>
> usb_blkdev->blk.blockbits = SECTOR_SHIFT;
> usb_blkdev->blk.num_blocks = lba + 1;
>
> - return sector_size;
> + ret = sector_size;
> +fail:
> + free(data);
> + return ret;
> }
>
> static int read_capacity_10(struct us_blk_dev *usb_blkdev)
> @@ -208,7 +212,7 @@ static int read_capacity_10(struct us_blk_dev *usb_blkdev)
>
> if (ret < 0) {
> dev_warn(dev, "Read Capacity(10) failed\n");
> - return ret;
> + goto fail;
> }
>
> sector_size = be32_to_cpu(data[1]);
> @@ -223,7 +227,10 @@ static int read_capacity_10(struct us_blk_dev *usb_blkdev)
> usb_blkdev->blk.num_blocks = lba + 1;
> usb_blkdev->blk.blockbits = SECTOR_SHIFT;
>
> - return SECTOR_SIZE;
> + ret = SECTOR_SIZE;
> +fail:
> + free(data);
> + return ret;
> }
>
> static int usb_stor_io_16(struct us_blk_dev *usb_blkdev, u8 opcode,
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2023-06-30 5:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-29 19:52 [PATCH 0/2] usb: small dma allocation fixes Denis Orlov
2023-06-29 19:52 ` [PATCH 1/2] usb: storage: fix missing calls to free() Denis Orlov
2023-06-30 5:54 ` Ahmad Fatoum [this message]
2023-06-29 19:52 ` [PATCH 2/2] usb: make sure dma buffers are properly allocated Denis Orlov
2023-06-30 11:52 ` [PATCH 0/2] usb: small dma allocation fixes Sascha Hauer
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=ffaf0eea-7a33-27eb-e9d7-a7ae4fe37171@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=denorl2009@gmail.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