Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Patrice Chotard <patrice.chotard@foss.st.com>,
	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: [PATCH 6/8] memory: stm32_omm: Shift and mask AMCR value in stm32_omm_set_amcr()
Date: Wed,  2 Dec 2026 09:33:53 +0000	[thread overview]
Message-ID: <38de9a4431c4d997fc56cefda75ca8d6ae01c56c.1796203994.git.lee@kernel.org> (raw)
In-Reply-To: <cover.1796203994.git.lee@kernel.org>

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



      parent reply	other threads:[~2026-12-02  9:35 UTC|newest]

Thread overview: 6+ 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 3/8] memory: stm32_omm: Depopulate child devices before disabling clocks 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  9:33 ` [PATCH 5/8] memory: stm32_omm: Avoid division by zero in req2ack calculation Lee Jones
2026-12-02  9:33 ` Lee Jones [this message]

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=38de9a4431c4d997fc56cefda75ca8d6ae01c56c.1796203994.git.lee@kernel.org \
    --to=lee@kernel.org \
    --cc=alexandre.torgue@foss.st.com \
    --cc=christophe.kerello@foss.st.com \
    --cc=krzk@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=patrice.chotard@foss.st.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