* [PATCH 1/6] nvmem: imx-ocotp-ele: simplify read beyond device check
2024-12-30 14:18 [PATCH 0/6] nvmem: fixes for 6.13 srinivas.kandagatla
@ 2024-12-30 14:18 ` srinivas.kandagatla
2024-12-30 14:18 ` [PATCH 2/6] nvmem: imx-ocotp-ele: fix reading from non zero offset srinivas.kandagatla
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: srinivas.kandagatla @ 2024-12-30 14:18 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, Sascha Hauer, stable, Peng Fan, Srinivas Kandagatla
From: Sascha Hauer <s.hauer@pengutronix.de>
Do the read beyond device check on function entry in bytes instead of
32bit words which is easier to follow.
Fixes: 22e9e6fcfb50 ("nvmem: imx: support i.MX93 OCOTP")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Cc: stable <stable@kernel.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
drivers/nvmem/imx-ocotp-ele.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/nvmem/imx-ocotp-ele.c b/drivers/nvmem/imx-ocotp-ele.c
index 1ba494497698..2e186b7d3b04 100644
--- a/drivers/nvmem/imx-ocotp-ele.c
+++ b/drivers/nvmem/imx-ocotp-ele.c
@@ -72,13 +72,13 @@ static int imx_ocotp_reg_read(void *context, unsigned int offset, void *val, siz
void *p;
int i;
+ if (offset + bytes > priv->data->size)
+ bytes = priv->data->size - offset;
+
index = offset;
num_bytes = round_up(bytes, 4);
count = num_bytes >> 2;
- if (count > ((priv->data->size >> 2) - index))
- count = (priv->data->size >> 2) - index;
-
p = kzalloc(num_bytes, GFP_KERNEL);
if (!p)
return -ENOMEM;
--
2.25.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 2/6] nvmem: imx-ocotp-ele: fix reading from non zero offset
2024-12-30 14:18 [PATCH 0/6] nvmem: fixes for 6.13 srinivas.kandagatla
2024-12-30 14:18 ` [PATCH 1/6] nvmem: imx-ocotp-ele: simplify read beyond device check srinivas.kandagatla
@ 2024-12-30 14:18 ` srinivas.kandagatla
2024-12-30 14:18 ` [PATCH 3/6] nvmem: imx-ocotp-ele: fix MAC address byte order srinivas.kandagatla
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: srinivas.kandagatla @ 2024-12-30 14:18 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, Sascha Hauer, stable, Peng Fan, Srinivas Kandagatla
From: Sascha Hauer <s.hauer@pengutronix.de>
In imx_ocotp_reg_read() the offset comes in as bytes and not as words.
This means we have to divide offset by 4 to get to the correct word
offset.
Also the incoming offset might not be word aligned. In order to read
from the OCOTP the driver aligns down the previous word boundary and
reads from there. This means we have to skip this alignment offset from
the temporary buffer when copying the data to the output buffer.
Fixes: 22e9e6fcfb50 ("nvmem: imx: support i.MX93 OCOTP")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Cc: stable <stable@kernel.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
drivers/nvmem/imx-ocotp-ele.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/nvmem/imx-ocotp-ele.c b/drivers/nvmem/imx-ocotp-ele.c
index 2e186b7d3b04..b2d21a5f77bc 100644
--- a/drivers/nvmem/imx-ocotp-ele.c
+++ b/drivers/nvmem/imx-ocotp-ele.c
@@ -71,12 +71,14 @@ static int imx_ocotp_reg_read(void *context, unsigned int offset, void *val, siz
u32 *buf;
void *p;
int i;
+ u8 skipbytes;
if (offset + bytes > priv->data->size)
bytes = priv->data->size - offset;
- index = offset;
- num_bytes = round_up(bytes, 4);
+ index = offset >> 2;
+ skipbytes = offset - (index << 2);
+ num_bytes = round_up(bytes + skipbytes, 4);
count = num_bytes >> 2;
p = kzalloc(num_bytes, GFP_KERNEL);
@@ -100,7 +102,7 @@ static int imx_ocotp_reg_read(void *context, unsigned int offset, void *val, siz
*buf++ = readl_relaxed(reg + (i << 2));
}
- memcpy(val, (u8 *)p, bytes);
+ memcpy(val, ((u8 *)p) + skipbytes, bytes);
mutex_unlock(&priv->lock);
--
2.25.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 3/6] nvmem: imx-ocotp-ele: fix MAC address byte order
2024-12-30 14:18 [PATCH 0/6] nvmem: fixes for 6.13 srinivas.kandagatla
2024-12-30 14:18 ` [PATCH 1/6] nvmem: imx-ocotp-ele: simplify read beyond device check srinivas.kandagatla
2024-12-30 14:18 ` [PATCH 2/6] nvmem: imx-ocotp-ele: fix reading from non zero offset srinivas.kandagatla
@ 2024-12-30 14:18 ` srinivas.kandagatla
2024-12-30 14:18 ` [PATCH 4/6] nvmem: imx-ocotp-ele: set word length to 1 srinivas.kandagatla
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: srinivas.kandagatla @ 2024-12-30 14:18 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, Sascha Hauer, stable, Peng Fan, Srinivas Kandagatla
From: Sascha Hauer <s.hauer@pengutronix.de>
According to the i.MX93 Fusemap the two MAC addresses are stored in
words 315 to 317 like this:
315 MAC1_ADDR_31_0[31:0]
316 MAC1_ADDR_47_32[47:32]
MAC2_ADDR_15_0[15:0]
317 MAC2_ADDR_47_16[31:0]
This means the MAC addresses are stored in reverse byte order. We have
to swap the bytes before passing them to the upper layers. The storage
format is consistent to the one used on i.MX6 using imx-ocotp driver
which does the same byte swapping as introduced here.
With this patch the MAC address on my i.MX93 TQ board correctly reads as
00:d0:93:6b:27:b8 instead of b8:27:6b:93:d0:00.
Fixes: 22e9e6fcfb50 ("nvmem: imx: support i.MX93 OCOTP")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Cc: stable <stable@kernel.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
drivers/nvmem/imx-ocotp-ele.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/drivers/nvmem/imx-ocotp-ele.c b/drivers/nvmem/imx-ocotp-ele.c
index b2d21a5f77bc..422a6d53b10e 100644
--- a/drivers/nvmem/imx-ocotp-ele.c
+++ b/drivers/nvmem/imx-ocotp-ele.c
@@ -111,6 +111,26 @@ static int imx_ocotp_reg_read(void *context, unsigned int offset, void *val, siz
return 0;
};
+static int imx_ocotp_cell_pp(void *context, const char *id, int index,
+ unsigned int offset, void *data, size_t bytes)
+{
+ u8 *buf = data;
+ int i;
+
+ /* Deal with some post processing of nvmem cell data */
+ if (id && !strcmp(id, "mac-address"))
+ for (i = 0; i < bytes / 2; i++)
+ swap(buf[i], buf[bytes - i - 1]);
+
+ return 0;
+}
+
+static void imx_ocotp_fixup_dt_cell_info(struct nvmem_device *nvmem,
+ struct nvmem_cell_info *cell)
+{
+ cell->read_post_process = imx_ocotp_cell_pp;
+}
+
static int imx_ele_ocotp_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -137,6 +157,8 @@ static int imx_ele_ocotp_probe(struct platform_device *pdev)
priv->config.stride = 1;
priv->config.priv = priv;
priv->config.read_only = true;
+ priv->config.add_legacy_fixed_of_cells = true;
+ priv->config.fixup_dt_cell_info = imx_ocotp_fixup_dt_cell_info;
mutex_init(&priv->lock);
nvmem = devm_nvmem_register(dev, &priv->config);
--
2.25.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 4/6] nvmem: imx-ocotp-ele: set word length to 1
2024-12-30 14:18 [PATCH 0/6] nvmem: fixes for 6.13 srinivas.kandagatla
` (2 preceding siblings ...)
2024-12-30 14:18 ` [PATCH 3/6] nvmem: imx-ocotp-ele: fix MAC address byte order srinivas.kandagatla
@ 2024-12-30 14:18 ` srinivas.kandagatla
2024-12-30 14:19 ` [PATCH 5/6] nvmem: qcom-spmi-sdam: Set size in struct nvmem_config srinivas.kandagatla
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: srinivas.kandagatla @ 2024-12-30 14:18 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, Sascha Hauer, stable, Peng Fan, Srinivas Kandagatla
From: Sascha Hauer <s.hauer@pengutronix.de>
The ELE hardware internally has a word length of 4. However, among other
things we store MAC addresses in the ELE OCOTP. With a length of 6 bytes
these are naturally unaligned to the word length. Therefore we must
support unaligned reads in reg_read() and indeed it works properly when
reg_read() is called via nvmem_reg_read(). Setting the word size to 4
has the only visible effect that doing unaligned reads from userspace
via bin_attr_nvmem_read() do not work because they are rejected by that
function.
Given that we have to abstract from word accesses to byte accesses in
the driver, set the word size to 1. This allows bytewise accesses from
userspace to be able to test what the driver has to support anyway.
Fixes: 22e9e6fcfb50 ("nvmem: imx: support i.MX93 OCOTP")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Cc: stable <stable@kernel.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
drivers/nvmem/imx-ocotp-ele.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/nvmem/imx-ocotp-ele.c b/drivers/nvmem/imx-ocotp-ele.c
index 422a6d53b10e..ca6dd71d8a2e 100644
--- a/drivers/nvmem/imx-ocotp-ele.c
+++ b/drivers/nvmem/imx-ocotp-ele.c
@@ -153,7 +153,7 @@ static int imx_ele_ocotp_probe(struct platform_device *pdev)
priv->config.owner = THIS_MODULE;
priv->config.size = priv->data->size;
priv->config.reg_read = priv->data->reg_read;
- priv->config.word_size = 4;
+ priv->config.word_size = 1;
priv->config.stride = 1;
priv->config.priv = priv;
priv->config.read_only = true;
--
2.25.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 5/6] nvmem: qcom-spmi-sdam: Set size in struct nvmem_config
2024-12-30 14:18 [PATCH 0/6] nvmem: fixes for 6.13 srinivas.kandagatla
` (3 preceding siblings ...)
2024-12-30 14:18 ` [PATCH 4/6] nvmem: imx-ocotp-ele: set word length to 1 srinivas.kandagatla
@ 2024-12-30 14:19 ` srinivas.kandagatla
2024-12-30 14:19 ` [PATCH 6/6] nvmem: core: improve range check for nvmem_cell_write() srinivas.kandagatla
2025-01-10 15:16 ` [PATCH 0/6] nvmem: fixes for 6.13 Greg KH
6 siblings, 0 replies; 8+ messages in thread
From: srinivas.kandagatla @ 2024-12-30 14:19 UTC (permalink / raw)
To: gregkh
Cc: linux-kernel, Luca Weiss, stable, Vladimir Zapolskiy,
Srinivas Kandagatla
From: Luca Weiss <luca.weiss@fairphone.com>
Let the nvmem core know what size the SDAM is, most notably this fixes
the size of /sys/bus/nvmem/devices/spmi_sdam*/nvmem being '0' and makes
user space work with that file.
~ # hexdump -C -s 64 /sys/bus/nvmem/devices/spmi_sdam2/nvmem
00000040 02 01 00 00 04 00 00 00 00 00 00 00 00 00 00 00 |................|
00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00000080
Fixes: 40ce9798794f ("nvmem: add QTI SDAM driver")
Cc: stable@vger.kernel.org
Signed-off-by: Luca Weiss <luca.weiss@fairphone.com>
Reviewed-by: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
drivers/nvmem/qcom-spmi-sdam.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/nvmem/qcom-spmi-sdam.c b/drivers/nvmem/qcom-spmi-sdam.c
index 9aa8f42faa4c..4f1cca6eab71 100644
--- a/drivers/nvmem/qcom-spmi-sdam.c
+++ b/drivers/nvmem/qcom-spmi-sdam.c
@@ -144,6 +144,7 @@ static int sdam_probe(struct platform_device *pdev)
sdam->sdam_config.owner = THIS_MODULE;
sdam->sdam_config.add_legacy_fixed_of_cells = true;
sdam->sdam_config.stride = 1;
+ sdam->sdam_config.size = sdam->size;
sdam->sdam_config.word_size = 1;
sdam->sdam_config.reg_read = sdam_read;
sdam->sdam_config.reg_write = sdam_write;
--
2.25.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 6/6] nvmem: core: improve range check for nvmem_cell_write()
2024-12-30 14:18 [PATCH 0/6] nvmem: fixes for 6.13 srinivas.kandagatla
` (4 preceding siblings ...)
2024-12-30 14:19 ` [PATCH 5/6] nvmem: qcom-spmi-sdam: Set size in struct nvmem_config srinivas.kandagatla
@ 2024-12-30 14:19 ` srinivas.kandagatla
2025-01-10 15:16 ` [PATCH 0/6] nvmem: fixes for 6.13 Greg KH
6 siblings, 0 replies; 8+ messages in thread
From: srinivas.kandagatla @ 2024-12-30 14:19 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, Jennifer Berringer, stable, Srinivas Kandagatla
From: Jennifer Berringer <jberring@redhat.com>
When __nvmem_cell_entry_write() is called for an nvmem cell that does
not need bit shifting, it requires that the len parameter exactly
matches the nvmem cell size. However, when the nvmem cell has a nonzero
bit_offset, it was skipping this check.
Accepting values of len larger than the cell size results in
nvmem_cell_prepare_write_buffer() trying to write past the end of a heap
buffer that it allocates. Add a check to avoid that problem and instead
return -EINVAL when len doesn't match the number of bits expected by the
nvmem cell when bit_offset is nonzero.
This check uses cell->nbits in order to allow providing the smaller size
to cells that are shifted into another byte by bit_offset. For example,
a cell with nbits=8 and nonzero bit_offset would have bytes=2 but should
accept a 1-byte write here, although no current callers depend on this.
Fixes: 69aba7948cbe ("nvmem: Add a simple NVMEM framework for consumers")
Cc: stable@vger.kernel.org
Signed-off-by: Jennifer Berringer <jberring@redhat.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
drivers/nvmem/core.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index d6494dfc20a7..845540b57e68 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -1790,6 +1790,8 @@ static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, void *buf, si
return -EINVAL;
if (cell->bit_offset || cell->nbits) {
+ if (len != BITS_TO_BYTES(cell->nbits) && len != cell->bytes)
+ return -EINVAL;
buf = nvmem_cell_prepare_write_buffer(cell, buf, len);
if (IS_ERR(buf))
return PTR_ERR(buf);
--
2.25.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 0/6] nvmem: fixes for 6.13
2024-12-30 14:18 [PATCH 0/6] nvmem: fixes for 6.13 srinivas.kandagatla
` (5 preceding siblings ...)
2024-12-30 14:19 ` [PATCH 6/6] nvmem: core: improve range check for nvmem_cell_write() srinivas.kandagatla
@ 2025-01-10 15:16 ` Greg KH
6 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2025-01-10 15:16 UTC (permalink / raw)
To: srinivas.kandagatla; +Cc: linux-kernel
On Mon, Dec 30, 2024 at 02:18:55PM +0000, srinivas.kandagatla@linaro.org wrote:
> From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
>
> Hi Greg,
>
> Here are some fixes in nvmem for 6.13, Could you queue
> these for next possible rc.
Sorry I missed these earlier. Same for this patch set, I'll queue them
up for 6.14-rc1.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 8+ messages in thread