From: Dan Carpenter <dan.carpenter@linaro.org>
To: Keguang Zhang <keguang.zhang@gmail.com>
Cc: linux-mips@vger.kernel.org, linux-mtd@lists.infradead.org,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
devicetree@vger.kernel.org
Subject: [bug report] mtd: rawnand: Add Loongson-1 NAND Controller Driver
Date: Fri, 2 May 2025 10:53:03 +0300 [thread overview]
Message-ID: <aBR535RZZT-sa6QZ@stanley.mountain> (raw)
Hello Keguang Zhang,
Commit d2d10ede04b1 ("mtd: rawnand: Add Loongson-1 NAND Controller
Driver") from Mar 20, 2025 (linux-next), 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':
drivers/mtd/nand/raw/loongson1-nand-controller.c
690 static int ls1x_nand_chip_init(struct ls1x_nand_host *host)
691 {
692 struct device *dev = host->dev;
693 int nchips = of_get_child_count(dev->of_node);
694 struct device_node *chip_np;
695 struct nand_chip *chip = &host->chip;
696 struct mtd_info *mtd = nand_to_mtd(chip);
697 int ret;
698
699 if (nchips != 1)
700 return dev_err_probe(dev, -EINVAL, "Currently one NAND chip supported\n");
701
702 chip_np = of_get_next_child(dev->of_node, NULL);
The of_get_next_child() function drops the reference on the current
child. That's probably not what we want to happen. This is similar to
a discussion we were having earlier about of_find_node_by_name().
Then it takes a reference to the new child.
703 if (!chip_np)
704 return dev_err_probe(dev, -ENODEV, "failed to get child node for NAND chip\n");
705
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);
710 nand_set_flash_node(chip, chip_np);
711 if (!mtd->name)
712 return dev_err_probe(dev, -EINVAL, "Missing MTD label\n");
of_node_put(chip_np) before returning.
713
714 mtd->dev.parent = dev;
715 mtd->owner = THIS_MODULE;
716
717 ret = nand_scan(chip, 1);
718 if (ret) {
719 of_node_put(chip_np);
720 return dev_err_probe(dev, ret, "failed to scan NAND chip\n");
721 }
722
723 ret = mtd_device_register(mtd, NULL, 0);
724 if (ret) {
725 nand_cleanup(chip);
726 of_node_put(chip_np);
727 return dev_err_probe(dev, ret, "failed to register MTD device\n");
728 }
729
I think we want to call of_node_put(chip_np) before returning on the
success path as well?
--> 730 return 0;
731 }
regards,
dan carpenter
next reply other threads:[~2025-05-02 7:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-02 7:53 Dan Carpenter [this message]
2025-05-02 16:04 ` [bug report] mtd: rawnand: Add Loongson-1 NAND Controller Driver Laurent Pinchart
2025-05-07 2:19 ` Keguang Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aBR535RZZT-sa6QZ@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=keguang.zhang@gmail.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-mips@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox