[PATCH] mtd: rawnand: r852: lock card-detection interrupt updates
James Hilliard
james.hilliard1 at gmail.com
Sun Nov 8 14:38:03 PST 2026
r852_update_card_detect() reads and writes the card interrupt enable
register without holding irqlock. A card interrupt can mask detection
interrupts and mark the card unstable between those accesses, only for
the worker to overwrite the mask with its saved value.
Hold irqlock across the register update and the transition to stable card
state. Remove the redundant unlocked card_unstable assignment in the
worker, which could otherwise clear an instability indication recorded
by an interrupt after the helper returns.
Fixes: 67e054e91924 ("mtd: nand: Add driver for Ricoh xD/SmartMedia reader")
Cc: stable at vger.kernel.org
Closes: https://lore.kernel.org/r/sashiko-outbox-204068@kernel.org/
Signed-off-by: James Hilliard <james.hilliard1 at gmail.com>
---
drivers/mtd/nand/raw/r852.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/nand/raw/r852.c b/drivers/mtd/nand/raw/r852.c
index 92c47d351c27..3ff4294a80dc 100644
--- a/drivers/mtd/nand/raw/r852.c
+++ b/drivers/mtd/nand/raw/r852.c
@@ -574,7 +574,11 @@ static void r852_card_update_present(struct r852_device *dev)
*/
static void r852_update_card_detect(struct r852_device *dev)
{
- int card_detect_reg = r852_read_reg(dev, R852_CARD_IRQ_ENABLE);
+ unsigned long flags;
+ int card_detect_reg;
+
+ spin_lock_irqsave(&dev->irqlock, flags);
+ card_detect_reg = r852_read_reg(dev, R852_CARD_IRQ_ENABLE);
dev->card_unstable = 0;
card_detect_reg &= ~(R852_CARD_IRQ_REMOVE | R852_CARD_IRQ_INSERT);
@@ -584,6 +588,7 @@ static void r852_update_card_detect(struct r852_device *dev)
R852_CARD_IRQ_REMOVE : R852_CARD_IRQ_INSERT;
r852_write_reg(dev, R852_CARD_IRQ_ENABLE, card_detect_reg);
+ spin_unlock_irqrestore(&dev->irqlock, flags);
}
static ssize_t media_type_show(struct device *sys_dev,
@@ -687,7 +692,6 @@ static void r852_card_detect_work(struct work_struct *work)
r852_card_update_present(dev);
r852_update_card_detect(dev);
- dev->card_unstable = 0;
/* False alarm */
if (dev->card_detected == dev->card_registered)
---
base-commit: 30daaf3e7897b4a8d9b72e5b0c86dd6e2a4d7d85
change-id: 20261108-submit-r852-card-detect-lock-v1-713bf5cd926b
Best regards,
--
James Hilliard <james.hilliard1 at gmail.com>
More information about the linux-mtd
mailing list