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

From: Lee Jones

Date: Wed Dec 02 2026 - 04:35:18 EST


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@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
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