* [PATCH] mtd: rawnand: omap2: fix device leak on probe failure
@ 2025-09-22 15:22 Johan Hovold
2025-09-23 17:05 ` Markus Elfring
2025-09-29 15:55 ` Miquel Raynal
0 siblings, 2 replies; 4+ messages in thread
From: Johan Hovold @ 2025-09-22 15:22 UTC (permalink / raw)
To: Miquel Raynal
Cc: Richard Weinberger, Vignesh Raghavendra, linux-mtd, linux-kernel,
Johan Hovold
Make sure to drop the reference to the elm device taken by
of_find_device_by_node() during probe on errors and on driver unload.
Fixes: 62116e5171e0 ("mtd: nand: omap2: Support for hardware BCH error correction.")
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/mtd/nand/raw/omap2.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/drivers/mtd/nand/raw/omap2.c b/drivers/mtd/nand/raw/omap2.c
index b8af3a3533fc..61fd98ad5c78 100644
--- a/drivers/mtd/nand/raw/omap2.c
+++ b/drivers/mtd/nand/raw/omap2.c
@@ -1979,7 +1979,7 @@ static int omap_nand_attach_chip(struct nand_chip *chip)
err = rawnand_sw_bch_init(chip);
if (err) {
dev_err(dev, "Unable to use BCH library\n");
- return err;
+ goto err_put_elm_dev;
}
break;
@@ -2016,7 +2016,7 @@ static int omap_nand_attach_chip(struct nand_chip *chip)
err = rawnand_sw_bch_init(chip);
if (err) {
dev_err(dev, "unable to use BCH library\n");
- return err;
+ goto err_put_elm_dev;
}
break;
@@ -2054,7 +2054,8 @@ static int omap_nand_attach_chip(struct nand_chip *chip)
break;
default:
dev_err(dev, "Invalid or unsupported ECC scheme\n");
- return -EINVAL;
+ err = -EINVAL;
+ goto err_put_elm_dev;
}
if (elm_bch_strength >= 0) {
@@ -2073,7 +2074,7 @@ static int omap_nand_attach_chip(struct nand_chip *chip)
info->nsteps_per_eccpg, chip->ecc.size,
chip->ecc.bytes);
if (err < 0)
- return err;
+ goto err_put_elm_dev;
}
/* Check if NAND device's OOB is enough to store ECC signatures */
@@ -2083,10 +2084,24 @@ static int omap_nand_attach_chip(struct nand_chip *chip)
dev_err(dev,
"Not enough OOB bytes: required = %d, available=%d\n",
min_oobbytes, mtd->oobsize);
- return -EINVAL;
+ err = -EINVAL;
+ goto err_put_elm_dev;
}
return 0;
+
+err_put_elm_dev:
+ put_device(info->elm_dev);
+
+ return err;
+}
+
+static void omap_nand_detach_chip(struct nand_chip *chip)
+{
+ struct mtd_info *mtd = nand_to_mtd(chip);
+ struct omap_nand_info *info = mtd_to_omap(mtd);
+
+ put_device(info->elm_dev);
}
static void omap_nand_data_in(struct nand_chip *chip, void *buf,
@@ -2187,6 +2202,7 @@ static int omap_nand_exec_op(struct nand_chip *chip,
static const struct nand_controller_ops omap_nand_controller_ops = {
.attach_chip = omap_nand_attach_chip,
+ .detach_chip = omap_nand_detach_chip,
.exec_op = omap_nand_exec_op,
};
--
2.49.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mtd: rawnand: omap2: fix device leak on probe failure
2025-09-22 15:22 [PATCH] mtd: rawnand: omap2: fix device leak on probe failure Johan Hovold
@ 2025-09-23 17:05 ` Markus Elfring
2025-09-24 7:43 ` Miquel Raynal
2025-09-29 15:55 ` Miquel Raynal
1 sibling, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2025-09-23 17:05 UTC (permalink / raw)
To: Johan Hovold, linux-mtd
Cc: LKML, Miquel Raynal, Richard Weinberger, Vignesh Raghavendra
…
> +++ b/drivers/mtd/nand/raw/omap2.c
…
> @@ -2054,7 +2054,8 @@ static int omap_nand_attach_chip(struct nand_chip *chip)
> break;
> default:
> dev_err(dev, "Invalid or unsupported ECC scheme\n");
> - return -EINVAL;
> + err = -EINVAL;
> + goto err_put_elm_dev;
> }
>
> if (elm_bch_strength >= 0) {
…
> @@ -2083,10 +2084,24 @@ static int omap_nand_attach_chip(struct nand_chip *chip)
> dev_err(dev,
> "Not enough OOB bytes: required = %d, available=%d\n",
> min_oobbytes, mtd->oobsize);
> - return -EINVAL;
> + err = -EINVAL;
> + goto err_put_elm_dev;
> }
…
May such an error code assignment be moved behind an additional label?
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mtd: rawnand: omap2: fix device leak on probe failure
2025-09-23 17:05 ` Markus Elfring
@ 2025-09-24 7:43 ` Miquel Raynal
0 siblings, 0 replies; 4+ messages in thread
From: Miquel Raynal @ 2025-09-24 7:43 UTC (permalink / raw)
To: Markus Elfring
Cc: Johan Hovold, linux-mtd, LKML, Richard Weinberger,
Vignesh Raghavendra
Hi Markus,
>> @@ -2083,10 +2084,24 @@ static int omap_nand_attach_chip(struct nand_chip *chip)
>> dev_err(dev,
>> "Not enough OOB bytes: required = %d, available=%d\n",
>> min_oobbytes, mtd->oobsize);
>> - return -EINVAL;
>> + err = -EINVAL;
>> + goto err_put_elm_dev;
>> }
> …
>
> May such an error code assignment be moved behind an additional label?
I don't think that's how labels are supposed to be used, current
proposal looks correct IMO.
Thanks,
Miquèl
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mtd: rawnand: omap2: fix device leak on probe failure
2025-09-22 15:22 [PATCH] mtd: rawnand: omap2: fix device leak on probe failure Johan Hovold
2025-09-23 17:05 ` Markus Elfring
@ 2025-09-29 15:55 ` Miquel Raynal
1 sibling, 0 replies; 4+ messages in thread
From: Miquel Raynal @ 2025-09-29 15:55 UTC (permalink / raw)
To: Johan Hovold
Cc: Richard Weinberger, Vignesh Raghavendra, linux-mtd, linux-kernel
On Mon, 22 Sep 2025 17:22:04 +0200, Johan Hovold wrote:
> Make sure to drop the reference to the elm device taken by
> of_find_device_by_node() during probe on errors and on driver unload.
>
>
Applied to nand/next, thanks!
[1/1] mtd: rawnand: omap2: fix device leak on probe failure
commit: fa1f26b48fe43195aa0ac4badf5651063590326f
Patche(s) should be available on mtd/linux.git and will be
part of the next PR (provided that no robot complains by then).
Kind regards,
Miquèl
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-29 15:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-22 15:22 [PATCH] mtd: rawnand: omap2: fix device leak on probe failure Johan Hovold
2025-09-23 17:05 ` Markus Elfring
2025-09-24 7:43 ` Miquel Raynal
2025-09-29 15:55 ` Miquel Raynal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox