Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2886696rwb; Mon, 15 Aug 2022 13:19:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR4NlTFGeckkSPECF3EqweI0I0BojDGvVBGcWu5inSLjqhFJDN1hUOYWyWmlaBePbCBCnpOJ X-Received: by 2002:a17:907:94ca:b0:731:8395:d526 with SMTP id dn10-20020a17090794ca00b007318395d526mr11086682ejc.389.1660594766101; Mon, 15 Aug 2022 13:19:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660594766; cv=none; d=google.com; s=arc-20160816; b=yd6dwE2ADrB2arYfqMsfUdrtWZA0qGnVoRR7ZVYHRlaM022rDxaTRyBMOJg2hQEvoM T5XCVphqkbEgQ0D3GBt67F803tdUuxNpQXA+d6z5DqSBeA7OiVaHBazz6i2asVW7z4n0 hLIPq2Xyn4Kk8XiS6/3PKSfGd8+2WTLAvy0fqbZB89ebjBEJhzyoudGLyfhWzD/j6QQR XWj29yjHKB9pZpzIVOeAntWaKphamGHtOElCklmKTUzG1+oMSXXOXGKw0Lfh4H0/7JnB cbQuu4INMHjsbHr2H8R854uVgIMcH/oj5stFG39oCBhtrKOGXlglVEL0oADaI8J/6XpR weFw== 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=vh5LxEAwLxnaJSif3xe7WqgybabadEp1wC1xViJGw6A=; b=XV4piuKW2qzX66A9M+fGtEFFwf4B0pmZ6PASW+queYPmn+UU6xFcIzKnGqPBxNf5pZ +LEPUguEj4rlLqdKEMpT9xwqCQxy6Broke+pC54IxcrxdDpiUCuJANNHz3bG2bVlWdig peay7xxXG/hFicIKLvm4cFWD/1nbj6fe/uBrMLFpPwrFwh7UkrN1mObvhEYSPYsfgsx8 hcVwRJ5JxeZ3Exkm2D1wMIsFtpbVO2q/lnWE1gX+4RLNzzngIAvGWjxxbkvp7v4s+q3g eRR4MzpmurF/MWY+aUI2nZcIF0KaEgzhejWsBMdMO7b/5PunzHB7GrKV4GPM0DJWaS2P vVsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K97TVZ8a; 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 hp39-20020a1709073e2700b007262c51b07dsi9589274ejc.724.2022.08.15.13.18.58; Mon, 15 Aug 2022 13:19:26 -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=K97TVZ8a; 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 S1345151AbiHOTST (ORCPT + 99 others); Mon, 15 Aug 2022 15:18:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343826AbiHOTO2 (ORCPT ); Mon, 15 Aug 2022 15:14:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AD8552451; Mon, 15 Aug 2022 11:37:42 -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 8CD87610A4; Mon, 15 Aug 2022 18:37:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8798FC433C1; Mon, 15 Aug 2022 18:37:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660588659; bh=Mg6Sn5bolJ4oeV46nSR5Urbra1kdWde0bOoiAeU8fPc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K97TVZ8a1cOzE/nsWec7dpKNX/akZV3tYdMkVU5REpn9db0qoZVFZL3oP2Py4FyDg aYP0uMz9NTWTG7BbaUsPvEXnzxPREUD6NxZKZ3YSmnOJc3+SrFUaba82oMJ5P70f8Z QqiHCdAI8jqbeCCidyBiTwPxoAVQPIBT06LU5+x0= 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.15 457/779] clk: qcom: clk-rcg2: Make sure to not write d=0 to the NMD register Date: Mon, 15 Aug 2022 20:01:41 +0200 Message-Id: <20220815180356.812632127@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@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 ebdbc842b98a..c3823cc32edc 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 @@ -429,9 +430,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