Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

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>
Link: https://lore.kernel.org/r/20241230141901.263976-3-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Sascha Hauer and committed by
Greg Kroah-Hartman
3c9e2cb6 343aa1e2

+5 -3
+5 -3
drivers/nvmem/imx-ocotp-ele.c
··· 71 71 u32 *buf; 72 72 void *p; 73 73 int i; 74 + u8 skipbytes; 74 75 75 76 if (offset + bytes > priv->data->size) 76 77 bytes = priv->data->size - offset; 77 78 78 - index = offset; 79 - num_bytes = round_up(bytes, 4); 79 + index = offset >> 2; 80 + skipbytes = offset - (index << 2); 81 + num_bytes = round_up(bytes + skipbytes, 4); 80 82 count = num_bytes >> 2; 81 83 82 84 p = kzalloc(num_bytes, GFP_KERNEL); ··· 102 100 *buf++ = readl_relaxed(reg + (i << 2)); 103 101 } 104 102 105 - memcpy(val, (u8 *)p, bytes); 103 + memcpy(val, ((u8 *)p) + skipbytes, bytes); 106 104 107 105 mutex_unlock(&priv->lock); 108 106