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 E4AF9CED245 for ; Mon, 7 Oct 2024 22:58:06 +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=CfH1DzO3PGs9QZQGnhVLIg4JlbXURxp8ugeFw+Eq3bc=; b=J1J36h+gwMpis3UaQ60Tx9eUOo WReaVwnPtcGwxu5cEEyqRIK1M9iJmtpjc2O0s4PB7DTtER3iIBS6UIBfvDrI22qbZtMa8c273PxzF RsjPkYXZvYbe5UQwUzb+AYOHwoFg6rvoWGxe5DZmx1NjLkVMwCzco7P3LuWUymA9+Op3oClOEzzNg 39VWRxfPI0XQOMdG3WJMEs/jEgTWYRPnwxGeIhh1ChWeTCOrVy1yXfXWqqAZUp742Vov4tYSQU0Ql Z0aXpwn0GCL07+4/sv1zDdSBgWF8UIudtZLVhG6y3IIlcLZaMddkF1inP6cHFee2lVUVnvZFQvl4/ OkG/oLMQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sxwfp-00000003xX6-27ZF; Mon, 07 Oct 2024 22:57:53 +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 1sxweX-00000003xP1-16p1 for linux-arm-kernel@lists.infradead.org; Mon, 07 Oct 2024 22:56:34 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id CD7955C5DBF; Mon, 7 Oct 2024 22:56:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4D9DC4CEC6; Mon, 7 Oct 2024 22:56:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728341791; bh=dKKV1EM0s4QgYvbpKmp0EseNPd4WeO/Tfh2tbg7FeGw=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=tUA6Isu5M+NsZH06dRE55DWXOfj8wFYag1NkXGKdvv9d/tSoKdGwwvjmNjFxtW03q yDf8gxvdhUOOXUb/RzSJYPSpHXU+31OsNHtGDpu8XuinkD5AQVJKlGNWp8chtuJpnB KZMTBmF+O9xTn7e5nV00YkSEzZrVpEn6jIjsOhcbJ48YUN4XZwOOSBtOqZboJ5xMs0 sJv1YjpZ2FFVssVbXwtcJ1t2LaA1qTA8iBPZdSaH6eLrezOzG0/9l6B5WiRF+IjCbC qulqa6W7A71HbGIz3QoVQAL6XGN39OQR/RnVkdozjAf8MhAuNsvGi5JCDvaNufwwh3 t0v4RDvjmOlyA== Message-ID: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: 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: 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: Mon, 07 Oct 2024 15:56:29 -0700 User-Agent: alot/0.10 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241007_155633_373962_467FFDF8 X-CRM114-Status: GOOD ( 15.58 ) 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-24 06:14:44) > >> diff --git a/drivers/clk/mvebu/armada-37xx-periph.c b/drivers/clk/mveb= u/armada-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(s= truct 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-= >init->name); > > hw->init is set to NULL after registration (see clk_register() code). If > > div is 0 what does the hardware do? >=20 > Thanks for noticing the error. Yes, hw->init is set to zero, > I will replace that code with clk_hw_get_name(hw). > If the value of div is 0, should I return 0 as stated in the > comment for .recalc_rate (in struct clk_ops) or should I > return parent_rate as in some other similar rate recalculation > functions (in some other drivers)? It depends on what the hardware does. Does the hardware pass on the parent rate if the divider is zero? If so, then return parent_rate. Or does it turn off completely? If so, return zero.