Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp249048pxb; Fri, 29 Oct 2021 09:09:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZUSy4opLvqNTtjWgZFB8OJdPKX0kV9dbpENMfe3y7jcVGGJb6XxSuJPR2RcqPYbKOA0so X-Received: by 2002:a05:6e02:1b0a:: with SMTP id i10mr8414516ilv.115.1635523767030; Fri, 29 Oct 2021 09:09:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635523767; cv=none; d=google.com; s=arc-20160816; b=q3Sc96cW711xdDJrpSIW9iJPXkSuukMJpVo1L6aJ8ObyjjB6t7s1/ClfIPO941R/2v 83Bd2RH4pTxh4nuODNksQ39pBfPjhSQn/hk2AjfmmmjpHxRth3xvRdnEcLkvKD4AsEtx YgYxVktMpddAlLBSkBA9kFTruaKKpOLjEzo10JlrB/iB4yGRGnpDcFG4qOe3wZgDLOvs GLPDZ7z4aru+vNtBS3BCyKZUpNWchtl8R6Du02ubHppaEQH6IHJBjYRBPLGtZsjLw+1x hLKGrNL6UwfFhvvqbvLzlOgKQxj/wZe8a3AehIGvAvIwCNaPLVWEofJOQSSxT83Joekw PAlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=lu7KlDiDD4b+IN0GOyZKFEqg42aag7ye4ODeWU/vdAQ=; b=F0o6tO3eKvJ7ZgQ9nKfCDFB8v0GiEdwzDma2ZMs7zWeF88EGi+XKKipcy8r0afggN+ Y4yd34PP+Y59a6Obi3/si67YMEcbJD93u+/rWd36FyiEVI495PRjZfDIy4zuLxIknTeC +TByMGQYTdzWiahJt8G702VYbBEw9ZzrYhW9eSklYaY79XdQvSKFHAOAISu7ZHkAC1Ct bbWfcVDKgCXUIUW45CfH2euFkM4lNT/roTGikBjBAGr9S48yJ6zXO9EspDGeMS4kC6Te PaSbf1B6OYkHSGy+BslZi6M3cjAq2qfkkxKC7AC1IAsle0DkCEn+5UuYEZj2FGxlxyNQ c1Aw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t3si2743495jaj.77.2021.10.29.09.08.58; Fri, 29 Oct 2021 09:09:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S229894AbhJ2QKA (ORCPT + 99 others); Fri, 29 Oct 2021 12:10:00 -0400 Received: from mail-oi1-f172.google.com ([209.85.167.172]:41758 "EHLO mail-oi1-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229607AbhJ2QJ7 (ORCPT ); Fri, 29 Oct 2021 12:09:59 -0400 Received: by mail-oi1-f172.google.com with SMTP id y128so13997363oie.8; Fri, 29 Oct 2021 09:07:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lu7KlDiDD4b+IN0GOyZKFEqg42aag7ye4ODeWU/vdAQ=; b=PrXYCtu+BFF+QJN+asWOiR2YFHkZIsbcMUyKLpUL+QC7zzclyzL5dzw+z8O85DbI+X F3k2O/Z/h6c1UWz/tojbkbsd8W3iyShUJ3Q5pIb/kDBqLhE6FWmHhQdLiKsFlc1D4u8o NVyH+qD3Jl3tztpsHodFIMoTaCxiuIKElff6A+Qen9uedgYcupEd/Lfubfvig+GOKlSd thMtx6cG4RKe/JSgS1DlCTLRm3Wro/xC6hpIoqNBy/zwCNTX9AxeStR3L1bMN/vgohjd oKhJvgany22eMbH6n/vTlfr751bxSqP4O3rL92U7J5xqgY9b43JaRgB6gJpxVJs3olrV RqwQ== X-Gm-Message-State: AOAM531MyMxyBz0o1j50OblMgSa3GKQ/xSOT4yKW2htUXfN0snziHLXB FGWA/LHFMatTeqIgrTH/IwP0TUeTiVBd0FzCRHI= X-Received: by 2002:a05:6808:e90:: with SMTP id k16mr8536510oil.166.1635523649047; Fri, 29 Oct 2021 09:07:29 -0700 (PDT) MIME-Version: 1.0 References: <1635478517-3071352-1-git-send-email-jiasheng@iscas.ac.cn> In-Reply-To: <1635478517-3071352-1-git-send-email-jiasheng@iscas.ac.cn> From: "Rafael J. Wysocki" Date: Fri, 29 Oct 2021 18:07:18 +0200 Message-ID: Subject: Re: [PATCH] cpufreq: Fix implicit type conversion To: Jiasheng Jiang Cc: "Rafael J. Wysocki" , Viresh Kumar , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Benjamin Segall , Mel Gorman , Daniel Bristot de Oliveira , Linux PM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 29, 2021 at 5:51 AM Jiasheng Jiang wrote: > > 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 Yes, it does. The binary representation of -1 is an all-ones value of the size of int. It is perfectly valid to store that value in an unsigned int variable. > and in the cpumask_next() they are implicitly type conversed to int. However, the return type of cpumask_next() is unsigned int. > It is universally accepted that the implicit type conversion is terrible. I wouldn't say "terrible", but yes, it is risky when dealing with variables of different sizes and possible sign-extensions. In this particular case, I don't see a problem. > 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); > -- > 2.7.4 >