[PATCH 06/10] nvmem: eeprom_93xx46: Reject unaligned writes on 16-bit devices

From: Lee Jones

Date: Thu Dec 03 2026 - 03:26:48 EST


eeprom_93xx46_probe() hardcodes nvmem_config.word_size to 1 even for
16-bit (EE_ADDR16) devices, while eeprom_93xx46_write() silently masks
off the low bit of count and returns 0 on success. A 1-byte write
therefore silently writes nothing and reports success, and an odd
offset is shifted down by eeprom_93xx46_write_word(), overwriting the
adjacent byte.

Set nvmem_config.word_size to 2 for EE_ADDR16 devices and reject odd
offsets or byte counts in eeprom_93xx46_write() with -EINVAL.

Fixes: a8ab316ab125 ("nvmem: 93xx46: remove nvmem regmap dependency")
Closes: https://sashiko.dev/#/bug/linux-2aded405-6835-472f-bb94-d76d40cc2d96
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---

Cc: Anatolij Gustschin <agust@xxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
Cc: Srinivas Kandagatla <srini@xxxxxxxxxx>

drivers/nvmem/eeprom_93xx46.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/nvmem/eeprom_93xx46.c b/drivers/nvmem/eeprom_93xx46.c
index f9c3ab52c2f9..6b159d5fa08e 100644
--- a/drivers/nvmem/eeprom_93xx46.c
+++ b/drivers/nvmem/eeprom_93xx46.c
@@ -282,10 +282,11 @@ static int eeprom_93xx46_write(void *priv, unsigned int off,
if (unlikely(!count))
return count;

- /* only write even number of bytes on 16-bit devices */
+ /* only write even offsets and counts on 16-bit devices */
if (edev->pdata->flags & EE_ADDR16) {
+ if ((off & 1) || (count & 1))
+ return -EINVAL;
step = 2;
- count &= ~1;
}

/* erase/write enable */
@@ -513,7 +514,7 @@ static int eeprom_93xx46_probe(struct spi_device *spi)
edev->nvmem_config.reg_write = eeprom_93xx46_write;
edev->nvmem_config.priv = edev;
edev->nvmem_config.stride = 4;
- edev->nvmem_config.word_size = 1;
+ edev->nvmem_config.word_size = (pd->flags & EE_ADDR16) ? 2 : 1;
edev->nvmem_config.size = edev->size;

edev->nvmem = devm_nvmem_register(&spi->dev, &edev->nvmem_config);
--
2.56.1.911.g883d8bcb20-goog