Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2162291ioo; Mon, 23 May 2022 11:34:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQaAchYfMSLWE7CBETdAFQPUMFO1o/Kp+N/2DfAlLxGpcjREZ/WnrNNpF0WaAhS1hCjFlm X-Received: by 2002:a17:90a:4896:b0:1de:fff2:6c48 with SMTP id b22-20020a17090a489600b001defff26c48mr322862pjh.89.1653330843961; Mon, 23 May 2022 11:34:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653330843; cv=none; d=google.com; s=arc-20160816; b=TyddzNEDCVgr1D0JYbDbwldrP1bfAT8uMwX0Jmg54yHvwrMcSzlkuNJqYs9SOwhICF l4YE436L6uDj8vWGTV6e0lwR+5mxpohywBj2wkH22hgjjYz+C8/aAejxEzjGP7HpA6nx DkvpRiKAMH1UvS4G7+tftwzFFXJPhAWHHCe7Df8LS9B1Iht+WERYAVzIBQQAKbTI1YQ+ 1kN2uD3xibIYGWCIHu0m3v+grVWSrNYFZ/iTN0ijfyy+4rySxjXE724zQ9yIT2dVm/cf dp4VH71k25BuQ+Zs45WGrN2BUfKWCi6MHkVi8Aswf7y4F/HWkOjIbFrV99U3/EDcbQju SSgg== 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=0GJjR0HVGTqOx1NidhrezWR9ZBMGsN7B63kMjAbbkWc=; b=i56mWMExtH4RL7Ua+yyu9nuTTVv/VCSazJV3pgow+OTuF56CluJmseGB8SZx6nI35u rjVJf8qZeqsuz5C3kx7j+ZNLKJ6KMtRAN7ZCaPlyETWPUFrx3BZhkzkp/Xy2ZrDjzgfO 1itGQ6wkEHFQE3JEpD2YZinK6awZI9psoWfLY4lXQM9ABj4HItUXaPXrNP7HtnJDu3qt ge+hcxJpT0Nxfg5KdbEnY6OfdydFfg7iKIaq7DC33rNO/skzWrmZQ4ghVP+W+dNlOSoB Dv2dAP+Bmj4IHOSSVY2h6GMWJKOHnMojW12UGqSm7uxyT59l1zFGhyiaCEZ2h9hXJbkk k96g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VBjZhLWg; 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 e12-20020a63db0c000000b003f5d8756675si10897178pgg.371.2022.05.23.11.34.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 11:34:03 -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=VBjZhLWg; 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 A60211796CB; Mon, 23 May 2022 11:32:26 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240122AbiEWRZB (ORCPT + 99 others); Mon, 23 May 2022 13:25:01 -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-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 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_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