From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27FBD606A32C for ; Wed, 2 Dec 2026 09:35:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=gU3dyngG; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ff/KEWwl DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=ZT9RFLoABQQ6n9tj3fxab4ED6DHACTnyGQZ8s54wzVw=; b=gU3dyngGIccdd/ ReJvsPl8IWZuEUrCXr+SoKjrSl0mGwxf6adOnpAVW2rrckIsMqWLI7lO5vcVYAPAUcWp0NSyXKe/R 4382Tcva+vLgneIFV2lj1kv26CakTHdF2Vz24WrV6YmCVv2trplyBhQAgbN3Bq2/rQUt9fkLjVAEX 7SM8MhNUNLOLHrc9NPJKUSwIcr7uejih39EHVL7vrSABmGUKWWqnIJKKGAlYRwuyuG2c/iV0pFHog r+uXGDw8tpGR80hCOY0uMeFVpXwVWtU2uJ3ipUPIQzjcLxGCRSnAgYubiqvDGoHaziwO0kxFOeDjv psJpaaB++oIPytzVyR8g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYgkB-0000000ArSK-0vxR; Wed, 02 Dec 2026 09:35:19 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYgk9-0000000ArRO-1U5y for linux-arm-kernel@lists.infradead.org; Wed, 02 Dec 2026 09:35:17 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 17671401AE; Wed, 2 Dec 2026 09:35:17 +0000 (UTC) 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-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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