Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2109284ioo; Mon, 23 May 2022 10:14:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWfgeM51pOwzpl5R7HnjYMvL0hrXIH7Q2moLCi7QS+9lCUB23G718iJkwbdajto5hSpYKT X-Received: by 2002:a17:90b:4b4b:b0:1dc:8724:3f75 with SMTP id mi11-20020a17090b4b4b00b001dc87243f75mr42220pjb.178.1653326080172; Mon, 23 May 2022 10:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653326080; cv=none; d=google.com; s=arc-20160816; b=u9ddSCiIotFrvoGvSzEsqrCzHsimBjd8KqsGp5EhG7wqmsYPQvNSr88rhhWAIGzjiR kodqJ5JVJcw103X2JeSSg8pz1kKGy5hkibAGMGR4Ci+UYKPDBLd+idccszjzCdzk0Fsa AnwhTDmfZ30d5TvoI487raPLtLHxJMgZuIPeqI0/swADT+6khNnY3uXKiZC1sTW6Rf4a tAXhPd3KPHrwhBx0wZFxtL5na0L4V6FzfUTJJlYBg9qOpsQmWDWrLrK9aUikJi3P5Vey tuCiVztD2SWgPYkecoNM+x1CL1PaJalKTHxbV7bpRBohq6dn6xUFuQg+AisaVqYG6Moq tiCg== 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=kFPGakUiCSlhpGSCPt4Haj/k7muH/7dLdz+BiwBXK1I=; b=A4Y4k8QZPapdBxDTRAugf+vDhI1haMGmo8rAMaFJ1XRB5DgIbI/LZZC2Y4LS2nLTkN s1jJiAEz7cOgsX/q5fOmCmYlK3rQzd6Ue5K3SPkfm2od0xsvpDjjh7JTt6mskNhzSDX7 dEgYjXL67MrJrKQTWEWPqUB3X8vFI4Gi4idtIrn/5in92XvpEXGOfQFfMvEYFsVABlzu u5KR80bl1ZVoeSg4pyyWU4pfxfmz2Upkt6Q1lqFpnbIoEip8QvGFuBha3y5ZXJOnZJjp hI/YgE5AuL2vipXiD7nQJ1zSrCy/h17X46oTShgAFtj1IATqqH5kPf4hMs8SJjwu3cl6 XRsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yODdqz+8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s22-20020a056a0008d600b0050ebd76abccsi16288583pfu.2.2022.05.23.10.14.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 10:14:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yODdqz+8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 10A5E6FA12; Mon, 23 May 2022 10:14:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239743AbiEWRLK (ORCPT + 99 others); Mon, 23 May 2022 13:11:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239684AbiEWRJo (ORCPT ); Mon, 23 May 2022 13:09:44 -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 0067A6C0CB; Mon, 23 May 2022 10:09:27 -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 7E2CEB811FE; Mon, 23 May 2022 17:09:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9FC0C385AA; Mon, 23 May 2022 17:09:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653325766; bh=8HqcDKgm30aIgAcb6f1MOQJAQLF0KAE4hGTUo6ovBM8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yODdqz+8xSPyRK3Dcpw1cWU0u9nJT8TCu4bQrpHzcW3Zlwp1nykSA/BCGJc6l6Smb TyXjqhNbv4hHR+At3jO2QBUEbv6jOjTuPr4HG4MrHTGubuMLdHR713BLMSeK87rL6V ZRwBHNAlvGEWXfPgXu0Diia6wwsTq9W0X3N4Wl6E= 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 4.14 16/33] clk: at91: generated: consider range when calculating best rate Date: Mon, 23 May 2022 19:05:05 +0200 Message-Id: <20220523165750.668051270@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165746.957506211@linuxfoundation.org> References: <20220523165746.957506211@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: 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 best_diff") Signed-off-by: Codrin Ciubotariu Link: https://lore.kernel.org/r/20220413071318.244912-1-codrin.ciubotariu@microchip.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-generated.c index ea23002be4de..b397556c34d9 100644 --- a/drivers/clk/at91/clk-generated.c +++ b/drivers/clk/at91/clk-generated.c @@ -119,6 +119,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) { -- 2.35.1