Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3688371lfo; Mon, 23 May 2022 11:29:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCiyc7NSHy7UweWD+AhOxl+GApq+ZomHPIRA/YybzHAaxM5woPEHe6weH2cZjCCnc6FTmk X-Received: by 2002:a17:902:8504:b0:15d:2c7c:ceac with SMTP id bj4-20020a170902850400b0015d2c7cceacmr24340364plb.130.1653330574593; Mon, 23 May 2022 11:29:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653330574; cv=none; d=google.com; s=arc-20160816; b=KldZ29pMiA7RqjqnlTxbJNLN1nnAizHX0+pB1eVgtWWiMNWrgOJsWbjaxBN3CVCD6z cdrMr34dbuHz/hXMa5/DAPIyzFvfvLsC531bHjXwpUkbiBMGZElVSUTG2E9j/KJrG79w sP2zjTWxorwr030+fEFxV4CB9MV44UKS73jYF4hJ4cGuElo/dsla8fY1Oy4ZJ9XgrXYx mbnL3gaMmb183DX7BYT05gKO7DCvlY4j24ajeBA1Fln4NosufMWVhkHbvKpvxHYGQYqz pREd+USnAwWNv2WT70jOFdiw6fzOKRXm88LCQR0ZWM7WX6ZppuNvJDYPE6ozRg5M49uz y9zQ== 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=tIw8J0h3RQS9TbeEwOrYg4S+ZTRPWbSORpahfP6SKfUKbYcO6zWldjtDfMlxO/RRxs PV20uhpeq0zrvNvB+FbnZvMnVtbCHMiY4VxUqoC2wRLGKU362iScDChtCd1O7zro3ZqO WsYIzCQrgaNQ+b0QAANTj3xPjTeEU2rXgmnGX8hMFArXl/+vx8DXs3e+6anfPlJtSAd1 1z/abznh6YmtwlonsYnSfhVQjlsn/FNR5jpiH5DjxjXFxKglStnXHjTgk7LeBK0qM9hF fmaGXq5zzO3FWF75vrZ0rIxRPw/Tt+dpXMkkk+gGuRKVfV8sisLeLauSbaSQC5CyR9dr Q+mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yErxJKDB; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id h4-20020a63e144000000b003dbaa0bd8d5si11634622pgk.537.2022.05.23.11.29.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 11:29:34 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yErxJKDB; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 7404AB0D3E; Mon, 23 May 2022 11:29:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239639AbiEWRPF (ORCPT + 99 others); Mon, 23 May 2022 13:15:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240515AbiEWRMa (ORCPT ); Mon, 23 May 2022 13:12:30 -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 45BEE62BCA; Mon, 23 May 2022 10:11:41 -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 45A7DB811F6; Mon, 23 May 2022 17:10:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AC49C385A9; Mon, 23 May 2022 17:10:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653325832; bh=8HqcDKgm30aIgAcb6f1MOQJAQLF0KAE4hGTUo6ovBM8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yErxJKDBn5tLhXHvmsbUU1/69TFu8biRo2oE5Zw1mYevzc8GZx8zX89ggBispOvQa XWlbeDPl59caCnHneiFyCIi6d/o2TarEZT2hzW97yAvYwON50b1Ya+8NKNlCI657lf BX2bUdKZvvXgXXaR1UybAJ52ZLjXH7XasoTluDNQ= 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.19 25/44] clk: at91: generated: consider range when calculating best rate Date: Mon, 23 May 2022 19:05:09 +0200 Message-Id: <20220523165757.738972522@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165752.797318097@linuxfoundation.org> References: <20220523165752.797318097@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