From patchwork Fri Oct 29 03:35:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiasheng Jiang X-Patchwork-Id: 12591477 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 341CBC433F5 for ; Fri, 29 Oct 2021 03:51:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0394F604AC for ; Fri, 29 Oct 2021 03:51:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231611AbhJ2Dxu (ORCPT ); Thu, 28 Oct 2021 23:53:50 -0400 Received: from smtp25.cstnet.cn ([159.226.251.25]:41718 "EHLO cstnet.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231523AbhJ2Dxu (ORCPT ); Thu, 28 Oct 2021 23:53:50 -0400 X-Greylist: delayed 921 seconds by postgrey-1.27 at vger.kernel.org; Thu, 28 Oct 2021 23:53:49 EDT Received: from localhost.localdomain (unknown [124.16.138.128]) by APP-05 (Coremail) with SMTP id zQCowAAH6e32a3thTamVBQ--.42489S2; Fri, 29 Oct 2021 11:35:18 +0800 (CST) From: Jiasheng Jiang To: rjw@rjwysocki.net, viresh.kumar@linaro.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH] cpufreq: Fix implicit type conversion Date: Fri, 29 Oct 2021 03:35:17 +0000 Message-Id: <1635478517-3071352-1-git-send-email-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2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UYxBIda VFxhVjvjDU0xZFpf9x0JUk3ktUUUUU= X-Originating-IP: [124.16.138.128] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The variable 'cpu' and 'j' are defined as unsigned int. However in the for_each_cpu, their values are assigned to -1. That doesn't make sense and in the cpumask_next() they are implicitly type conversed to int. It is universally accepted that the implicit type conversion is terrible. Also, having the good programming custom will set an example for others. Thus, it might be better to change the definition of 'cpu' and 'j' from unsigned int to int. Signed-off-by: Jiasheng Jiang --- kernel/sched/cpufreq_schedutil.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 4f09afd..4aff4b6 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -409,7 +409,7 @@ static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time) struct sugov_policy *sg_policy = sg_cpu->sg_policy; struct cpufreq_policy *policy = sg_policy->policy; unsigned long util = 0, max = 1; - unsigned int j; + int j; for_each_cpu(j, policy->cpus) { struct sugov_cpu *j_sg_cpu = &per_cpu(sugov_cpu, j); @@ -746,7 +746,7 @@ static int sugov_start(struct cpufreq_policy *policy) { struct sugov_policy *sg_policy = policy->governor_data; void (*uu)(struct update_util_data *data, u64 time, unsigned int flags); - unsigned int cpu; + int cpu; sg_policy->freq_update_delay_ns = sg_policy->tunables->rate_limit_us * NSEC_PER_USEC; sg_policy->last_freq_update_time = 0; @@ -783,7 +783,7 @@ static int sugov_start(struct cpufreq_policy *policy) static void sugov_stop(struct cpufreq_policy *policy) { struct sugov_policy *sg_policy = policy->governor_data; - unsigned int cpu; + int cpu; for_each_cpu(cpu, policy->cpus) cpufreq_remove_update_util_hook(cpu);