[PATCH 10/10] remoteproc: imx_dsp_rproc: Fix off-by-one bitmask for trailing bytes

Lee Jones lee at kernel.org
Mon Nov 23 09:20:54 PST 2026


When size is not a multiple of 4, both imx_dsp_rproc_memcpy() and
imx_dsp_rproc_memset() compute affected_mask as GENMASK(8 * r, 0) for
the remaining r bytes (1 <= r <= 3).  Because GENMASK(h, l) is inclusive
of bit h, GENMASK(8 * r, 0) sets 8 * r + 1 bits and clears or overwrites
the least-significant bit of the first byte past the end of the target
region during the 32-bit read-modify-write.

Use GENMASK(8 * r - 1, 0) to mask exclusively the r trailing bytes.

Fixes: 408ec1ff0caa ("remoteproc: imx_dsp_rproc: Add custom memory copy implementation for i.MX DSP Cores")
Closes: https://sashiko.dev/#/bug/linux-2e407b68-a7e9-42ff-a613-e61b47a4461b
Cc: stable at vger.kernel.org
Signed-off-by: Lee Jones <lee at kernel.org>
---
 drivers/remoteproc/imx_dsp_rproc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/remoteproc/imx_dsp_rproc.c b/drivers/remoteproc/imx_dsp_rproc.c
index 2771043ee433..0e0325d5df9f 100644
--- a/drivers/remoteproc/imx_dsp_rproc.c
+++ b/drivers/remoteproc/imx_dsp_rproc.c
@@ -799,7 +799,7 @@ static int imx_dsp_rproc_memcpy(void *dst, const void *src, size_t size)
 		writel(source[i], dest + i * 4);
 
 	if (r) {
-		affected_mask = GENMASK(8 * r, 0);
+		affected_mask = GENMASK(8 * r - 1, 0);
 
 		/*
 		 * first read the 32bit data of dest, then change affected
@@ -849,7 +849,7 @@ static int imx_dsp_rproc_memset(void *addr, u8 value, size_t size)
 	}
 
 	if (r) {
-		affected_mask = GENMASK(8 * r, 0);
+		affected_mask = GENMASK(8 * r - 1, 0);
 
 		/*
 		 * first read the 32bit data of addr, then change affected
-- 
2.56.1.750.gf70dc682cf-goog




More information about the linux-arm-kernel mailing list