From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4AC1CCE8D75 for ; Thu, 19 Sep 2024 10:25:38 +0000 (UTC) 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:Date:To:Cc:From:Subject: References:In-Reply-To:Content-Transfer-Encoding:MIME-Version:Content-Type: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=koofnj+ktr6gV46fpNzHN4KzwdO28LMKab3UfZ5EdNo=; b=LxrhTWi/0N6+tWphkZJM2kj2P0 7gxBoOCQo/XPfg6IO0WvQ/cpGNFUlSMTstDDJEOBC/YhBidOEh8TJrh6TgZJRLJUOkJBfqCGkJoa1 GZxEKqnMqXCJWgmyCq7xM2OY6JwENUndpbcPlzHFvAt9XFUECt88MdjAKtAXKyLSYg4mMSorjIpEl fACqGiViHkX3tlXJ3CavfzetBfM7sIhkaCdlhaDdIc+NZ4vZBCf1/jOfXcP86WSjxMqliXdt4Wb6s H4XBsDqqJVLM0D4yzo0cciX+6CSDH+7O9Ksyh8KjpSsRdLG2KY3rMx9SkV94HiJYSHRicndXt62Yg F7TQovGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1srELm-0000000A2rD-4Avh; Thu, 19 Sep 2024 10:25:27 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1srEKg-0000000A2jh-2KbL for linux-arm-kernel@lists.infradead.org; Thu, 19 Sep 2024 10:24:19 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id CC5FF5C54FD; Thu, 19 Sep 2024 10:24:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 326D7C4CEC4; Thu, 19 Sep 2024 10:24:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726741457; bh=GfU6BSfobe/pnJnguAQFwBRmWzOKDn8vaRJUwo6cZhY=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=UJBEZZbLcbb66fSRC47dgcPslISfqkDKAGzTyk03h3J5E/+WdQ32EBgOen+MSjrdK TzakDFI0MZSvcp7F0uTm5K8I+MdRBmyYWB1DVQDY5FRzCmBjCrzyTsT0R+zRnK3PlZ b/ToY+qYz2ZdrbYv9kGqb7aIaTOJz0bdJClheFgD5nFBqmZHcyWOfth0AxOBi+eC0c fvugpFNiTo/+JJsXApEzVH2wyDAR65VOlLuuAlFUz0m2Y69fz1AUHdB+8fh8w2DAKX ptLsGU2MwOPqIUEUSDSfKvDhfL83+50xPh8nskc+3n3wSwS4j0XnmgsYbx1wTWQT4n dqloVROYjUBOQ== Message-ID: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20240917132201.17513-1-adiupina@astralinux.ru> References: <20240917132201.17513-1-adiupina@astralinux.ru> Subject: Re: [PATCH v3] clk: mvebu: Prevent division by zero in clk_double_div_recalc_rate() From: Stephen Boyd Cc: Alexandra Diupina , Gregory Clement , Sebastian Hesselbarth , Michael Turquette , linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org To: Alexandra Diupina , Andrew Lunn Date: Thu, 19 Sep 2024 03:24:15 -0700 User-Agent: alot/0.10 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240919_032418_683384_248F93ED X-CRM114-Status: GOOD ( 21.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Quoting Alexandra Diupina (2024-09-17 06:22:01) > get_div() may return zero, so it is necessary to check > before calling DIV_ROUND_UP_ULL(). >=20 > Return value of get_div() depends on reg1, reg2, shift1, shift2 > fields of clk_double_div structure which are filled using the > PERIPH_DOUBLEDIV macro. This macro is called from the > PERIPH_CLK_FULL_DD and PERIPH_CLK_MUX_DD macros (the last 4 arguments). >=20 > It is not known exactly what values can be contained in the registers > at the addresses DIV_SEL0, DIV_SEL1, DIV_SEL2, so the final value of > div can be zero. Print an error message and return 0 in this case. >=20 > Found by Linux Verification Center (linuxtesting.org) with SVACE. >=20 > Fixes: 8ca4746a78ab ("clk: mvebu: Add the peripheral clock driver for Arm= ada 3700") > Signed-off-by: Alexandra Diupina > --- > v3: fix indentation > v2: added explanations to the commit message and printing=20 > of an error message when div=3D=3D0 Please stop sending as replies to previous patches. > drivers/clk/mvebu/armada-37xx-periph.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) >=20 > diff --git a/drivers/clk/mvebu/armada-37xx-periph.c b/drivers/clk/mvebu/a= rmada-37xx-periph.c > index 8701a58a5804..b32c6d4d7ee5 100644 > --- a/drivers/clk/mvebu/armada-37xx-periph.c > +++ b/drivers/clk/mvebu/armada-37xx-periph.c > @@ -343,7 +343,12 @@ static unsigned long clk_double_div_recalc_rate(stru= ct clk_hw *hw, > div =3D get_div(double_div->reg1, double_div->shift1); > div *=3D get_div(double_div->reg2, double_div->shift2); > =20 > - return DIV_ROUND_UP_ULL((u64)parent_rate, div); > + if (!div) { > + pr_err("Can't recalculate the rate of clock %s\n", hw->in= it->name); hw->init is set to NULL after registration (see clk_register() code). If div is 0 what does the hardware do? > + return 0; > + } else { > + return DIV_ROUND_UP_ULL((u64)parent_rate, div); > + } > } >