Skip to content

Commit 615f8f5

Browse files
kelvincheungmiquelraynal
authored andcommitted
mtd: rawnand: loongson1: Fix inconsistent refcounting in ls1x_nand_chip_init()
As reported by Dan, commit d2d10ed ("mtd: rawnand: Add Loongson-1 NAND Controller Driver"), leads to the following Smatch static checker warning: drivers/mtd/nand/raw/loongson1-nand-controller.c:730 ls1x_nand_chip_init() warn: inconsistent refcounting 'chip_np->kobj.kref.refcount.refs.counter': Fix this issue by calling of_node_put() immediately after using chip_np. In addition, remove all unnecessary of_node_put(chip_np) calls. Reported-by: Dan Carpenter <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Fixes: d2d10ed ("mtd: rawnand: Add Loongson-1 NAND Controller Driver") Signed-off-by: Keguang Zhang <[email protected]> Signed-off-by: Miquel Raynal <[email protected]>
1 parent 0d470c7 commit 615f8f5

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

drivers/mtd/nand/raw/loongson1-nand-controller.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -703,27 +703,25 @@ static int ls1x_nand_chip_init(struct ls1x_nand_host *host)
703703
if (!chip_np)
704704
return dev_err_probe(dev, -ENODEV, "failed to get child node for NAND chip\n");
705705

706-
chip->controller = &host->controller;
707-
chip->options = NAND_NO_SUBPAGE_WRITE | NAND_USES_DMA | NAND_BROKEN_XD;
708-
chip->buf_align = 16;
709-
nand_set_controller_data(chip, host);
710706
nand_set_flash_node(chip, chip_np);
707+
of_node_put(chip_np);
711708
if (!mtd->name)
712709
return dev_err_probe(dev, -EINVAL, "Missing MTD label\n");
713710

711+
nand_set_controller_data(chip, host);
712+
chip->controller = &host->controller;
713+
chip->options = NAND_NO_SUBPAGE_WRITE | NAND_USES_DMA | NAND_BROKEN_XD;
714+
chip->buf_align = 16;
714715
mtd->dev.parent = dev;
715716
mtd->owner = THIS_MODULE;
716717

717718
ret = nand_scan(chip, 1);
718-
if (ret) {
719-
of_node_put(chip_np);
719+
if (ret)
720720
return dev_err_probe(dev, ret, "failed to scan NAND chip\n");
721-
}
722721

723722
ret = mtd_device_register(mtd, NULL, 0);
724723
if (ret) {
725724
nand_cleanup(chip);
726-
of_node_put(chip_np);
727725
return dev_err_probe(dev, ret, "failed to register MTD device\n");
728726
}
729727

0 commit comments

Comments
 (0)