Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mtd: rawnand: r852: disable the engine when card registration fails
@ 2026-11-09  0:20 James Hilliard
  2026-11-09  0:24 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: James Hilliard @ 2026-11-09  0:20 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Maxim Levitsky
  Cc: linux-mtd, linux-kernel, stable, James Hilliard

r852_register_nand_device() enables the NAND engine before scanning and
registering the card. If sm_register_device() or device_create_file()
fails, the error path leaves the engine enabled while card_registered
remains clear.

A subsequent removal work item sees no registered card and skips
unregistration. The device removal path also returns immediately from
r852_unregister_nand_device() in this state, so neither path disables
the engine.

Disable the engine in the common registration-failure path after any
required NAND cleanup.

Fixes: 67e054e91924 ("mtd: nand: Add driver for Ricoh xD/SmartMedia reader")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/sashiko-outbox-204169@kernel.org/
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
 drivers/mtd/nand/raw/r852.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/nand/raw/r852.c b/drivers/mtd/nand/raw/r852.c
index 92c47d351c27..073f96f73be3 100644
--- a/drivers/mtd/nand/raw/r852.c
+++ b/drivers/mtd/nand/raw/r852.c
@@ -656,6 +656,7 @@ static int r852_register_nand_device(struct r852_device *dev)
 	WARN_ON(mtd_device_unregister(nand_to_mtd(dev->chip)));
 	nand_cleanup(dev->chip);
 error1:
+	r852_engine_disable(dev);
 	/* Force card redetect */
 	dev->card_detected = 0;
 	return -1;

---
base-commit: 30daaf3e7897b4a8d9b72e5b0c86dd6e2a4d7d85
change-id: 20261108-submit-r852-registration-unwind-v1-5c7cef4b5a70

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: rawnand: r852: disable the engine when card registration fails
  2026-11-09  0:20 [PATCH] mtd: rawnand: r852: disable the engine when card registration fails James Hilliard
@ 2026-11-09  0:24 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-09  0:24 UTC (permalink / raw)
  To: James Hilliard, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, Maxim Levitsky
  Cc: linux-mtd

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] mtd: rawnand: r852: ignored sm_controller_ops in
  sm_register_device() [1]
--

commit b0db256c0e7e95a57788ef377b493f1dae9d2218
Author: James Hilliard <james.hilliard1@gmail.com>

mtd: rawnand: r852: disable the engine when card registration fails

This commit calls r852_engine_disable() in the error path of
r852_register_nand_device() when sm_register_device() or
device_create_file() fails.

Link: https://lore.kernel.org/r/sashiko-outbox-204169@kernel.org/

> diff --git a/drivers/mtd/nand/raw/r852.c b/drivers/mtd/nand/raw/r852.c
> index 92c47d351c278..073f96f73be36 100644
> --- a/drivers/mtd/nand/raw/r852.c
> +++ b/drivers/mtd/nand/raw/r852.c
> @@ -656,6 +656,7 @@ static int r852_register_nand_device(struct r852_device *dev)
>  	WARN_ON(mtd_device_unregister(nand_to_mtd(dev->chip)));
>  	nand_cleanup(dev->chip);
>  error1:
> +	r852_engine_disable(dev);
>  	/* Force card redetect */
>  	dev->card_detected = 0;
>  	return -1;

[Severity: High]
This problem wasn't introduced by this patch, but does sm_register_device()
called earlier in r852_register_nand_device() have its sm_controller_ops
ignored [1]?

r852_probe() initializes chip->controller to &dev->controller (with
r852_ops), while sm_register_device() sets sm_controller_ops on
chip->legacy.dummy_controller:

drivers/mtd/nand/raw/sm_common.c:sm_register_device() {
    ...
	chip->legacy.dummy_controller.ops = &sm_controller_ops;
	flash_ids = smartmedia ? nand_smartmedia_flash_ids : nand_xd_flash_ids;
	ret = nand_scan_with_ids(chip, 1, flash_ids);
    ...
}

Because chip->controller is already non-NULL, nand_set_defaults() ignores
dummy_controller, so nand_attach() calls r852_attach_chip() without calling
sm_attach_chip(), leaving the card's OOB layout, bad-block marker
parameters, and page-size validation unconfigured.

[1] https://sashiko.dev/#/bug/linux-4d4f9cfa-07ac-4319-9927-3acf4cf70ca3

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261108-submit-r852-registration-unwind-v1-v1-1-e54be2c652c2@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-09  0:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-09  0:20 [PATCH] mtd: rawnand: r852: disable the engine when card registration fails James Hilliard
2026-11-09  0:24 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox