From: Dan Carpenter <error27@gmail.com>
To: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: linux-mtd@lists.infradead.org
Subject: [bug report] mtd: rawnand: ndfc: Stop using nand_release()
Date: Wed, 19 Aug 2026 08:56:42 +0300 [thread overview]
Message-ID: <aoVFmrEnQcDuI1fQ@stanley.mountain> (raw)
Hello Miquel Raynal,
Commit a9384f95fe77 ("mtd: rawnand: ndfc: Stop using nand_release()")
from May 19, 2020 (linux-next), leads to the following Smatch static
checker warning:
drivers/mtd/nand/raw/ndfc.c:254 ndfc_remove()
error: dereferencing freed memory 'mtd' (line 251)
drivers/mtd/nand/raw/ndfc.c
244 static void ndfc_remove(struct platform_device *ofdev)
245 {
246 struct ndfc_controller *ndfc = dev_get_drvdata(&ofdev->dev);
247 struct nand_chip *chip = &ndfc->chip;
248 struct mtd_info *mtd = nand_to_mtd(chip);
249 int ret;
250
251 ret = mtd_device_unregister(mtd);
252 WARN_ON(ret);
This WARN_ON() would trigger if the use after free were a real issue...
Smatch is complaining that the mtd_virt_concat_destroy() function frees
mtd->name and mtd.
253 nand_cleanup(chip);
--> 254 kfree(mtd->name);
^^^^^^^^^
So this is a use after free double free.
I feel like the free in mtd_virt_concat_destroy() is done at the wrong
layer and should just be removed. But I haven't looked at it very
closely.
255 }
This email is a free service from the Smatch-CI project [smatch.sf.net].
regards,
dan carpenter
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
reply other threads:[~2026-08-19 5:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=aoVFmrEnQcDuI1fQ@stanley.mountain \
--to=error27@gmail.com \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
/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