* [PATCH] mtd: leave the device type unset when naming fails
@ 2026-11-08 21:11 James Hilliard
2026-11-08 21:30 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: James Hilliard @ 2026-11-08 21:11 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Jens Axboe, Jan Kara
Cc: linux-mtd, linux-kernel, stable, James Hilliard
add_mtd_device() uses dev.type to reject a second registration of the
same MTD. It sets that field before dev_set_name(), but the failure path
for the name allocation leaves it set even though no device was
registered. Retrying registration then warns and fails with -EEXIST.
Set the type only after naming succeeds. The later registration error
paths already clear it before releasing the device.
Fixes: fa06052d637b ("mtd: Convert to dynamically allocated bdi infrastructure")
Cc: stable@vger.kernel.org
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
drivers/mtd/mtdcore.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 491a27d0315f..4f62a13dc481 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -798,12 +798,12 @@ int add_mtd_device(struct mtd_info *mtd)
/* Caller should have set dev.parent to match the
* physical device, if appropriate.
*/
- mtd->dev.type = &mtd_devtype;
mtd->dev.class = &mtd_class;
mtd->dev.devt = MTD_DEVT(i);
error = dev_set_name(&mtd->dev, "mtd%d", i);
if (error)
goto fail_devname;
+ mtd->dev.type = &mtd_devtype;
dev_set_drvdata(&mtd->dev, mtd);
mtd_check_of_node(mtd);
of_node_get(mtd_get_of_node(mtd));
---
base-commit: 1c1a342aceec79528b3ba51f376eca2be5928fe7
change-id: 20261108-submit-mtd-devname-retry-v1-3f7cb2ed8083
Best regards,
--
James Hilliard <james.hilliard1@gmail.com>
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mtd: leave the device type unset when naming fails
2026-11-08 21:11 [PATCH] mtd: leave the device type unset when naming fails James Hilliard
@ 2026-11-08 21:30 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-08 21:30 UTC (permalink / raw)
To: James Hilliard, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, Jens Axboe, Jan Kara
Cc: linux-mtd
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] mtd: inaccurate Fixes tag in commit message for add_mtd_device()
--
commit e76bbebb3c54ac45bcccfcf9ff4a9021c3ac0eac
Author: James Hilliard <james.hilliard1@gmail.com>
> mtd: leave the device type unset when naming fails
>
> add_mtd_device() uses dev.type to reject a second registration of the
> same MTD. It sets that field before dev_set_name(), but the failure path
> for the name allocation leaves it set even though no device was
> registered. Retrying registration then warns and fails with -EEXIST.
>
> Set the type only after naming succeeds. The later registration error
> paths already clear it before releasing the device.
>
> Fixes: fa06052d637b ("mtd: Convert to dynamically allocated bdi infrastructure")
> Cc: stable@vger.kernel.org
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
[Severity: Low]
Should the Fixes tag reference 6697dae1e2da ("mtd: capture device name
setting failure when adding mtd") instead?
While fa06052d637b ("mtd: Convert to dynamically allocated bdi
infrastructure") changed the duplicate registration guard in
add_mtd_device() to check mtd->dev.type, dev_set_name() was not checked
for errors at that point. The fail_devname error path that returns before
device_register() with mtd->dev.type still set was introduced in
6697dae1e2da ("mtd: capture device name setting failure when adding mtd"),
and clearing mtd->dev.type on the fail_added path was added in
9d4af746af8c ("mtd: fix double free and WARN_ON in add_mtd_device() error
paths").
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261108-submit-mtd-devname-retry-v1-v1-1-a67f332c54dd@gmail.com?part=1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-08 21:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-08 21:11 [PATCH] mtd: leave the device type unset when naming fails James Hilliard
2026-11-08 21:30 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox