From: Patrice CHOTARD <patrice.chotard@foss.st.com>
To: Lee Jones <lee@kernel.org>, Krzysztof Kozlowski <krzk@kernel.org>,
"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Christophe Kerello <christophe.kerello@foss.st.com>,
<linux-kernel@vger.kernel.org>,
<linux-stm32@st-md-mailman.stormreply.com>,
<linux-arm-kernel@lists.infradead.org>
Cc: <stable@vger.kernel.org>
Subject: Re: [PATCH 6/8] memory: stm32_omm: Shift and mask AMCR value in stm32_omm_set_amcr()
Date: Wed, 2 Dec 2026 15:33:07 +0100 [thread overview]
Message-ID: <de40911e-c34a-4493-89cf-4a9056c764cd@foss.st.com> (raw)
In-Reply-To: <38de9a4431c4d997fc56cefda75ca8d6ae01c56c.1796203994.git.lee@kernel.org>
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@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
> ---
> 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@foss.st.com>
Thanks
Patrice
next prev parent reply other threads:[~2026-12-02 14:33 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 9:33 [PATCH 0/8] memory: Fix Critical and High issues reported by Sashiko Lee Jones
2026-12-02 9:33 ` [PATCH 1/8] memory: atmel-ebi: Use non-devm allocations for of_update_property() Lee Jones
2026-12-02 9:33 ` [PATCH 2/8] memory: tegra210-emc: Stop timers on suspend and prevent training re-arm Lee Jones
2026-12-02 9:33 ` [PATCH 3/8] memory: stm32_omm: Depopulate child devices before disabling clocks Lee Jones
2026-12-02 13:54 ` Patrice CHOTARD
2026-12-02 9:33 ` [PATCH 4/8] memory: stm32_omm: Fix double FIELD_PREP() and clamp for REQ2ACK Lee Jones
2026-12-02 14:08 ` Patrice CHOTARD
2026-12-02 9:33 ` [PATCH 5/8] memory: stm32_omm: Avoid division by zero in req2ack calculation Lee Jones
2026-12-02 14:17 ` Patrice CHOTARD
2026-12-02 9:33 ` [PATCH 6/8] memory: stm32_omm: Shift and mask AMCR value in stm32_omm_set_amcr() Lee Jones
2026-12-02 14:33 ` Patrice CHOTARD [this message]
2026-12-02 9:33 ` [PATCH 7/8] memory: emif: Avoid __fls(0) and underflow in of_get_ddr_info() Lee Jones
2026-12-02 9:33 ` [PATCH 8/8] memory: emif: Clear invalid custom_configs in get_device_details() Lee Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=de40911e-c34a-4493-89cf-4a9056c764cd@foss.st.com \
--to=patrice.chotard@foss.st.com \
--cc=alexandre.torgue@foss.st.com \
--cc=christophe.kerello@foss.st.com \
--cc=krzk@kernel.org \
--cc=lee@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®