From patchwork Wed Apr 13 07:13:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Codrin Ciubotariu X-Patchwork-Id: 12811626 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 54021C433EF for ; Wed, 13 Apr 2022 07:14:51 +0000 (UTC) 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=aNRPoz3n+7RA028UVTUTZpJ9MBtrfNdhiApJwMOwtTw=; b=dWzfd7yANyStUy p9wseAcq/rFSoi8Y3Ta0XMRG99uLrn4I+ODPp4fV73r2tWL22nVJb+C42ig0DJNMDkt1qutovAX2l o8jQEk/tQiNjiz2UgvRh+WM7lGkCmHxQZRqIlMHZXrNriv88NUqXoFxdCkdrCcNAawPDYly+6h7hY zZpUc8W95UoeQs2TxgFtNKixg9Y9Lm7hzF+ZW/UPX9cV2TN4yyDcyZxXTEW8PRH3k51B/w2mJ0ixt eTQW6QSyyt6R29rn8EVpUy2uB2G6JtVhfyhqAjq3JEv5jOwz1hymmjRSG0PQw8GVTShSNW+5WSbhl JJWiVNNm/gOscQsuL+OA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1neXCC-00HMjs-2I; Wed, 13 Apr 2022 07:13:44 +0000 Received: from esa.microchip.iphmx.com ([68.232.153.233]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1neXC8-00HMig-Im for linux-arm-kernel@lists.infradead.org; Wed, 13 Apr 2022 07:13:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1649834021; x=1681370021; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=h3C/0JKkds2vE5J17NOx80JGTh8SJToIN8IB1dF+FE8=; b=VhdV3BuO1B/cYL/Qo1dPaqYq38ojhQZ1PEqfQ3ZgPGy9zKKN1uDFiW7k K16CEJpKXRQhfq93nAKWYhA5645u808ejGMEYcHH/YSJONsGlpX6IfQLC d/IrYRlUWAC7nI5KgKxjRN0JyaMLFN75rzPfIrZLD3q4VPlDHGbneYPv8 TwPBSXJb7DB5gPg8hTrNiZj/OWh3wic7mrPXr6rO43maIXNnk1AM90u6p CucbzoP5ZxTDuxC1WcZkVUb4OF4+nEbPtJacVBgGIVGRiPNkwOdsOMcK4 5xv2GzBwmMei3bMFgrJNPd8xlFXyFyVUPW2MDO11A5BG7xd5niF8Zx0Hy w==; X-IronPort-AV: E=Sophos;i="5.90,256,1643698800"; d="scan'208";a="159933363" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 13 Apr 2022 00:13:32 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Wed, 13 Apr 2022 00:13:31 -0700 Received: from rob-ult-m19940.amer.actel.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Wed, 13 Apr 2022 00:13:29 -0700 From: Codrin Ciubotariu To: , , Subject: [PATCH] clk: at91: generated: consider range when calculating best rate Date: Wed, 13 Apr 2022 10:13:18 +0300 Message-ID: <20220413071318.244912-1-codrin.ciubotariu@microchip.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220413_001340_650007_324C31F9 X-CRM114-Status: UNSURE ( 9.10 ) X-CRM114-Notice: Please train this message. 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: , Cc: alexandre.belloni@bootlin.com, sboyd@kernel.org, mturquette@baylibre.com, Codrin Ciubotariu , claudiu.beznea@microchip.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 best_diff") Signed-off-by: Codrin Ciubotariu Reviewed-by: Claudiu Beznea --- 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-generated.c index 23cc8297ec4c..d429ba52a719 100644 --- a/drivers/clk/at91/clk-generated.c +++ b/drivers/clk/at91/clk-generated.c @@ -117,6 +117,10 @@ static void clk_generated_best_diff(struct clk_rate_request *req, tmp_rate = parent_rate; else tmp_rate = parent_rate / div; + + if (tmp_rate < req->min_rate || tmp_rate > req->max_rate) + return; + tmp_diff = abs(req->rate - tmp_rate); if (*best_diff < 0 || *best_diff >= tmp_diff) {