Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH 1/8] memory: atmel-ebi: Use non-devm allocations for of_update_property()
       [not found] <cover.1796203994.git.lee@kernel.org>
@ 2026-12-02  9:33 ` Lee Jones
  2026-12-02  9:33 ` [PATCH 2/8] memory: tegra210-emc: Stop timers on suspend and prevent training re-arm Lee Jones
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 12+ 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] 12+ messages in thread

* [PATCH 2/8] memory: tegra210-emc: Stop timers on suspend and prevent training re-arm
       [not found] <cover.1796203994.git.lee@kernel.org>
  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  9:33 ` [PATCH 3/8] memory: stm32_omm: Depopulate child devices before disabling clocks Lee Jones
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-12-02  9:33 UTC (permalink / raw)
  To: lee, Krzysztof Kozlowski, Thierry Reding, Jonathan Hunter,
	Joseph Lo, linux-kernel, linux-tegra
  Cc: stable

tegra210_emc_train() unconditionally calls mod_timer(&emc->training, ...)
after releasing emc->lock.  When tegra210_emc_training_stop() deletes
the timer under emc->lock while tegra210_emc_train() is already running
on another CPU, the callback can race with the stop, execute
periodic_compensation() on an untrained rate, and re-arm itself.

In addition, tegra210_emc_suspend() detaches the EMC clock without
synchronously stopping the refresh polling timer or the periodic
training timer, allowing timer callbacks to touch EMC hardware or
re-enable training after suspend.

Track whether periodic training is enabled under emc->lock so
tegra210_emc_train() only runs and re-arms while training is active.
Synchronously stop refresh polling and periodic training in
tegra210_emc_suspend() before detaching the EMC clock, and restart
periodic training (if required by the resumed timing and not already
restarted by clk_set_rate()) and refresh polling in
tegra210_emc_resume().

Fixes: 10de21148f7d ("memory: tegra: Add EMC scaling support code for Tegra210")
Closes: https://sashiko.dev/#/bug/linux-47538f77-fb50-4a06-b49b-92dbee8b538b
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/memory/tegra/tegra210-emc-core.c | 37 +++++++++++++++++++-----
 drivers/memory/tegra/tegra210-emc.h      |  2 ++
 2 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/drivers/memory/tegra/tegra210-emc-core.c b/drivers/memory/tegra/tegra210-emc-core.c
index 044ec6f1bc32..06aba71d8fb6 100644
--- a/drivers/memory/tegra/tegra210-emc-core.c
+++ b/drivers/memory/tegra/tegra210-emc-core.c
@@ -560,28 +560,29 @@ static void tegra210_emc_train(struct timer_list *timer)
 	struct tegra210_emc *emc = timer_container_of(emc, timer, training);
 	unsigned long flags;
 
-	if (!emc->last)
-		return;
-
 	spin_lock_irqsave(&emc->lock, flags);
 
-	if (emc->sequence->periodic_compensation)
-		emc->sequence->periodic_compensation(emc);
+	if (emc->training_enabled && emc->last) {
+		if (emc->sequence->periodic_compensation)
+			emc->sequence->periodic_compensation(emc);
+
+		mod_timer(&emc->training,
+			  jiffies + msecs_to_jiffies(emc->training_interval));
+	}
 
 	spin_unlock_irqrestore(&emc->lock, flags);
-
-	mod_timer(&emc->training,
-		  jiffies + msecs_to_jiffies(emc->training_interval));
 }
 
 static void tegra210_emc_training_start(struct tegra210_emc *emc)
 {
+	emc->training_enabled = true;
 	mod_timer(&emc->training,
 		  jiffies + msecs_to_jiffies(emc->training_interval));
 }
 
 static void tegra210_emc_training_stop(struct tegra210_emc *emc)
 {
+	emc->training_enabled = false;
 	timer_delete(&emc->training);
 }
 
@@ -2001,6 +2002,7 @@ static void tegra210_emc_remove(struct platform_device *pdev)
 static int __maybe_unused tegra210_emc_suspend(struct device *dev)
 {
 	struct tegra210_emc *emc = dev_get_drvdata(dev);
+	unsigned long flags;
 	int err;
 
 	err = clk_rate_exclusive_get(emc->clk);
@@ -2009,9 +2011,19 @@ static int __maybe_unused tegra210_emc_suspend(struct device *dev)
 		return err;
 	}
 
+	emc->resume_refresh_poll = atomic_read(&emc->refresh_poll) > 0;
+	if (emc->resume_refresh_poll)
+		tegra210_emc_poll_refresh_stop(emc);
+
 	emc->resume_rate = clk_get_rate(emc->clk);
 
 	clk_set_rate(emc->clk, 204000000);
+
+	spin_lock_irqsave(&emc->lock, flags);
+	tegra210_emc_training_stop(emc);
+	spin_unlock_irqrestore(&emc->lock, flags);
+	timer_delete_sync(&emc->training);
+
 	tegra210_clk_emc_detach(emc->clk);
 
 	dev_dbg(dev, "suspending at %lu Hz\n", clk_get_rate(emc->clk));
@@ -2022,6 +2034,7 @@ static int __maybe_unused tegra210_emc_suspend(struct device *dev)
 static int __maybe_unused tegra210_emc_resume(struct device *dev)
 {
 	struct tegra210_emc *emc = dev_get_drvdata(dev);
+	unsigned long flags;
 	int err;
 
 	err = tegra210_clk_emc_attach(emc->clk, &emc->provider);
@@ -2033,6 +2046,14 @@ static int __maybe_unused tegra210_emc_resume(struct device *dev)
 	clk_set_rate(emc->clk, emc->resume_rate);
 	clk_rate_exclusive_put(emc->clk);
 
+	spin_lock_irqsave(&emc->lock, flags);
+	if (emc->last && emc->last->periodic_training && !emc->training_enabled)
+		tegra210_emc_training_start(emc);
+	spin_unlock_irqrestore(&emc->lock, flags);
+
+	if (emc->resume_refresh_poll)
+		tegra210_emc_poll_refresh_start(emc);
+
 	dev_dbg(dev, "resuming at %lu Hz\n", clk_get_rate(emc->clk));
 
 	return 0;
diff --git a/drivers/memory/tegra/tegra210-emc.h b/drivers/memory/tegra/tegra210-emc.h
index 8988bcf15290..44379034da8b 100644
--- a/drivers/memory/tegra/tegra210-emc.h
+++ b/drivers/memory/tegra/tegra210-emc.h
@@ -912,6 +912,7 @@ struct tegra210_emc {
 
 	unsigned int training_interval;
 	struct timer_list training;
+	bool training_enabled;
 
 	enum tegra210_emc_refresh refresh;
 	unsigned int refresh_poll_interval;
@@ -923,6 +924,7 @@ struct tegra210_emc {
 	int clkchange_delay;
 
 	unsigned long resume_rate;
+	bool resume_refresh_poll;
 
 	struct {
 		struct dentry *root;
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/8] memory: stm32_omm: Depopulate child devices before disabling clocks
       [not found] <cover.1796203994.git.lee@kernel.org>
  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 ` 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
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 12+ 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] 12+ messages in thread

