From: Lee Jones <lee@kernel.org>
To: lee@kernel.org
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
Anatolij Gustschin <agust@denx.de>,
Andrew Morton <akpm@linux-foundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
Srinivas Kandagatla <srini@kernel.org>
Subject: [PATCH 07/10] nvmem: eeprom_93xx46: Hold device lock across erase/write enable sequences
Date: Thu, 3 Dec 2026 08:26:08 +0000 [thread overview]
Message-ID: <d4a7ec0e790b64ea6e2d3f40850cca30a0488457.1796286324.git.lee@kernel.org> (raw)
In-Reply-To: <cover.1796286324.git.lee@kernel.org>
eeprom_93xx46_ew() and eeprom_93xx46_eral() each acquire and release
edev->lock internally, leaving edev->lock unheld between enabling
erase/write mode, issuing the write or erase commands, and disabling
erase/write mode again. A concurrent writer or eraser can therefore
send EWDS before the first caller writes, causing the EEPROM to ignore
writes silently while returning 0. In addition, erase_store() returned
early on an erase error without sending EWDS.
Move locking to the callers (eeprom_93xx46_write() and erase_store())
so edev->lock is held across the entire EWEN, write/erase, and EWDS
sequence, assert the lock in eeprom_93xx46_ew() and
eeprom_93xx46_eral(), and always send EWDS after eeprom_93xx46_eral()
in erase_store().
Fixes: 06b4501e88ad ("misc/eeprom: add driver for microwire 93xx46 EEPROMs")
Closes: https://sashiko.dev/#/bug/linux-f81c5c58-cfcf-4b32-95d1-2f722f5dd347
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
Cc: Anatolij Gustschin <agust@denx.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Srinivas Kandagatla <srini@kernel.org>
drivers/nvmem/eeprom_93xx46.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/drivers/nvmem/eeprom_93xx46.c b/drivers/nvmem/eeprom_93xx46.c
index 6b159d5fa08e..35966552ddbd 100644
--- a/drivers/nvmem/eeprom_93xx46.c
+++ b/drivers/nvmem/eeprom_93xx46.c
@@ -7,10 +7,12 @@
#include <linux/array_size.h>
#include <linux/bits.h>
+#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/gpio/consumer.h>
#include <linux/kstrtox.h>
+#include <linux/lockdep.h>
#include <linux/log2.h>
#include <linux/module.h>
#include <linux/mutex.h>
@@ -207,7 +209,7 @@ static int eeprom_93xx46_ew(struct eeprom_93xx46_dev *edev, int is_on)
spi_message_init_with_transfers(&m, &t, 1);
- mutex_lock(&edev->lock);
+ lockdep_assert_held(&edev->lock);
gpiod_set_value_cansleep(edev->pdata->select, 1);
@@ -220,7 +222,6 @@ static int eeprom_93xx46_ew(struct eeprom_93xx46_dev *edev, int is_on)
gpiod_set_value_cansleep(edev->pdata->select, 0);
- mutex_unlock(&edev->lock);
return ret;
}
@@ -289,13 +290,13 @@ static int eeprom_93xx46_write(void *priv, unsigned int off,
step = 2;
}
+ guard(mutex)(&edev->lock);
+
/* erase/write enable */
ret = eeprom_93xx46_ew(edev, 1);
if (ret)
return ret;
- mutex_lock(&edev->lock);
-
gpiod_set_value_cansleep(edev->pdata->select, 1);
for (i = 0; i < count; i += step) {
@@ -308,8 +309,6 @@ static int eeprom_93xx46_write(void *priv, unsigned int off,
gpiod_set_value_cansleep(edev->pdata->select, 0);
- mutex_unlock(&edev->lock);
-
/* erase/write disable */
eeprom_93xx46_ew(edev, 0);
return ret;
@@ -341,7 +340,7 @@ static int eeprom_93xx46_eral(struct eeprom_93xx46_dev *edev)
spi_message_init_with_transfers(&m, &t, 1);
- mutex_lock(&edev->lock);
+ lockdep_assert_held(&edev->lock);
gpiod_set_value_cansleep(edev->pdata->select, 1);
@@ -353,7 +352,6 @@ static int eeprom_93xx46_eral(struct eeprom_93xx46_dev *edev)
gpiod_set_value_cansleep(edev->pdata->select, 0);
- mutex_unlock(&edev->lock);
return ret;
}
@@ -369,15 +367,19 @@ static ssize_t erase_store(struct device *dev, struct device_attribute *attr,
return ret;
if (erase) {
+ int ewds_ret;
+
+ guard(mutex)(&edev->lock);
+
ret = eeprom_93xx46_ew(edev, 1);
if (ret)
return ret;
ret = eeprom_93xx46_eral(edev);
+ ewds_ret = eeprom_93xx46_ew(edev, 0);
if (ret)
return ret;
- ret = eeprom_93xx46_ew(edev, 0);
- if (ret)
- return ret;
+ if (ewds_ret)
+ return ewds_ret;
}
return count;
}
--
2.56.1.911.g883d8bcb20-goog
next prev parent reply other threads:[~2026-12-03 8:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 8:26 [PATCH 00/10] nvmem: Fix Critical and High issues reported by Sashiko Lee Jones
2026-12-03 8:26 ` [PATCH 01/10] nvmem: meson-efuse: Reject negative or zero SMC size in meson_efuse_probe() Lee Jones
2026-12-03 8:26 ` [PATCH 02/10] nvmem: core: Prevent integer underflow in nvmem_cell_attr_read() Lee Jones
2026-12-03 8:26 ` [PATCH 03/10] nvmem: sprd: Avoid out-of-bounds read on partial writes in sprd_efuse_raw_prog() Lee Jones
2026-12-03 8:26 ` [PATCH 04/10] nvmem: core: Handle multi-byte bit offsets in nvmem_cell_prepare_write_buffer() Lee Jones
2026-12-03 8:26 ` [PATCH 05/10] nvmem: core: Serialise writes when toggling the write-protect GPIO Lee Jones
2026-12-03 8:26 ` [PATCH 06/10] nvmem: eeprom_93xx46: Reject unaligned writes on 16-bit devices Lee Jones
2026-12-03 8:26 ` Lee Jones [this message]
2026-12-03 8:26 ` [PATCH 08/10] nvmem: eeprom_93xx46: Use DMA-safe command buffer for SPI transfers Lee Jones
2026-12-03 8:26 ` [PATCH 09/10] nvmem: meson-efuse: Detect short reads and writes from Secure Monitor Lee Jones
2026-12-03 8:26 ` [PATCH 10/10] nvmem: stm32: Avoid OP-TEE session leak on unaligned writes Lee Jones
2026-12-03 10:16 ` Patrick DELAUNAY
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=d4a7ec0e790b64ea6e2d3f40850cca30a0488457.1796286324.git.lee@kernel.org \
--to=lee@kernel.org \
--cc=agust@denx.de \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rdunlap@infradead.org \
--cc=srini@kernel.org \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®