Skip to content

Commit fa1f26b

Browse files
jhovoldmiquelraynal
authored andcommitted
mtd: rawnand: omap2: fix device leak on probe failure
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: 62116e5 ("mtd: nand: omap2: Support for hardware BCH error correction.") Signed-off-by: Johan Hovold <[email protected]> Signed-off-by: Miquel Raynal <[email protected]>
1 parent 8ed4728 commit fa1f26b

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

drivers/mtd/nand/raw/omap2.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,7 @@ static int omap_nand_attach_chip(struct nand_chip *chip)
19791979
err = rawnand_sw_bch_init(chip);
19801980
if (err) {
19811981
dev_err(dev, "Unable to use BCH library\n");
1982-
return err;
1982+
goto err_put_elm_dev;
19831983
}
19841984
break;
19851985

@@ -2016,7 +2016,7 @@ static int omap_nand_attach_chip(struct nand_chip *chip)
20162016
err = rawnand_sw_bch_init(chip);
20172017
if (err) {
20182018
dev_err(dev, "unable to use BCH library\n");
2019-
return err;
2019+
goto err_put_elm_dev;
20202020
}
20212021
break;
20222022

@@ -2054,7 +2054,8 @@ static int omap_nand_attach_chip(struct nand_chip *chip)
20542054
break;
20552055
default:
20562056
dev_err(dev, "Invalid or unsupported ECC scheme\n");
2057-
return -EINVAL;
2057+
err = -EINVAL;
2058+
goto err_put_elm_dev;
20582059
}
20592060

20602061
if (elm_bch_strength >= 0) {
@@ -2073,7 +2074,7 @@ static int omap_nand_attach_chip(struct nand_chip *chip)
20732074
info->nsteps_per_eccpg, chip->ecc.size,
20742075
chip->ecc.bytes);
20752076
if (err < 0)
2076-
return err;
2077+
goto err_put_elm_dev;
20772078
}
20782079

20792080
/* 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)
20832084
dev_err(dev,
20842085
"Not enough OOB bytes: required = %d, available=%d\n",
20852086
min_oobbytes, mtd->oobsize);
2086-
return -EINVAL;
2087+
err = -EINVAL;
2088+
goto err_put_elm_dev;
20872089
}
20882090

20892091
return 0;
2092+
2093+
err_put_elm_dev:
2094+
put_device(info->elm_dev);
2095+
2096+
return err;
2097+
}
2098+
2099+
static void omap_nand_detach_chip(struct nand_chip *chip)
2100+
{
2101+
struct mtd_info *mtd = nand_to_mtd(chip);
2102+
struct omap_nand_info *info = mtd_to_omap(mtd);
2103+
2104+
put_device(info->elm_dev);
20902105
}
20912106

20922107
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,
21872202

21882203
static const struct nand_controller_ops omap_nand_controller_ops = {
21892204
.attach_chip = omap_nand_attach_chip,
2205+
.detach_chip = omap_nand_detach_chip,
21902206
.exec_op = omap_nand_exec_op,
21912207
};
21922208

0 commit comments

Comments
 (0)