linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] mtd: rawnand: intel: Add missing of_node_put() in ebu_nand_probe()
@ 2022-09-24 13:10 Yang Yingliang
  2022-09-25 19:39 ` Martin Blumenstingl
  2022-10-18  9:02 ` Miquel Raynal
  0 siblings, 2 replies; 6+ messages in thread
From: Yang Yingliang @ 2022-09-24 13:10 UTC (permalink / raw)
  To: linux-mtd; +Cc: miquel.raynal, martin.blumenstingl, yangyingliang

The 'chip_np' returned by of_get_next_child() with refcount decremented,
of_node_put() need be called in error path to decrease the refcount.

Fixes: bfc618fcc3f1 ("mtd: rawnand: intel: Read the chip-select line from the correct OF node")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/mtd/nand/raw/intel-nand-controller.c | 23 +++++++++++++-------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/nand/raw/intel-nand-controller.c b/drivers/mtd/nand/raw/intel-nand-controller.c
index d4a0987e93ac..6f4cea81f97c 100644
--- a/drivers/mtd/nand/raw/intel-nand-controller.c
+++ b/drivers/mtd/nand/raw/intel-nand-controller.c
@@ -608,11 +608,12 @@ static int ebu_nand_probe(struct platform_device *pdev)
 	ret = of_property_read_u32(chip_np, "reg", &cs);
 	if (ret) {
 		dev_err(dev, "failed to get chip select: %d\n", ret);
-		return ret;
+		goto err_of_node_put;
 	}
 	if (cs >= MAX_CS) {
 		dev_err(dev, "got invalid chip select: %d\n", cs);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto err_of_node_put;
 	}
 
 	ebu_host->cs_num = cs;
@@ -620,18 +621,22 @@ static int ebu_nand_probe(struct platform_device *pdev)
 	resname = devm_kasprintf(dev, GFP_KERNEL, "nand_cs%d", cs);
 	ebu_host->cs[cs].chipaddr = devm_platform_ioremap_resource_byname(pdev,
 									  resname);
-	if (IS_ERR(ebu_host->cs[cs].chipaddr))
-		return PTR_ERR(ebu_host->cs[cs].chipaddr);
+	if (IS_ERR(ebu_host->cs[cs].chipaddr)) {
+		ret = PTR_ERR(ebu_host->cs[cs].chipaddr);
+		goto err_of_node_put;
+	}
 
 	ebu_host->clk = devm_clk_get(dev, NULL);
-	if (IS_ERR(ebu_host->clk))
-		return dev_err_probe(dev, PTR_ERR(ebu_host->clk),
-				     "failed to get clock\n");
+	if (IS_ERR(ebu_host->clk)) {
+		ret = dev_err_probe(dev, PTR_ERR(ebu_host->clk),
+				    "failed to get clock\n");
+		goto err_of_node_put;
+	}
 
 	ret = clk_prepare_enable(ebu_host->clk);
 	if (ret) {
 		dev_err(dev, "failed to enable clock: %d\n", ret);
-		return ret;
+		goto err_of_node_put;
 	}
 
 	ebu_host->dma_tx = dma_request_chan(dev, "tx");
@@ -695,6 +700,8 @@ static int ebu_nand_probe(struct platform_device *pdev)
 	ebu_dma_cleanup(ebu_host);
 err_disable_unprepare_clk:
 	clk_disable_unprepare(ebu_host->clk);
+err_of_node_put:
+	of_node_put(chip_np);
 
 	return ret;
 }
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH -next] mtd: rawnand: intel: Add missing of_node_put() in ebu_nand_probe()
  2022-09-24 13:10 [PATCH -next] mtd: rawnand: intel: Add missing of_node_put() in ebu_nand_probe() Yang Yingliang
@ 2022-09-25 19:39 ` Martin Blumenstingl
  2022-09-26  1:57   ` Yang Yingliang
  2022-10-18  9:02 ` Miquel Raynal
  1 sibling, 1 reply; 6+ messages in thread
From: Martin Blumenstingl @ 2022-09-25 19:39 UTC (permalink / raw)
  To: Yang Yingliang; +Cc: linux-mtd, miquel.raynal

Hello,

On Sat, Sep 24, 2022 at 3:03 PM Yang Yingliang <yangyingliang@huawei.com> wrote:
>
> The 'chip_np' returned by of_get_next_child() with refcount decremented,
> of_node_put() need be called in error path to decrease the refcount.
Thanks a lot for bringing this up!

[...]
> @@ -695,6 +700,8 @@ static int ebu_nand_probe(struct platform_device *pdev)
>         ebu_dma_cleanup(ebu_host);
>  err_disable_unprepare_clk:
>         clk_disable_unprepare(ebu_host->clk);
> +err_of_node_put:
> +       of_node_put(chip_np);
Here I have one question:
My understanding is that with this patch we now use
of_node_put(chip_np); in case any error occurs during probe.
But what about the case where there's no error and someone later
unloads the driver (using rmmod)? Or in other words: do we need
another of_node_put() call in ebu_nand_remove()?


Best regards,
Martin

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH -next] mtd: rawnand: intel: Add missing of_node_put() in ebu_nand_probe()
  2022-09-25 19:39 ` Martin Blumenstingl
@ 2022-09-26  1:57   ` Yang Yingliang
  2022-09-27 19:26     ` Martin Blumenstingl
  0 siblings, 1 reply; 6+ messages in thread
From: Yang Yingliang @ 2022-09-26  1:57 UTC (permalink / raw)
  To: Martin Blumenstingl; +Cc: linux-mtd, miquel.raynal

Hi,

