Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3251930rwb; Mon, 15 Aug 2022 22:21:11 -0700 (PDT) X-Google-Smtp-Source: AA6agR7a7Xwy0KYO1SEEWu4y9VoL9S/kg/5NGp6xCIUKCmnpeUVUrN1Bm643iFJTRcuatTUWVlNQ X-Received: by 2002:a63:d609:0:b0:41d:9296:11d4 with SMTP id q9-20020a63d609000000b0041d929611d4mr16493696pgg.102.1660627270441; Mon, 15 Aug 2022 22:21:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660627270; cv=none; d=google.com; s=arc-20160816; b=X/2cy6eHlb1LOcUSzwYJa+FtB3TGTWzqLeZCODT9G0CkOZgHx5GTZ40QmZ3ujhXGen D3V9LJ4RbD1eBfRvg/Iug3ssu/FFmmUqq8W/JHAvXIkyRkDFw3swV6arRjEjhJrei9w9 MTAHO9I991azb6PAcNBrxIwoICPM7TQs4IPrXT3rBK7xnTSztTxJMUdWodgBA83x7ET1 T1N7tI0M/4RXS7qt2AA7vVqhNNaV12SSV5VFNDYAqDryCBDba7hQaBKY9ynggdrSiYIo 7PIjiO+Rzv1ZaMb1u2sT5gJWXrtlFH/brEO3GmugaKXhPCqVW+pHIMn8aN7h+g4akDAK 4m+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TBZrFb2XvJ0jH/EjOPFsVkNiiRDh+zCMiZm2H0PWTw0=; b=KwZLDNnI2LYkTQs+z9SWgySGv5S1laUMYMoTjbdqRLChv21+n4U8hYaPMeAPx6Yr28 Zz53xRJxi5TePxEaaXneDRxNszedWGy9w5tHmeAth2vvVhwS9NNpdZj/dYXh5dns93m4 YoosX3rd5db3bDSht4XIAvkL4F0/nYbivKF385rm4kryo13xRx+Tb2bLscyQkcyUwpvb rmZNs2N0ux5Z17imFxgybe5d3+4pMiYNjkTBe0Ahjof73zD1r6tUJgeJO6jua2yimRcT l0xM0ZXcPnTFdeGhPzIVuTFYWhx5VKOxgV9AYVWzXdUf6xrDHI2tx54oWPehdcJmQlfQ 5UJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fSUHK1e3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j1-20020a636e01000000b004202cb15b7dsi13269000pgc.81.2022.08.15.22.20.59; Mon, 15 Aug 2022 22:21:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fSUHK1e3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232177AbiHPEnx (ORCPT + 99 others); Tue, 16 Aug 2022 00:43:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232051AbiHPEkr (ORCPT ); Tue, 16 Aug 2022 00:40:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0914D330; Mon, 15 Aug 2022 13:32:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 98CB461089; Mon, 15 Aug 2022 20:32:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88FA8C433C1; Mon, 15 Aug 2022 20:32:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660595530; bh=Bd7fE8Kt4aaU6LVNR5gCH5ownrgcWeBzvZ5qrcrnwI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fSUHK1e3hQbguiifx3Sr4nR0lmhmvoyRGD9qm17Ck7iPuvsnyu02NkVcx5E1T5vT0 YcO+i8mBeYfauKhJQeZindKYAHZ/gAC3ToBeK8k6ipRJiPu27vHhMoNh2gfvVHOLnc 0CiQlC0nCuorkFicWbTzTF1kddEjs/kC4jCRkIE8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nikita Travkin , Stephen Boyd , Bjorn Andersson , Sasha Levin Subject: [PATCH 5.19 0762/1157] clk: qcom: clk-rcg2: Make sure to not write d=0 to the NMD register Date: Mon, 15 Aug 2022 20:01:58 +0200 Message-Id: <20220815180509.964648701@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nikita Travkin [ Upstream commit d0696770cef35a1fd16ea2167e2198c18aa6fbfe ] Sometimes calculation of d value may result in 0 because of the rounding after integer division. This causes the following error: [ 113.969689] camss_gp1_clk_src: rcg didn't update its configuration. [ 113.969754] WARNING: CPU: 3 PID: 35 at drivers/clk/qcom/clk-rcg2.c:122 update_config+0xc8/0xdc Make sure that D value is never zero. Fixes: 7f891faf596e ("clk: qcom: clk-rcg2: Add support for duty-cycle for RCG") Signed-off-by: Nikita Travkin Reviewed-by: Stephen Boyd Signed-off-by: Bjorn Andersson Link: https://lore.kernel.org/r/20220612145955.385787-3-nikita@trvn.ru Signed-off-by: Sasha Levin --- drivers/clk/qcom/clk-rcg2.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/clk/qcom/clk-rcg2.c b/drivers/clk/qcom/clk-rcg2.c index 2375e8122012..28019edd2a50 100644 --- a/drivers/clk/qcom/clk-rcg2.c +++ b/drivers/clk/qcom/clk-rcg2.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -461,9 +462,11 @@ static int clk_rcg2_set_duty_cycle(struct clk_hw *hw, struct clk_duty *duty) /* Calculate 2d value */ d = DIV_ROUND_CLOSEST(n * duty_per * 2, 100); - /* Check bit widths of 2d. If D is too big reduce duty cycle. */ - if (d > mask) - d = mask; + /* + * Check bit widths of 2d. If D is too big reduce duty cycle. + * Also make sure it is never zero. + */ + d = clamp_val(d, 1, mask); if ((d / 2) > (n - m)) d = (n - m) * 2; -- 2.35.1