From patchwork Tue Sep 17 13:22:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandra Diupina X-Patchwork-Id: 13806163 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 C0F12C021A7 for ; Tue, 17 Sep 2024 13:24:05 +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: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-Owner; bh=Yq0XxEmYMOt2gBRG6tHpN7Y2nem3g/3bA4mx0gVCycE=; b=gkU57MeIWILTN2KED8C6wAQP41 U6VByjgU86rQe9nyHO3YmutxdxK7ZwHvcadWsV/yOoJju+euCDABydnh4O+bUDt21n4vSEyfNDQDM mxX/A4LXvKwFu9CCHpwtkuDRGghzHSH3yO/c6bSMnU8qK5/cmNOvmHrbvdmXrRI1v+PY7O+P05fpg oeOgwbuN2TEtgGuqD+4pIicKFFO2O3b5qLOMOzQSs9t1QBMwXxdDMp7gVOx1C/14mwHmp4UyBCwqC 5585Vdi2NDYHX2xNz1kTZ48KN6KxEzBtfMzlfUbz6JawDawXWw6RNGsfuxedz2wrUOpCqx2bcgGlg pjctjk0w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sqYBO-00000006Djf-2dcf; Tue, 17 Sep 2024 13:23:54 +0000 Received: from mx.astralinux.ru ([89.232.161.68]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sqYAI-00000006Dee-0x3E for linux-arm-kernel@lists.infradead.org; Tue, 17 Sep 2024 13:22:48 +0000 Received: from [10.177.185.109] (helo=new-mail.astralinux.ru) by mx.astralinux.ru with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sqY8g-00D6mY-No; Tue, 17 Sep 2024 16:21:06 +0300 Received: from rbta-msk-lt-302690.astralinux.ru (unknown [10.198.39.98]) by new-mail.astralinux.ru (Postfix) with ESMTPA id 4X7Mrt42DFzkXGg; Tue, 17 Sep 2024 16:22:22 +0300 (MSK) From: Alexandra Diupina To: Andrew Lunn Cc: Alexandra Diupina , Gregory Clement , Sebastian Hesselbarth , Michael Turquette , Stephen Boyd , linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: [PATCH v3] clk: mvebu: Prevent division by zero in clk_double_div_recalc_rate() Date: Tue, 17 Sep 2024 16:22:01 +0300 Message-Id: <20240917132201.17513-1-adiupina@astralinux.ru> X-Mailer: git-send-email 2.30.2 In-Reply-To: <82162974-00b5-44c9-bbb8-701e6c871bb0@lunn.ch> References: MIME-Version: 1.0 X-DrWeb-SpamScore: 0 X-DrWeb-SpamState: legit X-DrWeb-SpamDetail: gggruggvucftvghtrhhoucdtuddrgedvfedrvdehuddgtddvucetufdoteggodetrfcurfhrohhfihhlvgemucfftfghgfeunecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeetlhgvgigrnhgurhgrucffihhuphhinhgruceorgguihhuphhinhgrsegrshhtrhgrlhhinhhugidrrhhuqeenucggtffrrghtthgvrhhnpeefkedufedvkeffuedtgfdugeeutdegvdffffejfffgleffieduhfejvdelffdvudenucffohhmrghinheplhhinhhugihtvghsthhinhhgrdhorhhgnecukfhppedutddrudelkedrfeelrdelkeenucfrrghrrghmpehhvghloheprhgsthgrqdhmshhkqdhlthdqfedtvdeiledtrdgrshhtrhgrlhhinhhugidrrhhupdhinhgvthepuddtrdduleekrdefledrleekmeegudegheeipdhmrghilhhfrhhomheprgguihhuphhinhgrsegrshhtrhgrlhhinhhugidrrhhupdhnsggprhgtphhtthhopedutddprhgtphhtthhopegrnhgurhgvfieslhhunhhnrdgthhdprhgtphhtthhopegrughiuhhpihhnrgesrghsthhrrghlihhnuhigrdhruhdprhgtphhtthhopehgrhgvghhorhihrdgtlhgvmhgvnhhtsegsohhothhlihhnrdgtohhmpdhrtghpthhtohepshgvsggrshhtihgrnhdrhhgvshhsvghlsggrrhhthhesghhmrghilhdrtghomhdprhgtphhtth hopehmthhurhhquhgvthhtvgessggrhihlihgsrhgvrdgtohhmpdhrtghpthhtohepshgsohihugeskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrghrmhdqkhgvrhhnvghlsehlihhsthhsrdhinhhfrhgruggvrggurdhorhhgpdhrtghpthhtoheplhhinhhugidqtghlkhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlvhgtqdhprhhojhgvtghtsehlihhnuhigthgvshhtihhnghdrohhrghenucffrhdrhggvsgcutehnthhishhprghmmecunecuvfgrghhsme X-DrWeb-SpamVersion: Dr.Web Antispam 1.0.7.202406240#1726239283#02 X-AntiVirus: Checked by Dr.Web [MailD: 11.1.19.2307031128, SE: 11.1.12.2210241838, Core engine: 7.00.65.05230, Virus records: 12178289, Updated: 2024-Sep-16 05:03:55 UTC] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240917_062246_290310_69A5FEF6 X-CRM114-Status: GOOD ( 12.53 ) 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 get_div() may return zero, so it is necessary to check before calling DIV_ROUND_UP_ULL(). 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). 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. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 8ca4746a78ab ("clk: mvebu: Add the peripheral clock driver for Armada 3700") Signed-off-by: Alexandra Diupina --- v3: fix indentation v2: added explanations to the commit message and printing of an error message when div==0 drivers/clk/mvebu/armada-37xx-periph.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/clk/mvebu/armada-37xx-periph.c b/drivers/clk/mvebu/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(struct clk_hw *hw, div = get_div(double_div->reg1, double_div->shift1); div *= get_div(double_div->reg2, double_div->shift2); - 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); + return 0; + } else { + return DIV_ROUND_UP_ULL((u64)parent_rate, div); + } } static const struct clk_ops clk_double_div_ops = {