From nobody Sat Feb 7 21:14:39 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7BE9C433F5 for ; Mon, 23 May 2022 17:25:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240634AbiEWRZD (ORCPT ); Mon, 23 May 2022 13:25:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240797AbiEWRQn (ORCPT ); Mon, 23 May 2022 13:16:43 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D23062BC3; Mon, 23 May 2022 10:16:32 -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 ams.source.kernel.org (Postfix) with ESMTPS id 2163FB811F6; Mon, 23 May 2022 17:13:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CC46C385A9; Mon, 23 May 2022 17:13:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653326014; bh=AjV0KidD6laytPE2vdH+XdL8fxaQdJo0NN4+hqr5dqw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VBjZhLWgeEXC9EA4gPa1vhAVBCUCwFgYZ4Xd4XMboMmyyDwA5IKOPOJcuZUZKQvyw +1SJbkU3FF4EZHBd8G7jj5WO4G9id/A+eZz9tpmjYeNh2klWFGgE9ZO7jwLs75dY7P 3+iV653K1lXpmoH1sZQwr66urBO8ltLDmiFmOPsk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Codrin Ciubotariu , Claudiu Beznea , Stephen Boyd , Sasha Levin Subject: [PATCH 5.4 41/68] clk: at91: generated: consider range when calculating best rate Date: Mon, 23 May 2022 19:05:08 +0200 Message-Id: <20220523165809.389122273@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165802.500642349@linuxfoundation.org> References: <20220523165802.500642349@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Codrin Ciubotariu [ Upstream commit d0031e6fbed955ff8d5f5bbc8fe7382482559cec ] clk_generated_best_diff() helps in finding the parent and the divisor to compute a rate closest to the required one. However, it doesn't take into account the request's range for the new rate. Make sure the new rate is within the required range. Fixes: 8a8f4bf0c480 ("clk: at91: clk-generated: create function to find bes= t_diff") Signed-off-by: Codrin Ciubotariu Link: https://lore.kernel.org/r/20220413071318.244912-1-codrin.ciubotariu@m= icrochip.com Reviewed-by: Claudiu Beznea Signed-off-by: Stephen Boyd Signed-off-by: Sasha Levin --- drivers/clk/at91/clk-generated.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/clk/at91/clk-generated.c b/drivers/clk/at91/clk-genera= ted.c index d7fe1303f79d..0e7ec5075689 100644 --- a/drivers/clk/at91/clk-generated.c +++ b/drivers/clk/at91/clk-generated.c @@ -105,6 +105,10 @@ static void clk_generated_best_diff(struct clk_rate_re= quest *req, tmp_rate =3D parent_rate; else tmp_rate =3D parent_rate / div; + + if (tmp_rate < req->min_rate || tmp_rate > req->max_rate) + return; + tmp_diff =3D abs(req->rate - tmp_rate); =20 if (*best_diff < 0 || *best_diff >=3D tmp_diff) { --=20 2.35.1