nvmem: imx-ocotp-ele: fix reading from non zero offset

BugLink: https://bugs.launchpad.net/bugs/2114239

commit 3c9e2cb6cecf65f7501004038c5d1ed85fb7db84 upstream.

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: 22e9e6fcfb ("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>
Link: https://lore.kernel.org/r/20241230141901.263976-3-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Noah Wager <noah.wager@canonical.com>
Signed-off-by: Mehmet Basaran <mehmet.basaran@canonical.com>
This commit is contained in:
Sascha Hauer
2024-12-30 14:18:57 +00:00
committed by Mehmet Basaran
parent aef45b2fa6
commit fae540db8f
+5 -3
View File
@@ -70,12 +70,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);
@@ -96,7 +98,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);