Skip to content

Commit 3c9e2cb

Browse files
saschahauergregkh
authored andcommitted
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: 22e9e6f ("nvmem: imx: support i.MX93 OCOTP") Signed-off-by: Sascha Hauer <[email protected]> Cc: stable <[email protected]> Reviewed-by: Peng Fan <[email protected]> Signed-off-by: Srinivas Kandagatla <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 343aa1e commit 3c9e2cb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

drivers/nvmem/imx-ocotp-ele.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,14 @@ static int imx_ocotp_reg_read(void *context, unsigned int offset, void *val, siz
7171
u32 *buf;
7272
void *p;
7373
int i;
74+
u8 skipbytes;
7475

7576
if (offset + bytes > priv->data->size)
7677
bytes = priv->data->size - offset;
7778

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);
8082
count = num_bytes >> 2;
8183

8284
p = kzalloc(num_bytes, GFP_KERNEL);
@@ -100,7 +102,7 @@ static int imx_ocotp_reg_read(void *context, unsigned int offset, void *val, siz
100102
*buf++ = readl_relaxed(reg + (i << 2));
101103
}
102104

103-
memcpy(val, (u8 *)p, bytes);
105+
memcpy(val, ((u8 *)p) + skipbytes, bytes);
104106

105107
mutex_unlock(&priv->lock);
106108

0 commit comments

Comments
 (0)