Re: [PATCH 6/8] memory: stm32_omm: Shift and mask AMCR value in stm32_omm_set_amcr()
From: Patrice CHOTARD
Date: Wed Dec 02 2026 - 09:33:27 EST
On 12/2/26 10:33, Lee Jones wrote:
> stm32_omm_set_amcr() passes the unshifted amcr value to
> regmap_update_bits() and reads back the register without masking
> against syscon_args[1] before shifting right. In addition, if
> syscon_args[1] is zero, ffs(syscon_args[1]) - 1 evaluates to -1 and
> causes an undefined shift.
>
> Reject a zero AMCR mask, shift amcr by ffs(syscon_args[1]) - 1 when
> updating the register, and mask read_amcr with syscon_args[1] before
> shifting it right.
>
> Fixes: 8181d061dcff ("memory: Add STM32 Octo Memory Manager driver")
> Closes: https://sashiko.dev/#/bug/linux-c5113484-83da-4bf2-9016-a95d3bd37a5b
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
> ---
> drivers/memory/stm32_omm.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/memory/stm32_omm.c b/drivers/memory/stm32_omm.c
> index c6f605531239..211ef9bc59b6 100644
> --- a/drivers/memory/stm32_omm.c
> +++ b/drivers/memory/stm32_omm.c
> @@ -49,7 +49,7 @@ static int stm32_omm_set_amcr(struct device *dev, bool set)
> struct resource res, res1;
> unsigned int syscon_args[2];
> int ret = 0, idx;
> - unsigned int i, amcr, read_amcr;
> + unsigned int i, amcr, read_amcr, shift;
>
> for (i = 0; i < omm->nb_child; i++) {
> idx = of_property_match_string(dev->of_node,
> @@ -105,14 +105,21 @@ static int stm32_omm_set_amcr(struct device *dev, bool set)
> return dev_err_probe(dev, PTR_ERR(syscfg_regmap),
> "Failed to get st,syscfg-amcr property\n");
>
> + if (!syscon_args[1]) {
> + dev_err(dev, "Invalid AMCR mask\n");
> + return -EINVAL;
> + }
> +
> + shift = ffs(syscon_args[1]) - 1;
> amcr = mm_ospi2_size / SZ_64M;
>
> if (set)
> - regmap_update_bits(syscfg_regmap, syscon_args[0], syscon_args[1], amcr);
> + regmap_update_bits(syscfg_regmap, syscon_args[0], syscon_args[1],
> + amcr << shift);
>
> /* read AMCR and check coherency with memory-map areas defined in DT */
> regmap_read(syscfg_regmap, syscon_args[0], &read_amcr);
> - read_amcr = read_amcr >> (ffs(syscon_args[1]) - 1);
> + read_amcr = (read_amcr & syscon_args[1]) >> shift;
>
> if (amcr != read_amcr) {
> dev_err(dev, "AMCR value not coherent with DT memory-map areas\n");
Hi Lee
Reviewed-by: Patrice Chotard <patrice.chotard@xxxxxxxxxxx>
Thanks
Patrice