From: Miquel Raynal <miquel.raynal@bootlin.com>
To: "GONG, Ruiqi" <gongruiqi1@huawei.com>
Cc: <richard@nod.at>, <vigneshr@ti.com>,
<linux-mtd@lists.infradead.org>, <linux-kernel@vger.kernel.org>,
<wangweiyang2@huawei.com>
Subject: Re: [PATCH] mtd: rawnand: denali: Fix a possible resource leak in denali_pci_probe
Date: Mon, 19 Sep 2022 17:34:07 +0200 [thread overview]
Message-ID: <20220919173407.7068709a@xps-13> (raw)
In-Reply-To: <20220801080315.1713934-1-gongruiqi1@huawei.com>
Hi Ruiqi,
gongruiqi1@huawei.com wrote on Mon, 1 Aug 2022 16:03:15 +0800:
> Call pci_release_regions() to retrieve the allocated resource when
> devm_ioremap() or denali_init() failed.
fail
>
> Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com>
> ---
> drivers/mtd/nand/raw/denali_pci.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/denali_pci.c b/drivers/mtd/nand/raw/denali_pci.c
> index de7e722d3826..40943cda0914 100644
> --- a/drivers/mtd/nand/raw/denali_pci.c
> +++ b/drivers/mtd/nand/raw/denali_pci.c
> @@ -74,21 +74,22 @@ static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
> return ret;
> }
>
> + ret = -ENOMEM;
I don't like so much this construction as later changes in the probe
might just fail this logic.
Please just set ret = -ENOMEM; in the error path each time it's needed.
I don't care about loosing 3 lines of code if it clarifies what the
error path returns.
> denali->reg = devm_ioremap(denali->dev, csr_base, csr_len);
> if (!denali->reg) {
> dev_err(&dev->dev, "Spectra: Unable to remap memory region\n");
> - return -ENOMEM;
> + goto out_release_pci;
> }
>
> denali->host = devm_ioremap(denali->dev, mem_base, mem_len);
> if (!denali->host) {
> dev_err(&dev->dev, "Spectra: ioremap failed!");
> - return -ENOMEM;
> + goto out_release_pci;
> }
>
> ret = denali_init(denali);
> if (ret)
> - return ret;
> + goto out_release_pci;
>
> nsels = denali->nbanks;
>
> @@ -116,6 +117,8 @@ static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
>
> out_remove_denali:
> denali_remove(denali);
> +out_release_pci:
> + pci_release_regions(dev);
> return ret;
> }
>
Thanks,
Miquèl
prev parent reply other threads:[~2022-09-19 15:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-01 8:03 [PATCH] mtd: rawnand: denali: Fix a possible resource leak in denali_pci_probe GONG, Ruiqi
2022-08-01 18:26 ` Christophe JAILLET
2022-09-19 15:35 ` Miquel Raynal
2022-09-19 15:34 ` Miquel Raynal [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=20220919173407.7068709a@xps-13 \
--to=miquel.raynal@bootlin.com \
--cc=gongruiqi1@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
--cc=vigneshr@ti.com \
--cc=wangweiyang2@huawei.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