Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2440983rwr; Fri, 21 Apr 2023 08:57:22 -0700 (PDT) X-Google-Smtp-Source: AKy350ZJ0wYa4m1sk7T2U4wOn8RxvzywF0shNXJIUbzCP5SvdL3EJL/UQXhPmTWJvSiUFz86SLxe X-Received: by 2002:a17:902:f685:b0:1a9:4167:5db7 with SMTP id l5-20020a170902f68500b001a941675db7mr4208709plg.4.1682092641808; Fri, 21 Apr 2023 08:57:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682092641; cv=none; d=google.com; s=arc-20160816; b=CWLe8d5g0vRk3Xrn1FHIl6UcVy/CM1CkSoSjceF7rqfpTUfV1eVslO+y6qmjwDzJv9 ZzPLUihBaYiJeXE2iWioGYAlYpHn4izX6KTsQJj8SmWQ1B5EryquwTnbaj4bziooOsVd PnuYfjAp8n9+PmTWGtdalvSKWA89Hub+RzRcSvzOBJUn57dXB3Ct7xdovk9qjIK7Xp8x zb4B/oEVHdfxLKEfSo0eV/z08FQZkHqt14wTG1oqkpdjYpZQCV/P4sCjtyROA/TM9zz4 7p23N4fJAKmPXFqzJSWaqgCsKciihwlzarKjtUlY1tOQsugj217IhHFU3pS0I1yO8R2W yjNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:reply-to:cc:to:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=KKEnym5piLrAkweCrCikPNqZ4fWL7ohVt0AkByX6p+E=; b=FoBcZHpUGjbTUQ9DRIg+1QmmZqd7HLQwfgXz+crPYoMl2JWkm+pu3hB/E2x594Jnbr dO1lrIsLgPNJyKG70zCHrgV25PM+GsB1xUz8XCfDLjKjfG+QpEItTXxyfCfTdWFHw4yP DyCKyL+COK+SFJR0q3IAhDFCl61Ivhc5dFld17tmuMJ9mcD72Tm3hLdqAk5s7m1Cy7m7 oqwpLaJt7T7UWWvU+uOFkQxotZ5g0oQQNXlWXq8mxfE8TbCWPyI2WWwpdNuEfsgJfUM1 u7feYA+fI3H9iugcWmC68eLmR50uqpQpDdqe+gwGGuzLyH36RhIRWC+o66Azge9HCtPP ykBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Selg5O2+; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b2-20020a1709027e0200b001a95929ca08si163468plm.533.2023.04.21.08.57.10; Fri, 21 Apr 2023 08:57:21 -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=@kernel.org header.s=k20201202 header.b=Selg5O2+; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232417AbjDUP4q (ORCPT + 99 others); Fri, 21 Apr 2023 11:56:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232002AbjDUP4o (ORCPT ); Fri, 21 Apr 2023 11:56:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C6B712C87; Fri, 21 Apr 2023 08:56:43 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 28F0C64EEE; Fri, 21 Apr 2023 15:56:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 8977EC433EF; Fri, 21 Apr 2023 15:56:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682092602; bh=XU1f54RNsab+tDqSiS+rVrizLk0jrqbfUMef83cufsg=; h=From:Date:Subject:To:Cc:Reply-To:From; b=Selg5O2+RUBECvFqLlQohN+8XjmUmtjKxpt4N/aE+OJDKSVkhXoXgLEjop/Rn0uBU VoZ+QeJFK7biU3TxB0Jo1UhiC4bSyVYcIndBVDCptM9KAPCL5kputKxE0JGqeBNgFM 0r+LoXgQtPi67fFXw4RrM7BgZ3HFr+VvGSpYklj5Rrb98FxEWfONRo7e2uUf1jM0qU EcWS2BA/fRvBP+ZBkxp8r6637cMh4R4J8SM/kInxJBqZxhDcVJEqHAyzJcptJzhDA1 uc3VZF3QJs4oo+X90YLypB8pn2eKkyfEI2DtliTTFXqVsPc8tz9RJ+RyPwECVgO1Qk K4+LKDmxWSgHQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76BB4C77B61; Fri, 21 Apr 2023 15:56:42 +0000 (UTC) From: Yang Xiwen via B4 Relay Date: Fri, 21 Apr 2023 23:56:38 +0800 Subject: [PATCH] clk: use ULONG_MAX as the initial value for the iteration in clk_mux_determine_rate_flags() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230421-clk-v1-1-bb503f2f2cf3@outlook.com> X-B4-Tracking: v=1; b=H4sIADWyQmQC/x2MQQqEMAwAvyI5W7BVevAryx7aNGpQu0siIoh/t 3ocZpgTlIRJoa9OENpZ+ZcL2LoCnEIeyXAqDK5xbdM5a3CZje/QR0/OYopQyhiUTJSQcXraNeh G8oi/0MDHu/98r+sG21J/qm4AAAA= To: Michael Turquette , Stephen Boyd Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Yang Xiwen X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1682092599; l=1447; i=forbidden405@outlook.com; s=20230415; h=from:subject:message-id; bh=ytvGjpTT/iD/YyNfNbs7xnF5FUQ/FGezwhki/7VVuk0=; b=x/5HVLQ6VewfSBPSIWtRlNHZMEnOYh3iOPFIDFCFysM+v7AJ4ZhdQ4kQumhDKGoJXg4En8/nb 1PAI+QnHqkmD/rLNmamWa3YjAYVPYM+hJeAj7n+hBfdW3WkYUpkddvZ X-Developer-Key: i=forbidden405@outlook.com; a=ed25519; pk=hfdpPU3AXR+t7fdv58tXCD4UzRNq+fop2TMJezFlAhM= X-Endpoint-Received: by B4 Relay for forbidden405@outlook.com/20230415 with auth_id=44 X-Original-From: Yang Xiwen Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_REPLYTO, FREEMAIL_REPLYTO_END_DIGIT,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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: Yang Xiwen Currently, clk_mux_determine_rate_flags() use 0 as the initial value for selecting the best matching parent. However, this will choose a non-existant rate(0) if the requested rate is closer to 0 than the minimum rate the parents have. Fix that by initializing the initial value to ULONG_MAX and treat it as a magic number. Signed-off-by: Yang Xiwen --- drivers/clk/clk.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index ae07685c7588b..ab8a2acfac8f3 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -541,6 +541,9 @@ EXPORT_SYMBOL_GPL(__clk_is_enabled); static bool mux_is_better_rate(unsigned long rate, unsigned long now, unsigned long best, unsigned long flags) { + if (best == ULONG_MAX) + return true; + if (flags & CLK_MUX_ROUND_CLOSEST) return abs(now - rate) < abs(best - rate); @@ -600,7 +603,7 @@ int clk_mux_determine_rate_flags(struct clk_hw *hw, { struct clk_core *core = hw->core, *parent, *best_parent = NULL; int i, num_parents, ret; - unsigned long best = 0; + unsigned long best = ULONG_MAX; /* if NO_REPARENT flag set, pass through to current parent */ if (core->flags & CLK_SET_RATE_NO_REPARENT) { --- base-commit: 76f598ba7d8e2bfb4855b5298caedd5af0c374a8 change-id: 20230421-clk-64c6b6e21cdb Best regards, -- Yang Xiwen