]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
nvmem: imx-ocotp-ele: simplify read beyond device check
authorSascha Hauer <s.hauer@pengutronix.de>
Mon, 30 Dec 2024 14:18:56 +0000 (14:18 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 10 Jan 2025 15:16:47 +0000 (16:16 +0100)
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>
Link: https://lore.kernel.org/r/20241230141901.263976-2-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/nvmem/imx-ocotp-ele.c

index 1ba4944976987415c0bfefdbbae23ea0d9adc934..2e186b7d3b040595cc3cf7571506640600743eb0 100644 (file)
@@ -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;