Skip to content

Commit 11493f2

Browse files
tasksetmiquelraynal
authored andcommitted
mtd: rawnand: jz4780: fix possible object reference leak
of_find_device_by_node() takes a reference to the struct device when it finds a match via get_device, there is no need to call get_device() twice. We also should make sure to drop the reference to the device taken by of_find_device_by_node() on driver unbind. Fixes: ae02ab0 ("mtd: nand: jz4780: driver for NAND devices on JZ4780 SoCs") Signed-off-by: Wen Yang <yellowriver2010@hotmail.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent a12085d commit 11493f2

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/mtd/nand/raw/jz4780_bch.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,15 @@ static struct jz4780_bch *jz4780_bch_get(struct device_node *np)
281281
struct jz4780_bch *bch;
282282

283283
pdev = of_find_device_by_node(np);
284-
if (!pdev || !platform_get_drvdata(pdev))
284+
if (!pdev)
285285
return ERR_PTR(-EPROBE_DEFER);
286286

287-
get_device(&pdev->dev);
288-
289287
bch = platform_get_drvdata(pdev);
288+
if (!bch) {
289+
put_device(&pdev->dev);
290+
return ERR_PTR(-EPROBE_DEFER);
291+
}
292+
290293
clk_prepare_enable(bch->clk);
291294

292295
return bch;

0 commit comments

Comments
 (0)