From patchwork Wed Aug 16 01:58:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liao Chang X-Patchwork-Id: 135894 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp749419vqi; Thu, 17 Aug 2023 07:39:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGyCgyg4c+u5U7+BnLVkZJt+u8llhxHuFT1ZDxlGwvjZ8eWg1giMHxJBwlNGqdrUNFKcI6l X-Received: by 2002:a17:902:720b:b0:1b6:68bb:6ad0 with SMTP id ba11-20020a170902720b00b001b668bb6ad0mr5074774plb.55.1692283182114; Thu, 17 Aug 2023 07:39:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692283182; cv=none; d=google.com; s=arc-20160816; b=0mxyYFI/E37xpxpAVVUfwkb4KNBjFu7ANwTTV9YwjimXtmyst2j10QYKe+QW7l1wys VOvrJsO3gNjfjWcZuJpfJzRW7Smyrh4MEKMc9Ao45AWWX63OXkH8pMy6WB4fjR3tezF9 cMR8QAWtFrSuKOy3gITzjpyVt6zeg1JSHQDUK2awpQmgwTihD1EvUI5K5+DcXWs2BhQ9 8arJAt4PnWHAKe3vP4zG3nyTzQgQpNh5CFC1VYI3RixCmjOQGk515go22+9zXSLMfaHF AWkmyKVPyrmg3HKjlKuHgrxz2/7vTMRKuLyDh8SAYTs56ZbN7Q41IBNQvzH9vqzxiewJ p1QQ== 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 :message-id:date:subject:cc:to:from; bh=d1jeDskMsU//ByGoW9pPFqmHOL62hZEuhQCpL0pj8ho=; fh=MkjW1f1ixasRiKuzf2PaYxsdrg4RoFahP+0zEUjLGHA=; b=lSyl5E7eEoal4LLIiPn06JrCNHRHnKREUTxdnlBvZeUpGF1FQgUGrEYKAK1ZkCFno0 zL3m1S/26nl5W9VRCETBCIsSoDh9SJb2JxUvaC95rrwoYJEa++V2nPbWP9/uzD9AkZ43 n57tDDluERcvwSpw3uqX0nPBv7uGgoDtFWpSJVyi4/CN2YqGEid8pm9Tpi4TlipLvedX XDuW0v9+VbNvVjNDo/+KQCecbAvXtcJwfGLnwy4/EAL0YDimyVYwSiX4oQ12+CbWPQus alcRuVHh5pJbpchc4HbtuNxdTNFu/y3xuN+qTsgrLl5QeBkcl3WjbEAVgMTYYd6X8eGf q1Dw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cp12-20020a170902e78c00b001bba8f79ad0si12561100plb.109.2023.08.17.07.39.27; Thu, 17 Aug 2023 07:39:42 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241178AbjHPCBB (ORCPT + 99 others); Tue, 15 Aug 2023 22:01:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241160AbjHPCAk (ORCPT ); Tue, 15 Aug 2023 22:00:40 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 849AA10EC; Tue, 15 Aug 2023 19:00:39 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RQWXP3fn1z1GDLH; Wed, 16 Aug 2023 09:59:17 +0800 (CST) Received: from huawei.com (10.67.174.28) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Wed, 16 Aug 2023 10:00:36 +0800 From: Liao Chang To: , CC: , Subject: [PATCH] cpufreq: Use clamp helper macro to improve the code readability Date: Wed, 16 Aug 2023 01:58:53 +0000 Message-ID: <20230816015853.849426-1-liaochang1@huawei.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.67.174.28] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774487530455734942 X-GMAIL-MSGID: 1774487530455734942 The valid values of policy.{min, max} should be between 'min' and 'max', so use clamp() helper macro to makes cpufreq_verify_within_limits() more readable. Signed-off-by: Liao Chang --- include/linux/cpufreq.h | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 99da27466b8f..43b363a99215 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -19,6 +19,7 @@ #include #include #include +#include /********************************************************************* * CPUFREQ INTERFACE * @@ -467,17 +468,8 @@ static inline void cpufreq_verify_within_limits(struct cpufreq_policy_data *poli unsigned int min, unsigned int max) { - if (policy->min < min) - policy->min = min; - if (policy->max < min) - policy->max = min; - if (policy->min > max) - policy->min = max; - if (policy->max > max) - policy->max = max; - if (policy->min > policy->max) - policy->min = policy->max; - return; + policy->max = clamp(policy->max, min, max); + policy->min = clamp(policy->min, min, policy->max); } static inline void