Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3087067rwb; Mon, 15 Aug 2022 17:48:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR61JY5Nmzb5l38muUuxIyMxc20MpnIkDt2raulipCelaR+K5tGltvAyOlBnIHdAHeyWzZGg X-Received: by 2002:a17:907:1c26:b0:730:960f:118 with SMTP id nc38-20020a1709071c2600b00730960f0118mr11704851ejc.650.1660610930881; Mon, 15 Aug 2022 17:48:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660610930; cv=none; d=google.com; s=arc-20160816; b=NOo2KUjnwNjtMxkZBKFIi/V/jrtiOutJOdjyP9kBevN/fZ8aAVY391wXzLjn6g5rnR BQjGujVyQk6GxA9p2qWp0/wHgcke8G+lZwywpFdfzF6d9i6Y2BHswfoFyu/Mdmw7b0fq liStq+LbFU8tSwVzx4sTLnWTIz6jr14YPAyH+W/7ux+s0wys94oBMLn1svIsEjyKRAIG ORA4LIPP9YS3/uzOgmKl7D9TEu/LqiDCpvqcoYzfAPWVcs/OGesHddw20u/86fl5bT8R GhbDlc7KG8SPLlmX2oDbA7Yzfd0Z+MzC9HtdGQ1aGhTwlx99+Hj866AneCznrRB2jS5T HkAw== 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=vM5Fjs5AVCKPNX724TD8g8Tqnk5uiaGYhQxG3ecLydk=; b=MHF5Cc/Qx5oK1Uua2KMwCFtCEd9gyBwsLJcawJORaFS1o+cgTqNOUdQsIBW/ZrM2Ha HmYZrw/fdanIVoJkXnnGZyzD2VKSY9asCwNREWzFIFjJOEQNbTiU2dKtLa2woFB/h46B UAveTLz2P80VGLh0IDDOpGlrUTOJMZnph4G993UelVqGciXNYcjW5GiNALTRs1qods4Y IHoYB5xyKetbmhpSFPWzVU6Fe7IkLduuqwVifMkUFDcee9n7rwoUJKRtwgQBkCgoaLeK Joc2X06DaCxyn/wn2cmTj1xp4DcSCLYZlxdLMbaD+5FoXqaQqTBnP1EtChisJAMMRMNG 6Hhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=i0TqItxl; 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 qw23-20020a1709066a1700b0073276700562si8976469ejc.282.2022.08.15.17.48.25; Mon, 15 Aug 2022 17:48:50 -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=i0TqItxl; 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 S244377AbiHOVyi (ORCPT + 99 others); Mon, 15 Aug 2022 17:54:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350534AbiHOVve (ORCPT ); Mon, 15 Aug 2022 17:51:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EB8F106F97; Mon, 15 Aug 2022 12:33:00 -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 338F36115A; Mon, 15 Aug 2022 19:33:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A0A3C433C1; Mon, 15 Aug 2022 19:32:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660591979; bh=reaCaFSvJsZu7N/qYI/xflIODqPJK6dLRIETjCF7GMs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i0TqItxlElUtjLey9HZVbY/jcGPSIU6qU78oUXfSyQmhdt4HpTzFAKmYGC7oQmfYz lXG2gDUGCsBTx76ZM48t8XxbtPZNWMNoebJ+jsfzPMSNmkKgXhqdiJIwii6EZn3tZn xyWj6P7AASHQ9NFRgsmlPQT/NMwuSI500GD31VIA= 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.18 0713/1095] clk: qcom: clk-rcg2: Make sure to not write d=0 to the NMD register Date: Mon, 15 Aug 2022 20:01:52 +0200 Message-Id: <20220815180458.895291883@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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 9611c9a7231f..caafc35eecfd 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