* [PATCH 1/8] memory: atmel-ebi: Use non-devm allocations for of_update_property()
2026-12-02 9:33 [PATCH 0/8] memory: Fix Critical and High issues reported by Sashiko Lee Jones
@ 2026-12-02 9:33 ` Lee Jones
2026-12-02 9:33 ` [PATCH 3/8] memory: stm32_omm: Depopulate child devices before disabling clocks Lee Jones
` (3 subsequent siblings)
4 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-12-02 9:33 UTC (permalink / raw)
To: lee, Krzysztof Kozlowski, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Jean-Jacques Hiblot, Boris Brezillon,
linux-kernel, linux-arm-kernel
Cc: stable
atmel_ebi_dev_disable() allocates the struct property and its name and
value strings using devm_kzalloc() and devm_kstrdup(), then installs the
property into the live device tree via of_update_property(). Because
device tree properties outlive the platform device, a subsequent probe
failure or device unbind frees those devm-managed allocations while the
property remains linked in np->properties, causing a use-after-free on
later device tree accesses.
Switch atmel_ebi_dev_disable() to kzalloc_obj() and kstrdup() with
proper kfree() unwinding on error, and drop the now-unused ebi
parameter.
Fixes: 6a4ec4cd0888 ("memory: add Atmel EBI (External Bus Interface) driver")
Closes: https://sashiko.dev/#/bug/linux-2e85dceb-25c0-4065-b486-f6bdc0a88ca6
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/memory/atmel-ebi.c | 40 +++++++++++++++++++++++++++-----------
1 file changed, 29 insertions(+), 11 deletions(-)
diff --git a/drivers/memory/atmel-ebi.c b/drivers/memory/atmel-ebi.c
index 33d7007d9d0c..89a5b5e8a334 100644
--- a/drivers/memory/atmel-ebi.c
+++ b/drivers/memory/atmel-ebi.c
@@ -18,6 +18,7 @@
#include <linux/platform_device.h>
#include <linux/property.h>
#include <linux/regmap.h>
+#include <linux/slab.h>
#include <soc/at91/atmel-sfr.h>
#define AT91_EBI_NUM_CS 8
@@ -493,26 +494,43 @@ static const struct of_device_id atmel_ebi_id_table[] = {
{ /* sentinel */ }
};
-static int atmel_ebi_dev_disable(struct atmel_ebi *ebi, struct device_node *np)
+static int atmel_ebi_dev_disable(struct device_node *np)
{
- struct device *dev = ebi->dev;
struct property *newprop;
+ int ret;
- newprop = devm_kzalloc(dev, sizeof(*newprop), GFP_KERNEL);
+ newprop = kzalloc_obj(*newprop);
if (!newprop)
return -ENOMEM;
- newprop->name = devm_kstrdup(dev, "status", GFP_KERNEL);
- if (!newprop->name)
- return -ENOMEM;
+ newprop->name = kstrdup("status", GFP_KERNEL);
+ if (!newprop->name) {
+ ret = -ENOMEM;
+ goto err_free_prop;
+ }
- newprop->value = devm_kstrdup(dev, "disabled", GFP_KERNEL);
- if (!newprop->value)
- return -ENOMEM;
+ newprop->value = kstrdup("disabled", GFP_KERNEL);
+ if (!newprop->value) {
+ ret = -ENOMEM;
+ goto err_free_name;
+ }
newprop->length = sizeof("disabled");
- return of_update_property(np, newprop);
+ ret = of_update_property(np, newprop);
+ if (ret)
+ goto err_free_value;
+
+ return 0;
+
+err_free_value:
+ kfree(newprop->value);
+err_free_name:
+ kfree(newprop->name);
+err_free_prop:
+ kfree(newprop);
+
+ return ret;
}
static int atmel_ebi_probe(struct platform_device *pdev)
@@ -603,7 +621,7 @@ static int atmel_ebi_probe(struct platform_device *pdev)
dev_err(dev, "failed to configure EBI bus for %pOF, disabling the device",
child);
- ret = atmel_ebi_dev_disable(ebi, child);
+ ret = atmel_ebi_dev_disable(child);
if (ret)
goto err_disable_clk;
}
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 3/8] memory: stm32_omm: Depopulate child devices before disabling clocks
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 ` 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
` (2 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: Lee Jones @ 2026-12-02 9:33 UTC (permalink / raw)
To: lee, Patrice Chotard, Krzysztof Kozlowski, Maxime Coquelin,
Alexandre Torgue, Christophe Kerello, linux-kernel, linux-stm32,
linux-arm-kernel
Cc: stable
stm32_omm_probe() registers child OSPI devices via
devm_of_platform_populate(), whose devres cleanup runs after
stm32_omm_remove() returns. When CR_MUXEN is set, stm32_omm_remove()
disables the OSPI child clocks while the child drivers are still bound
and may access their hardware during removal.
Populate child devices with of_platform_populate() and explicitly call
of_platform_depopulate() on partial population failure and at the start
of stm32_omm_remove() before disabling the child clocks.
Fixes: 8181d061dcff ("memory: Add STM32 Octo Memory Manager driver")
Closes: https://sashiko.dev/#/bug/linux-24c34b63-4c84-4d67-8ee1-eb7964079c44
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/memory/stm32_omm.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/memory/stm32_omm.c b/drivers/memory/stm32_omm.c
index 3599683ab04a..5ff63870421f 100644
--- a/drivers/memory/stm32_omm.c
+++ b/drivers/memory/stm32_omm.c
@@ -368,8 +368,9 @@ static int stm32_omm_probe(struct platform_device *pdev)
return ret;
}
- ret = devm_of_platform_populate(dev);
+ ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
if (ret) {
+ of_platform_depopulate(dev);
if (omm->cr & CR_MUXEN)
stm32_omm_toggle_child_clock(&pdev->dev, false);
@@ -383,6 +384,8 @@ static void stm32_omm_remove(struct platform_device *pdev)
{
struct stm32_omm *omm = platform_get_drvdata(pdev);
+ of_platform_depopulate(&pdev->dev);
+
if (omm->cr & CR_MUXEN)
stm32_omm_toggle_child_clock(&pdev->dev, false);
}
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 3/8] memory: stm32_omm: Depopulate child devices before disabling clocks
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 15:59 ` Lee Jones
0 siblings, 1 reply; 11+ messages in thread
From: Patrice CHOTARD @ 2026-12-02 13:54 UTC (permalink / raw)
To: Lee Jones, Krzysztof Kozlowski, Maxime Coquelin, Alexandre Torgue,
Christophe Kerello, linux-kernel, linux-stm32, linux-arm-kernel
Cc: stable
On 12/2/26 10:33, Lee Jones wrote:
> stm32_omm_probe() registers child OSPI devices via
> devm_of_platform_populate(), whose devres cleanup runs after
> stm32_omm_remove() returns. When CR_MUXEN is set, stm32_omm_remove()
> disables the OSPI child clocks while the child drivers are still bound
> and may access their hardware during removal.
>
> Populate child devices with of_platform_populate() and explicitly call
> of_platform_depopulate() on partial population failure and at the start
> of stm32_omm_remove() before disabling the child clocks.
>
> Fixes: 8181d061dcff ("memory: Add STM32 Octo Memory Manager driver")
> Closes: https://sashiko.dev/#/bug/linux-24c34b63-4c84-4d67-8ee1-eb7964079c44
> Cc: stable@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
> ---
> drivers/memory/stm32_omm.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/memory/stm32_omm.c b/drivers/memory/stm32_omm.c
> index 3599683ab04a..5ff63870421f 100644
> --- a/drivers/memory/stm32_omm.c
> +++ b/drivers/memory/stm32_omm.c
> @@ -368,8 +368,9 @@ static int stm32_omm_probe(struct platform_device *pdev)
> return ret;
> }
>
> - ret = devm_of_platform_populate(dev);
> + ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
> if (ret) {
> + of_platform_depopulate(dev);
> if (omm->cr & CR_MUXEN)
> stm32_omm_toggle_child_clock(&pdev->dev, false);
>
> @@ -383,6 +384,8 @@ static void stm32_omm_remove(struct platform_device *pdev)
> {
> struct stm32_omm *omm = platform_get_drvdata(pdev);
>
> + of_platform_depopulate(&pdev->dev);
> +
> if (omm->cr & CR_MUXEN)
> stm32_omm_toggle_child_clock(&pdev->dev, false);
> }
Hi Lee
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Thanks
Patrice
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH 3/8] memory: stm32_omm: Depopulate child devices before disabling clocks
2026-12-02 13:54 ` Patrice CHOTARD
@ 2026-12-02 15:59 ` Lee Jones
0 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-12-02 15:59 UTC (permalink / raw)
To: Patrice CHOTARD
Cc: Krzysztof Kozlowski, Maxime Coquelin, Alexandre Torgue,
Christophe Kerello, linux-kernel, linux-stm32, linux-arm-kernel,
stable
On Wed, 02 Dec 2026, Patrice CHOTARD wrote:
>
>
> On 12/2/26 10:33, Lee Jones wrote:
> > stm32_omm_probe() registers child OSPI devices via
> > devm_of_platform_populate(), whose devres cleanup runs after
> > stm32_omm_remove() returns. When CR_MUXEN is set, stm32_omm_remove()
> > disables the OSPI child clocks while the child drivers are still bound
> > and may access their hardware during removal.
> >
> > Populate child devices with of_platform_populate() and explicitly call
> > of_platform_depopulate() on partial population failure and at the start
> > of stm32_omm_remove() before disabling the child clocks.
> >
> > Fixes: 8181d061dcff ("memory: Add STM32 Octo Memory Manager driver")
> > Closes: https://sashiko.dev/#/bug/linux-24c34b63-4c84-4d67-8ee1-eb7964079c44
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Lee Jones <lee@kernel.org>
> > ---
> > drivers/memory/stm32_omm.c | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/memory/stm32_omm.c b/drivers/memory/stm32_omm.c
> > index 3599683ab04a..5ff63870421f 100644
> > --- a/drivers/memory/stm32_omm.c
> > +++ b/drivers/memory/stm32_omm.c
> > @@ -368,8 +368,9 @@ static int stm32_omm_probe(struct platform_device *pdev)
> > return ret;
> > }
> >
> > - ret = devm_of_platform_populate(dev);
> > + ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
> > if (ret) {
> > + of_platform_depopulate(dev);
> > if (omm->cr & CR_MUXEN)
> > stm32_omm_toggle_child_clock(&pdev->dev, false);
> >
> > @@ -383,6 +384,8 @@ static void stm32_omm_remove(struct platform_device *pdev)
> > {
> > struct stm32_omm *omm = platform_get_drvdata(pdev);
> >
> > + of_platform_depopulate(&pdev->dev);
> > +
> > if (omm->cr & CR_MUXEN)
> > stm32_omm_toggle_child_clock(&pdev->dev, false);
> > }
>
> Hi Lee
Hey bud. I hope that you are well.
> Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Thanks for these.
--
Lee Jones
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 4/8] memory: stm32_omm: Fix double FIELD_PREP() and clamp for REQ2ACK
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 3/8] memory: stm32_omm: Depopulate child devices before disabling clocks Lee Jones
@ 2026-12-02 9:33 ` 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 9:33 ` [PATCH 6/8] memory: stm32_omm: Shift and mask AMCR value in stm32_omm_set_amcr() Lee Jones
4 siblings, 1 reply; 11+ messages in thread
From: Lee Jones @ 2026-12-02 9:33 UTC (permalink / raw)
To: lee, Patrice Chotard, Krzysztof Kozlowski, Maxime Coquelin,
Alexandre Torgue, Christophe Kerello, linux-kernel, linux-stm32,
linux-arm-kernel
Cc: stable
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@vger.kernel.org
Signed-off-by: Lee Jones <lee@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
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 4/8] memory: stm32_omm: Fix double FIELD_PREP() and clamp for REQ2ACK
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
0 siblings, 0 replies; 11+ messages in thread
From: Patrice CHOTARD @ 2026-12-02 14:08 UTC (permalink / raw)
To: Lee Jones, Krzysztof Kozlowski, Maxime Coquelin, Alexandre Torgue,
Christophe Kerello, linux-kernel, linux-stm32, linux-arm-kernel
Cc: stable
On 12/2/26 10:33, Lee Jones wrote:
> 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@vger.kernel.org
> Signed-off-by: Lee Jones <lee@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);
>
Hi Lee
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Thanks
Patrice
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 5/8] memory: stm32_omm: Avoid division by zero in req2ack calculation
2026-12-02 9:33 [PATCH 0/8] memory: Fix Critical and High issues reported by Sashiko Lee Jones
` (2 preceding siblings ...)
2026-12-02 9:33 ` [PATCH 4/8] memory: stm32_omm: Fix double FIELD_PREP() and clamp for REQ2ACK Lee Jones
@ 2026-12-02 9:33 ` 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
4 siblings, 1 reply; 11+ messages in thread
From: Lee Jones @ 2026-12-02 9:33 UTC (permalink / raw)
To: lee, Patrice Chotard, Krzysztof Kozlowski, Maxime Coquelin,
Alexandre Torgue, Christophe Kerello, linux-kernel, linux-stm32,
linux-arm-kernel
Cc: stable
stm32_omm_configure() converts st,omm-req2ack-ns into clock cycles via
DIV_ROUND_UP(req2ack, NSEC_PER_SEC / clk_rate_max) - 1. If
clk_rate_max exceeds NSEC_PER_SEC (1 GHz), NSEC_PER_SEC / clk_rate_max
evaluates to zero and triggers a division by zero. For lower rates,
truncating the clock period to an integer number of nanoseconds also
loses precision.
Compute the cycle count directly in 64-bit arithmetic using
mul_u64_u64_div_u64_roundup() before subtracting one and clamping to
FIELD_MAX(CR_REQ2ACK_MASK).
Fixes: 8181d061dcff ("memory: Add STM32 Octo Memory Manager driver")
Closes: https://sashiko.dev/#/bug/linux-18fbeb54-8161-4b1a-a1b9-1556a0bf7999
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/memory/stm32_omm.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/memory/stm32_omm.c b/drivers/memory/stm32_omm.c
index 588e67bb1cc9..c6f605531239 100644
--- a/drivers/memory/stm32_omm.c
+++ b/drivers/memory/stm32_omm.c
@@ -8,7 +8,9 @@
#include <linux/bus/stm32_firewall_device.h>
#include <linux/clk.h>
#include <linux/err.h>
+#include <linux/math64.h>
#include <linux/mfd/syscon.h>
+#include <linux/minmax.h>
#include <linux/module.h>
#include <linux/of_address.h>
#include <linux/of_platform.h>
@@ -238,10 +240,11 @@ static int stm32_omm_configure(struct device *dev)
ret = of_property_read_u32(dev->of_node, "st,omm-req2ack-ns",
&req2ack);
if (!ret && req2ack) {
- req2ack = DIV_ROUND_UP(req2ack, NSEC_PER_SEC / clk_rate_max) - 1;
+ u64 cycles;
- if (req2ack > FIELD_MAX(CR_REQ2ACK_MASK))
- req2ack = FIELD_MAX(CR_REQ2ACK_MASK);
+ cycles = mul_u64_u64_div_u64_roundup(req2ack, clk_rate_max,
+ NSEC_PER_SEC);
+ req2ack = min_t(u64, cycles - 1, FIELD_MAX(CR_REQ2ACK_MASK));
}
omm->cr &= ~CR_REQ2ACK_MASK;
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 5/8] memory: stm32_omm: Avoid division by zero in req2ack calculation
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
0 siblings, 0 replies; 11+ messages in thread
From: Patrice CHOTARD @ 2026-12-02 14:17 UTC (permalink / raw)
To: Lee Jones, Krzysztof Kozlowski, Maxime Coquelin, Alexandre Torgue,
Christophe Kerello, linux-kernel, linux-stm32, linux-arm-kernel
Cc: stable
On 12/2/26 10:33, Lee Jones wrote:
> stm32_omm_configure() converts st,omm-req2ack-ns into clock cycles via
> DIV_ROUND_UP(req2ack, NSEC_PER_SEC / clk_rate_max) - 1. If
> clk_rate_max exceeds NSEC_PER_SEC (1 GHz), NSEC_PER_SEC / clk_rate_max
> evaluates to zero and triggers a division by zero. For lower rates,
> truncating the clock period to an integer number of nanoseconds also
> loses precision.
>
> Compute the cycle count directly in 64-bit arithmetic using
> mul_u64_u64_div_u64_roundup() before subtracting one and clamping to
> FIELD_MAX(CR_REQ2ACK_MASK).
>
> Fixes: 8181d061dcff ("memory: Add STM32 Octo Memory Manager driver")
> Closes: https://sashiko.dev/#/bug/linux-18fbeb54-8161-4b1a-a1b9-1556a0bf7999
> Cc: stable@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
> ---
> drivers/memory/stm32_omm.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/memory/stm32_omm.c b/drivers/memory/stm32_omm.c
> index 588e67bb1cc9..c6f605531239 100644
> --- a/drivers/memory/stm32_omm.c
> +++ b/drivers/memory/stm32_omm.c
> @@ -8,7 +8,9 @@
> #include <linux/bus/stm32_firewall_device.h>
> #include <linux/clk.h>
> #include <linux/err.h>
> +#include <linux/math64.h>
> #include <linux/mfd/syscon.h>
> +#include <linux/minmax.h>
> #include <linux/module.h>
> #include <linux/of_address.h>
> #include <linux/of_platform.h>
> @@ -238,10 +240,11 @@ static int stm32_omm_configure(struct device *dev)
> ret = of_property_read_u32(dev->of_node, "st,omm-req2ack-ns",
> &req2ack);
> if (!ret && req2ack) {
> - req2ack = DIV_ROUND_UP(req2ack, NSEC_PER_SEC / clk_rate_max) - 1;
> + u64 cycles;
>
> - if (req2ack > FIELD_MAX(CR_REQ2ACK_MASK))
> - req2ack = FIELD_MAX(CR_REQ2ACK_MASK);
> + cycles = mul_u64_u64_div_u64_roundup(req2ack, clk_rate_max,
> + NSEC_PER_SEC);
> + req2ack = min_t(u64, cycles - 1, FIELD_MAX(CR_REQ2ACK_MASK));
> }
>
> omm->cr &= ~CR_REQ2ACK_MASK;
Hi Lee
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Thanks
Patrice
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 6/8] memory: stm32_omm: Shift and mask AMCR value in stm32_omm_set_amcr()
2026-12-02 9:33 [PATCH 0/8] memory: Fix Critical and High issues reported by Sashiko Lee Jones
` (3 preceding siblings ...)
2026-12-02 9:33 ` [PATCH 5/8] memory: stm32_omm: Avoid division by zero in req2ack calculation Lee Jones
@ 2026-12-02 9:33 ` Lee Jones
2026-12-02 14:33 ` Patrice CHOTARD
4 siblings, 1 reply; 11+ messages in thread
From: Lee Jones @ 2026-12-02 9:33 UTC (permalink / raw)
To: lee, Patrice Chotard, Krzysztof Kozlowski, Maxime Coquelin,
Alexandre Torgue, Christophe Kerello, linux-kernel, linux-stm32,
linux-arm-kernel
Cc: stable
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");
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 6/8] memory: stm32_omm: Shift and mask AMCR value in stm32_omm_set_amcr()
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
0 siblings, 0 replies; 11+ messages in thread
From: Patrice CHOTARD @ 2026-12-02 14:33 UTC (permalink / raw)
To: Lee Jones, Krzysztof Kozlowski, Maxime Coquelin, Alexandre Torgue,
Christophe Kerello, linux-kernel, linux-stm32, linux-arm-kernel
Cc: stable
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
^ permalink raw reply [flat|nested] 11+ messages in thread