Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2752089rwd; Fri, 26 May 2023 10:39:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4lzNPpzQL650FXZtjvPc546BQxpcrJXtgMb8WsZIQocZ0Frz1AxXFM7ZFVUGZoYTjXvu04 X-Received: by 2002:a17:90a:be03:b0:256:2ef:92ec with SMTP id a3-20020a17090abe0300b0025602ef92ecmr3324629pjs.1.1685122749911; Fri, 26 May 2023 10:39:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685122749; cv=none; d=google.com; s=arc-20160816; b=RDYG2ouqZrPWJ1v3QrbqTlk5eUpJF7o1FmeyoKvrsUruPCyDsQy4PturUgbIqLjWi/ 5D+KVSg0CMOamRUP8eIKuVKbzmw23W/dkIAdi3/5uZ2j1jJd0EaZUsZ3g5npt3THNGmO xuLd8xIVQMv8JzSpGdyxE2Ornqhism1xs7xIgzKKc2VpQMgUWwSR/6h2ef1wO0A3t8yW sooSuZC2Uqi8vDBeRz4p3SWhZzXvDTDsp8cPAtHeK3fBvb0tDUPKAkEL2uvDjN2gFTq/ lLgJkCcSHYVaxIiCf1cIuYxDpaBiGrWg4Kdw6NV6pbe3Jutd/rtQ6jqjS1fy0wQFR47e 2BbA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6LXE9Ras8JYXtFb0LHuJoKHZd9KU99FGYE69e50L0aY=; b=zWc09pVauG8jKJ1/mx+eioPP623aJ9yrITer7+q0+1x1u2yDpvjawA1X0N6HMTcTI8 iUkpDWHPp/P/OV193EC5wd3YnM3iANPEoWeagVhb9jvEBfNhT8e9TQfKa2XEasq8+yH/ QXtWtluVAWplDkYfTBGng1g4WeEUTk8wOzChg7XiaTkH/rIqtULxE6Ure69xyDdN90zt UKAitHyZv5YuStyf4px97wRK6sIRqxDn8HZwqxw7tf0WKe+OuEPEHOi9j5KUGlllM8NK bNV2sYmGBwe7n291gWcXABz15HuyAhQxfHIbCCHi1aArWw1n+7vGeySvRbwknlH1GSe4 jqkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=KFL5ezHX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v11-20020a17090ad58b00b0024e47fae466si4311994pju.180.2023.05.26.10.38.57; Fri, 26 May 2023 10:39:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=KFL5ezHX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242301AbjEZRLJ (ORCPT + 99 others); Fri, 26 May 2023 13:11:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236835AbjEZRLC (ORCPT ); Fri, 26 May 2023 13:11:02 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01099FB; Fri, 26 May 2023 10:11:00 -0700 (PDT) Received: from jupiter.universe (dyndsl-091-248-132-021.ewe-ip-backbone.de [91.248.132.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: sre) by madras.collabora.co.uk (Postfix) with ESMTPSA id 872486606E94; Fri, 26 May 2023 18:10:59 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1685121059; bh=8tIgZvve58LmRVC3TweXsKlF+FYtaM8+jla/W7NnB5Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KFL5ezHXSfaf06+obC/aX5tMUYWQlwtH/YLQIw0bI7u1qHRESWBGpuCT6PnvGUR2W TzSn7HldAPBE+GWokVj+FzEXa/d9q8aQvdwl68g1H93vDFNFrmOFoThHwYT/t/hOaV 5WMAhlO0T8ran4LWdPR6yDiSxhNApaX2H7FZr2cQctlt8Ft7oWEgm0sJS4VbIzNefm bXnDGlOOlISZv/GosaJzI2mdfFZT/5ihwBBmmVET6jVEdIGTsCh+4DSGLvQ+UQkykW YKOS5w6zTTcPa4z82lbJq+buSdOgtljkJ/tm6jLeyMgGDmAYWHT89bhBKqb+fiZ4H+ xxIMgMO16mjfQ== Received: by jupiter.universe (Postfix, from userid 1000) id D26934807E2; Fri, 26 May 2023 19:10:57 +0200 (CEST) From: Sebastian Reichel To: Michael Turquette , Stephen Boyd , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christopher Obbard , David Laight , Sebastian Reichel , kernel@collabora.com, stable@vger.kernel.org Subject: [PATCH v2 1/2] clk: composite: Fix handling of high clock rates Date: Fri, 26 May 2023 19:10:56 +0200 Message-Id: <20230526171057.66876-2-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230526171057.66876-1-sebastian.reichel@collabora.com> References: <20230526171057.66876-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 ULONG_MAX is used by a few drivers to figure out the highest available clock rate via clk_round_rate(clk, ULONG_MAX). Since abs() takes a signed value as input, the current logic effectively calculates with ULONG_MAX = -1, which results in the worst parent clock being chosen instead of the best one. For example on Rockchip RK3588 the eMMC driver tries to figure out the highest available clock rate. There are three parent clocks available resulting in the following rate diffs with the existing logic: GPLL: abs(18446744073709551615 - 1188000000) = 1188000001 CPLL: abs(18446744073709551615 - 1500000000) = 1500000001 XIN24M: abs(18446744073709551615 - 24000000) = 24000001 As a result the clock framework will promote a maximum supported clock rate of 24 MHz, even though 1.5GHz are possible. With the updated logic any casting between signed and unsigned is avoided and the numbers look like this instead: GPLL: 18446744073709551615 - 1188000000 = 18446744072521551615 CPLL: 18446744073709551615 - 1500000000 = 18446744072209551615 XIN24M: 18446744073709551615 - 24000000 = 18446744073685551615 As a result the parent with the highest acceptable rate is chosen instead of the parent clock with the lowest one. Cc: stable@vger.kernel.org Fixes: 49502408007b ("mmc: sdhci-of-dwcmshc: properly determine max clock on Rockchip") Tested-by: Christopher Obbard Signed-off-by: Sebastian Reichel --- drivers/clk/clk-composite.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c index edfa94641bbf..66759fe28fad 100644 --- a/drivers/clk/clk-composite.c +++ b/drivers/clk/clk-composite.c @@ -119,7 +119,10 @@ static int clk_composite_determine_rate(struct clk_hw *hw, if (ret) continue; - rate_diff = abs(req->rate - tmp_req.rate); + if (req->rate >= tmp_req.rate) + rate_diff = req->rate - tmp_req.rate; + else + rate_diff = tmp_req.rate - req->rate; if (!rate_diff || !req->best_parent_hw || best_rate_diff > rate_diff) { -- 2.39.2