On 2022/9/26 3:39, Martin Blumenstingl wrote:
> Hello,
>
> On Sat, Sep 24, 2022 at 3:03 PM Yang Yingliang <yangyingliang@huawei.com> wrote:
>> The 'chip_np' returned by of_get_next_child() with refcount decremented,
>> of_node_put() need be called in error path to decrease the refcount.
> Thanks a lot for bringing this up!
>
> [...]
>> @@ -695,6 +700,8 @@ static int ebu_nand_probe(struct platform_device *pdev)
>>          ebu_dma_cleanup(ebu_host);
>>   err_disable_unprepare_clk:
>>          clk_disable_unprepare(ebu_host->clk);
>> +err_of_node_put:
>> +       of_node_put(chip_np);
> Here I have one question:
> My understanding is that with this patch we now use
> of_node_put(chip_np); in case any error occurs during probe.
> But what about the case where there's no error and someone later
> unloads the driver (using rmmod)? Or in other words: do we need
> another of_node_put() call in ebu_nand_remove()?
In normal case, when the module is removing, the of_node_put() is
called in del_mtd_device() which is called by mtd_device_unregister().

Thanks,
Yang
>
>
> Best regards,
> Martin
> .

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH -next] mtd: rawnand: intel: Add missing of_node_put() in ebu_nand_probe()
  2022-09-26  1:57   ` Yang Yingliang
@ 2022-09-27 19:26     ` Martin Blumenstingl
  2022-09-28 10:19       ` Info Skymem
  0 siblings, 1 reply; 6+ messages in thread
From: Martin Blumenstingl @ 2022-09-27 19:26 UTC (permalink / raw)
  To: Yang Yingliang; +Cc: linux-mtd, miquel.raynal

Hi,

On Mon, Sep 26, 2022 at 3:58 AM Yang Yingliang <yangyingliang@huawei.com> wrote:
[...]
> >> +err_of_node_put:
> >> +       of_node_put(chip_np);
> > Here I have one question:
> > My understanding is that with this patch we now use
> > of_node_put(chip_np); in case any error occurs during probe.
> > But what about the case where there's no error and someone later
> > unloads the driver (using rmmod)? Or in other words: do we need
> > another of_node_put() call in ebu_nand_remove()?
> In normal case, when the module is removing, the of_node_put() is
> called in del_mtd_device() which is called by mtd_device_unregister().
Thank you so much for the explanation! With this your patch gets my:
Reviewed-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>


Best regards,
Martin

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH -next] mtd: rawnand: intel: Add missing of_node_put() in ebu_nand_probe()
  2022-09-27 19:26     ` Martin Blumenstingl
@ 2022-09-28 10:19       ` Info Skymem
  0 siblings, 0 replies; 6+ messages in thread
From: Info Skymem @ 2022-09-28 10:19 UTC (permalink / raw)
  To: Martin Blumenstingl; +Cc: Yang Yingliang, linux-mtd, miquel.raynal

Hi,
thank you for your information.

On our website you can find email addresses of companies and people.
https://www.skymem.info

In short, it’s like Google for emails.

Best regards,
Robert,
Skymem team

On Tue, Sep 27, 2022 at 9:27 PM Martin Blumenstingl
<martin.blumenstingl@googlemail.com> wrote:
>
> Hi,
>
> On Mon, Sep 26, 2022 at 3:58 AM Yang Yingliang <yangyingliang@huawei.com> wrote:
> [...]
> > >> +err_of_node_put:
> > >> +       of_node_put(chip_np);
> > > Here I have one question:
> > > My understanding is that with this patch we now use
> > > of_node_put(chip_np); in case any error occurs during probe.
> > > But what about the case where there's no error and someone later
> > > unloads the driver (using rmmod)? Or in other words: do we need
> > > another of_node_put() call in ebu_nand_remove()?
> > In normal case, when the module is removing, the of_node_put() is
> > called in del_mtd_device() which is called by mtd_device_unregister().
> Thank you so much for the explanation! With this your patch gets my:
> Reviewed-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
>
>
> Best regards,
> Martin
>
> ______________________________________________________
> Linux MTD discussion mailing list
> http://lists.infradead.org/mailman/listinfo/linux-mtd/

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH -next] mtd: rawnand: intel: Add missing of_node_put() in ebu_nand_probe()
  2022-09-24 13:10 [PATCH -next] mtd: rawnand: intel: Add missing of_node_put() in ebu_nand_probe() Yang Yingliang
  2022-09-25 19:39 ` Martin Blumenstingl
@ 2022-10-18  9:02 ` Miquel Raynal
  1 sibling, 0 replies; 6+ messages in thread
From: Miquel Raynal @ 2022-10-18  9:02 UTC (permalink / raw)
  To: Yang Yingliang, linux-mtd; +Cc: Miquel Raynal, martin.blumenstingl

On Sat, 2022-09-24 at 13:10:10 UTC, Yang Yingliang wrote:
> The 'chip_np' returned by of_get_next_child() with refcount decremented,
> of_node_put() need be called in error path to decrease the refcount.
> 
> Fixes: bfc618fcc3f1 ("mtd: rawnand: intel: Read the chip-select line from the correct OF node")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> Reviewed-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/fixes, thanks.

Miquel

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-10-18  9:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-24 13:10 [PATCH -next] mtd: rawnand: intel: Add missing of_node_put() in ebu_nand_probe() Yang Yingliang
2022-09-25 19:39 ` Martin Blumenstingl
2022-09-26  1:57   ` Yang Yingliang
2022-09-27 19:26     ` Martin Blumenstingl
2022-09-28 10:19       ` Info Skymem
2022-10-18  9:02 ` Miquel Raynal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).