From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796204117; b=HxAQkC3mPnY2N4Jw0WXp64AXbZdQJUG7QNeyqTZEXn/tXGoZgDwDmsEepe+2BOJiVM3R 096FlNDqO4VpbjtTzEsCJe28Urt4BnTa1XZIyYd9OMo02EoXIlbiW9Xon+ysruJcSF46I HY15AqnMCiq0+OWSdOa9H2zaR72/hbMdwBmNzRlWcj9nlo68qAR5ZJ4G+Nj2To/VZrKuo /EJVy5uH4wuKurT0yuFwRDqOyuLl8bF15jryu9cEDEe2yHDA61m4N/Y2+/SD0f38N5ftu GxkZ/kwxmGj4ZiApKIAzf1XpohXp6u7zGeGroDN6e+zQxWwIhpj9DdTgPoFdYX2XF2w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796204117; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=ZT9RFLoABQQ6n9tj3fxab4ED6DHACTnyGQZ8s54wzVw=; b=T8305zTgBn4VfSXOAIh8mOxuzuxn6Pl9InLjJYpjrWJhWg65bog3AlNW/W1orTfmXcGK jyiLUTXRp0lRDAxDXXnCCczLJ07Rdhi1CfTInKDNw1Y122w2/Myhr1nr17xtszSXB96MM poPR6DzbG9w/8BKoMYUztjAi+pb5uesPNXSOk32IsiuBzOsFRTWa+zyBSV9HyU2zX7M+p Yl01iBAZ04h93g6WXizFEN2d3raw3XO5o/BYGAIernfAw66vv5CH5q1/hGiVwu/LTv0zc homPmpckoRNXy+CsIkvX8v6dbtEoegjriIR9R75+Uf249Q2qeG8nyinytknQCYaLZpw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="ff/KEWwl"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DF00606A32C; Wed, 2 Dec 2026 09:35:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ff/KEWwl Received: by smtp.kernel.org (Postfix) with ESMTPSA id 307B61F00929; Wed, 2 Dec 2026 09:35:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796204116; bh=ZT9RFLoABQQ6n9tj3fxab4ED6DHACTnyGQZ8s54wzVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ff/KEWwljCULIwolSjtQ1ASsvcnfV1u76xNnF4gXICtaI8o5VdZcRES9ep/pIE6vN Htrf7p6UYMbXFISDtnIho3GkjTamgV7LENHAuOSzo81Ydy+dvToSldhXeMOy/gdEWA r8dQRU8kZ7AuSe2od5xOof9xafqKJ5hxZBQyeY1CN34j/ZVNftGLFYcRd1Bx3ur2w6 MGaX22gXzVHcMU4Kft/awZcQOTSgC7Jij0qFtMbTKiHGindaWAGdbZEvJEgx0DoK9p 0ixwxC3fYcOYE3eTDDyJpzOHTqqyOVpof42tuYTrPZ8gKj1JvqyCnsmiVcO5trCMy+ WC1KBvKctHDvA== From: Lee Jones To: lee@kernel.org, Patrice Chotard , Krzysztof Kozlowski , Maxime Coquelin , Alexandre Torgue , Christophe Kerello , 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 5/8] memory: stm32_omm: Avoid division by zero in req2ack calculation Date: Wed, 2 Dec 2026 09:33:52 +0000 Message-ID: <407e9b75952f7c3b59a7ded80a8516da9a58ea2a.1796203994.git.lee@kernel.org> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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 #include #include +#include #include +#include #include #include #include @@ -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