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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 881ADC433FE for ; Mon, 11 Oct 2021 11:37:40 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 4B08B60EE2 for ; Mon, 11 Oct 2021 11:37:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4B08B60EE2 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uQEbBOWniIhK7xtb4V1M/S2OFvOzZ2O9BTdQj2toznc=; b=O9EVwjeq6TkWdW MMlZ5CBRTm+1yfzAZDOoweOLVZ2w9QOOU4LS0ogBvgE/4uRwvoZKwS0aekfsAaNMak0Ft3sUnWEp6 +YyOlQaM5WuJj81t/0wL1Pw+v0CE2znPpr8zgLGi7UvhfuPQ3BQoU2b0nF7XBAy4UdlYUfnxNgI7Z 3t0ycYOPTOcw2mohL3ZQCyPpz6Lj7GDyc23Ib1lg80y4ljQI6SI3XGqE7Sv9EkOBo8gr5dFN+W3iW bbyFFN5GkhytH2wtkWxcig6bhy2GuSof6ztEY3ujKq70Gvc0fUa2DKKzzrCStYVzux5oqQUvi1Kdt yRiY2xk9n4ZggctxjBSg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mZta7-0096YH-H4; Mon, 11 Oct 2021 11:35:02 +0000 Received: from esa.microchip.iphmx.com ([68.232.154.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mZtTD-0093oR-50 for linux-arm-kernel@lists.infradead.org; Mon, 11 Oct 2021 11:27:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1633951671; x=1665487671; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=S2pBzduVdLBand+IYegWgUWMNB29c7JB6jeWuWWNdV0=; b=JJX0TaDuM7VI5mAqfdBEW5NowhfENHKd9YGfvDNgGNGf64v8U20iXRDt fkiATDcnDVupm28xDiwIJko9tcaElFAciVFfvQ+h25xr/Jwu4/s0do1T9 EgiH+06jESyKlfltPlmTR3JYaHgvK5zJEc+ph+Tkv1vdflfZUrpO6Uk4E mWO0rAuuFwFc0ait9YcoLqWv2+R6duTmbOS3K3BmqFV5lG2/mHcqFfOEM y8MgquDLUa47FFddQOrgj+jX4X38XTxJvHtsw/cb2DMS+JABOcfHO1vAs DENEbI9yQ775o3xJscONkHpMqwUBElXWw4GqGuSnYjEVP4dg3KQ5CYtje w==; IronPort-SDR: IANyGvuARxcOpnODQmCV3aI4kbca822stwCGCFf7nvrZ31w4i7eV7HR+vNpXBoBK4y2OYHDsr7 apu50aek2rDoCcHIZPDKVJZlbGZPL1hOREKGQMCP5JMINsnmlrCs2MJSEkvoPHP9m0DPAznbfA F5T+XFfE5pJeZPxmRzweM1ohH6GzsEoraLB0lY35YMn0oInR/LT07shnsleehrR+E9fi/riC2A bkKZOn9IndSGEWZdsGwu+CUuL8PBRqsJKAvb2Nq2Tq1fVz5imx9/ZbXX+Ilfr/aaaugfpyP43T ztK7ZTyVcKpCldU8GALVnDa4 X-IronPort-AV: E=Sophos;i="5.85,364,1624345200"; d="scan'208";a="135067591" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 11 Oct 2021 04:27:50 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Mon, 11 Oct 2021 04:27:50 -0700 Received: from rob-dk-mpu01.microchip.com (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Mon, 11 Oct 2021 04:27:47 -0700 From: Claudiu Beznea To: , , , , CC: , , , Claudiu Beznea Subject: [PATCH v5 08/15] clk: at91: clk-master: check if div or pres is zero Date: Mon, 11 Oct 2021 14:27:12 +0300 Message-ID: <20211011112719.3951784-9-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211011112719.3951784-1-claudiu.beznea@microchip.com> References: <20211011112719.3951784-1-claudiu.beznea@microchip.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211011_042751_285469_95E133F0 X-CRM114-Status: GOOD ( 10.72 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Check if div or pres is zero before using it as argument for ffs(). In case div is zero ffs() will return 0 and thus substracting from zero will lead to invalid values to be setup in registers. Fixes: 7a110b9107ed8 ("clk: at91: clk-master: re-factor master clock") Fixes: 75c88143f3b87 ("clk: at91: clk-master: add master clock support for SAMA7G5") Signed-off-by: Claudiu Beznea --- drivers/clk/at91/clk-master.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/clk/at91/clk-master.c b/drivers/clk/at91/clk-master.c index 9a2c8e64cacf..2093e13b5068 100644 --- a/drivers/clk/at91/clk-master.c +++ b/drivers/clk/at91/clk-master.c @@ -344,7 +344,7 @@ static int clk_master_pres_set_rate(struct clk_hw *hw, unsigned long rate, else if (pres == 3) pres = MASTER_PRES_MAX; - else + else if (pres) pres = ffs(pres) - 1; spin_lock_irqsave(master->lock, flags); @@ -757,7 +757,7 @@ static int clk_sama7g5_master_set_rate(struct clk_hw *hw, unsigned long rate, if (div == 3) div = MASTER_PRES_MAX; - else + else if (div) div = ffs(div) - 1; spin_lock_irqsave(master->lock, flags); -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel