[PATCH 4/8] memory: stm32_omm: Fix double FIELD_PREP() and clamp for REQ2ACK

Lee Jones lee at kernel.org
Wed Dec 2 01:33:51 PST 2026


stm32_omm_configure() applies FIELD_PREP(CR_REQ2ACK_MASK, req2ack)
twice in succession.  The first call shifts the value into bits 23:16
leaving bits 7:0 zero, so the second FIELD_PREP() always masks and
writes zero into OMM_CR.  In addition, CR_REQ2ACK_MASK is an 8-bit
field (maximum value 255), so clamping req2ack to 256 overflows the
field mask.

Drop the redundant FIELD_PREP() call and clamp req2ack against
FIELD_MAX(CR_REQ2ACK_MASK).

Fixes: 8181d061dcff ("memory: Add STM32 Octo Memory Manager driver")
Closes: https://sashiko.dev/#/bug/linux-92be9e12-b6dd-44b3-8d8a-00635a3c1527
Cc: stable at vger.kernel.org
Signed-off-by: Lee Jones <lee at kernel.org>
---
 drivers/memory/stm32_omm.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/memory/stm32_omm.c b/drivers/memory/stm32_omm.c
index 5ff63870421f..588e67bb1cc9 100644
--- a/drivers/memory/stm32_omm.c
+++ b/drivers/memory/stm32_omm.c
@@ -240,12 +240,10 @@ static int stm32_omm_configure(struct device *dev)
 			if (!ret && req2ack) {
 				req2ack = DIV_ROUND_UP(req2ack, NSEC_PER_SEC / clk_rate_max) - 1;
 
-				if (req2ack > 256)
-					req2ack = 256;
+				if (req2ack > FIELD_MAX(CR_REQ2ACK_MASK))
+					req2ack = FIELD_MAX(CR_REQ2ACK_MASK);
 			}
 
-			req2ack = FIELD_PREP(CR_REQ2ACK_MASK, req2ack);
-
 			omm->cr &= ~CR_REQ2ACK_MASK;
 			omm->cr |= FIELD_PREP(CR_REQ2ACK_MASK, req2ack);
 
-- 
2.56.1.911.g883d8bcb20-goog




More information about the linux-arm-kernel mailing list