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 08/10] nvmem: eeprom_93xx46: Use DMA-safe command buffer for SPI transfers
Date: Thu, 3 Dec 2026 08:26:09 +0000 [thread overview]
Message-ID: <c518a5e2eb986d93f64c5f5161142043ba029155.1796286324.git.lee@kernel.org> (raw)
In-Reply-To: <cover.1796286324.git.lee@kernel.org>
eeprom_93xx46_read(), eeprom_93xx46_ew(), eeprom_93xx46_write_word(),
and eeprom_93xx46_eral() all pass a stack-allocated u16 cmd_addr as
tx_buf to spi_sync(). Stack memory is not DMA-safe under
CONFIG_VMAP_STACK or DMA-capable SPI controllers.
Move cmd_addr into the heap-allocated struct eeprom_93xx46_dev with
cacheline alignment, serialised under edev->lock across all four SPI
operations.
Fixes: 06b4501e88ad ("misc/eeprom: add driver for microwire 93xx46 EEPROMs")
Closes: https://sashiko.dev/#/bug/linux-d67d0811-56d4-4dbc-a558-75418ab48ad0
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 | 58 ++++++++++++++++++-----------------
1 file changed, 30 insertions(+), 28 deletions(-)
diff --git a/drivers/nvmem/eeprom_93xx46.c b/drivers/nvmem/eeprom_93xx46.c
index 35966552ddbd..e191ac2e3745 100644
--- a/drivers/nvmem/eeprom_93xx46.c
+++ b/drivers/nvmem/eeprom_93xx46.c
@@ -7,6 +7,7 @@
#include <linux/array_size.h>
#include <linux/bits.h>
+#include <linux/cache.h>
#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/device.h>
@@ -87,6 +88,7 @@ struct eeprom_93xx46_dev {
struct nvmem_device *nvmem;
int addrlen;
int size;
+ u16 cmd_addr ____cacheline_aligned;
};
static inline bool has_quirk_single_word_read(struct eeprom_93xx46_dev *edev)
@@ -129,28 +131,29 @@ static int eeprom_93xx46_read(void *priv, unsigned int off,
while (count) {
struct spi_message m;
struct spi_transfer t[2] = {};
- u16 cmd_addr = OP_READ << edev->addrlen;
size_t nbytes = count;
+ edev->cmd_addr = OP_READ << edev->addrlen;
+
if (edev->pdata->flags & EE_ADDR8) {
- cmd_addr |= off;
+ edev->cmd_addr |= off;
if (has_quirk_single_word_read(edev))
nbytes = 1;
} else {
- cmd_addr |= (off >> 1);
+ edev->cmd_addr |= (off >> 1);
if (has_quirk_single_word_read(edev))
nbytes = 2;
}
dev_dbg(&edev->spi->dev, "read cmd 0x%x, %d Hz\n",
- cmd_addr, edev->spi->max_speed_hz);
+ edev->cmd_addr, edev->spi->max_speed_hz);
if (has_quirk_extra_read_cycle(edev)) {
- cmd_addr <<= 1;
+ edev->cmd_addr <<= 1;
bits += 1;
}
- t[0].tx_buf = (char *)&cmd_addr;
+ t[0].tx_buf = &edev->cmd_addr;
t[0].len = 2;
t[0].bits_per_word = bits;
@@ -187,30 +190,29 @@ static int eeprom_93xx46_ew(struct eeprom_93xx46_dev *edev, int is_on)
struct spi_message m;
struct spi_transfer t = {};
int bits, ret;
- u16 cmd_addr;
+
+ lockdep_assert_held(&edev->lock);
/* The opcode in front of the address is three bits. */
bits = edev->addrlen + 3;
- cmd_addr = OP_START << edev->addrlen;
- cmd_addr |= (is_on ? ADDR_EWEN : ADDR_EWDS) << (edev->addrlen - 6);
+ edev->cmd_addr = OP_START << edev->addrlen;
+ edev->cmd_addr |= (is_on ? ADDR_EWEN : ADDR_EWDS) << (edev->addrlen - 6);
if (has_quirk_instruction_length(edev)) {
- cmd_addr <<= 2;
+ edev->cmd_addr <<= 2;
bits += 2;
}
dev_dbg(&edev->spi->dev, "ew %s cmd 0x%04x, %d bits\n",
- str_enable_disable(is_on), cmd_addr, bits);
+ str_enable_disable(is_on), edev->cmd_addr, bits);
- t.tx_buf = &cmd_addr;
+ t.tx_buf = &edev->cmd_addr;
t.len = 2;
t.bits_per_word = bits;
spi_message_init_with_transfers(&m, &t, 1);
- lockdep_assert_held(&edev->lock);
-
gpiod_set_value_cansleep(edev->pdata->select, 1);
ret = spi_sync(edev->spi, &m);
@@ -232,7 +234,8 @@ eeprom_93xx46_write_word(struct eeprom_93xx46_dev *edev,
struct spi_message m;
struct spi_transfer t[2] = {};
int bits, data_len, ret;
- u16 cmd_addr;
+
+ lockdep_assert_held(&edev->lock);
if (unlikely(off >= edev->size))
return -EINVAL;
@@ -240,19 +243,19 @@ eeprom_93xx46_write_word(struct eeprom_93xx46_dev *edev,
/* The opcode in front of the address is three bits. */
bits = edev->addrlen + 3;
- cmd_addr = OP_WRITE << edev->addrlen;
+ edev->cmd_addr = OP_WRITE << edev->addrlen;
if (edev->pdata->flags & EE_ADDR8) {
- cmd_addr |= off;
+ edev->cmd_addr |= off;
data_len = 1;
} else {
- cmd_addr |= (off >> 1);
+ edev->cmd_addr |= (off >> 1);
data_len = 2;
}
- dev_dbg(&edev->spi->dev, "write cmd 0x%x\n", cmd_addr);
+ dev_dbg(&edev->spi->dev, "write cmd 0x%x\n", edev->cmd_addr);
- t[0].tx_buf = (char *)&cmd_addr;
+ t[0].tx_buf = &edev->cmd_addr;
t[0].len = 2;
t[0].bits_per_word = bits;
@@ -319,29 +322,28 @@ static int eeprom_93xx46_eral(struct eeprom_93xx46_dev *edev)
struct spi_message m;
struct spi_transfer t = {};
int bits, ret;
- u16 cmd_addr;
+
+ lockdep_assert_held(&edev->lock);
/* The opcode in front of the address is three bits. */
bits = edev->addrlen + 3;
- cmd_addr = OP_START << edev->addrlen;
- cmd_addr |= ADDR_ERAL << (edev->addrlen - 6);
+ edev->cmd_addr = OP_START << edev->addrlen;
+ edev->cmd_addr |= ADDR_ERAL << (edev->addrlen - 6);
if (has_quirk_instruction_length(edev)) {
- cmd_addr <<= 2;
+ edev->cmd_addr <<= 2;
bits += 2;
}
- dev_dbg(&edev->spi->dev, "eral cmd 0x%04x, %d bits\n", cmd_addr, bits);
+ dev_dbg(&edev->spi->dev, "eral cmd 0x%04x, %d bits\n", edev->cmd_addr, bits);
- t.tx_buf = &cmd_addr;
+ t.tx_buf = &edev->cmd_addr;
t.len = 2;
t.bits_per_word = bits;
spi_message_init_with_transfers(&m, &t, 1);
- lockdep_assert_held(&edev->lock);
-
gpiod_set_value_cansleep(edev->pdata->select, 1);
ret = spi_sync(edev->spi, &m);
--
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 ` [PATCH 07/10] nvmem: eeprom_93xx46: Hold device lock across erase/write enable sequences Lee Jones
2026-12-03 8:26 ` Lee Jones [this message]
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=c518a5e2eb986d93f64c5f5161142043ba029155.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®