* [PATCH 4/8] memory: stm32_omm: Fix double FIELD_PREP() and clamp for REQ2ACK
       [not found] <cover.1796203994.git.lee@kernel.org>
                   ` (2 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 12+ 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] 12+ messages in thread

* [PATCH 5/8] memory: stm32_omm: Avoid division by zero in req2ack calculation
       [not found] <cover.1796203994.git.lee@kernel.org>
                   ` (3 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
  2026-12-02  9:33 ` [PATCH 7/8] memory: emif: Avoid __fls(0) and underflow in of_get_ddr_info() Lee Jones
  6 siblings, 1 reply; 12+ 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] 12+ messages in thread

* [PATCH 6/8] memory: stm32_omm: Shift and mask AMCR value in stm32_omm_set_amcr()
       [not found] <cover.1796203994.git.lee@kernel.org>
                   ` (4 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
  2026-12-02  9:33 ` [PATCH 7/8] memory: emif: Avoid __fls(0) and underflow in of_get_ddr_info() Lee Jones
  6 siblings, 1 reply; 12+ 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] 12+ messages in thread

* [PATCH 7/8] memory: emif: Avoid __fls(0) and underflow in of_get_ddr_info()
       [not found] <cover.1796203994.git.lee@kernel.org>
                   ` (5 preceding siblings ...)
  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  9:33 ` Lee Jones
  6 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-12-02  9:33 UTC (permalink / raw)
  To: lee, Santosh Shilimkar, Krzysztof Kozlowski, Aneesh V,
	Greg Kroah-Hartman, Grant Likely, Benoit Cousson, linux-kernel
  Cc: stable

of_get_ddr_info() uses `x & (x - 1)` to test whether the "density" and
"io-width" device tree properties are powers of two before calling
__fls().  When either property is missing or zero, `0 & -1` evaluates
to zero and __fls(0) is called, which has undefined behaviour.  Small
power-of-two values (density < 64 or io-width < 4) also underflow when
subtracting 5 or 1 from the bit index.

Use is_power_of_2() and check the minimum valid values (64 Mb for
density and 4 bits for io-width) before calling __fls().

Fixes: e6b42eb6a66c ("memory: emif: add device tree support to emif driver")
Closes: https://sashiko.dev/#/bug/linux-c8a6e639-7c1a-4114-99be-f6df07f04fb4
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/memory/emif.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/memory/emif.c b/drivers/memory/emif.c
index 886c2ca0dc19..cb2c49028d6c 100644
--- a/drivers/memory/emif.c
+++ b/drivers/memory/emif.c
@@ -10,6 +10,7 @@
 #include <linux/cleanup.h>
 #include <linux/err.h>
 #include <linux/kernel.h>
+#include <linux/log2.h>
 #include <linux/reboot.h>
 #include <linux/platform_data/emif_plat.h>
 #include <linux/io.h>
@@ -892,13 +893,13 @@ static void of_get_ddr_info(struct device_node *np_emif,
 	of_property_read_u32(np_ddr, "io-width", &io_width);
 
 	/* Convert from density in Mb to the density encoding in jedc_ddr.h */
-	if (density & (density - 1))
+	if (!is_power_of_2(density) || density < 64)
 		dev_info->density = 0;
 	else
 		dev_info->density = __fls(density) - 5;
 
 	/* Convert from io_width in bits to io_width encoding in jedc_ddr.h */
-	if (io_width & (io_width - 1))
+	if (!is_power_of_2(io_width) || io_width < 4)
 		dev_info->io_width = 0;
 	else
 		dev_info->io_width = __fls(io_width) - 1;
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 12+ 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; 12+ 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] 12+ 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; 12+ 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] 12+ 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; 12+ 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] 12+ 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; 12+ 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] 12+ 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; 12+ 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] 12+ messages in thread

end of thread, other threads:[~2026-12-02 15:59 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1796203994.git.lee@kernel.org>
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 15:59     ` Lee Jones
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
2026-12-02  9:33 ` [PATCH 7/8] memory: emif: Avoid __fls(0) and underflow in of_get_ddr_info() Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox