From: sashiko-bot@kernel.org
To: "James Hilliard" <james.hilliard1@gmail.com>,
"Miquel Raynal" <miquel.raynal@bootlin.com>,
"Richard Weinberger" <richard@nod.at>,
"Vignesh Raghavendra" <vigneshr@ti.com>,
"Maxim Levitsky" <maximlevitsky@gmail.com>
Cc: linux-mtd@lists.infradead.org
Subject: Re: [PATCH v2] mtd: rawnand: r852: preserve card changes during detection work
Date: Sun, 08 Nov 2026 23:43:17 +0000 [thread overview]
Message-ID: <sashiko-outbox-204169@kernel.org> (raw)
In-Reply-To: <20261108-submit-r852-card-detect-lock-v1-v2-1-e3251bc3680a@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mtd: rawnand: r852: inconsistent card state in
r852_update_media_status()
--
commit 047b9555fe843aa22fb04dabbc400ccd2117fd0a
Author: James Hilliard <james.hilliard1@gmail.com>
mtd: rawnand: r852: preserve card changes during detection work
This commit serializes card-detect interrupt mask updates under irqlock
and samples card presence once in r852_card_detect_work() to avoid losing
concurrent card state transitions.
> diff --git a/drivers/mtd/nand/raw/r852.c b/drivers/mtd/nand/raw/r852.c
> index 92c47d351c278..4c094648673b4 100644
> --- a/drivers/mtd/nand/raw/r852.c
> +++ b/drivers/mtd/nand/raw/r852.c
[ ... ]
> @@ -684,20 +701,20 @@ static void r852_card_detect_work(struct work_struct *work)
> {
> struct r852_device *dev =
> container_of(work, struct r852_device, card_detect_work.work);
> + bool present;
>
> - r852_card_update_present(dev);
> + present = r852_card_update_present(dev);
> r852_update_card_detect(dev);
> - dev->card_unstable = 0;
>
> /* False alarm */
> - if (dev->card_detected == dev->card_registered)
> + if (present == dev->card_registered)
> goto exit;
>
> /* Read media properties */
> r852_update_media_status(dev);
>
> /* Register the card */
> - if (dev->card_detected)
> + if (present)
> r852_register_nand_device(dev);
> else
> r852_unregister_nand_device(dev);
[Severity: Medium]
Can r852_update_media_status() observe a different card state than
r852_card_detect_work() when an interrupt fires after
r852_update_card_detect() unmasks card interrupts?
kworker <hardirq>
r852_card_detect_work()
present = r852_card_update_present(dev)
/* present == true */
r852_update_card_detect(dev)
r852_irq()
dev->card_detected = 0
dev->card_unstable = 1
r852_update_media_status(dev)
if (!dev->card_detected)
return; <-- skips reading media status
if (present)
r852_register_nand_device(dev)
Because r852_update_media_status() still checks dev->card_detected while
r852_card_detect_work() branches on present, a removal interrupt during
insertion causes r852_update_media_status() to return early without
updating dev->readonly or dev->sm. r852_register_nand_device() then runs
with stale media properties, enables the hardware engine via
r852_engine_enable(), and fails in sm_register_device() without disabling
the engine on the error1 path; the subsequent delayed work sees
present == dev->card_registered (0 == 0) and exits early, leaving the
engine enabled with no card present.
Conversely, if an insertion interrupt fires while handling a removal
(present == false), r852_update_media_status() sees dev->card_detected set
and reads R852_CARD_STA and R852_DMA_CAP while dev->card_unstable is set
right before r852_unregister_nand_device() runs. Passing present to
r852_update_media_status() (or only calling it when present is true) would
keep both steps consistent.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261108-submit-r852-card-detect-lock-v1-v2-1-e3251bc3680a@gmail.com?part=1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
prev parent reply other threads:[~2026-11-08 23:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-08 23:27 [PATCH v2] mtd: rawnand: r852: preserve card changes during detection work James Hilliard
2026-11-08 23:43 ` sashiko-bot [this message]
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=sashiko-outbox-204169@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=james.hilliard1@gmail.com \
--cc=linux-mtd@lists.infradead.org \
--cc=maximlevitsky@gmail.com \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vigneshr@ti.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