Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1251920pxb; Tue, 26 Oct 2021 05:42:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRicHknyNbzq5JWp6ZL8XYpf/+9X5rUEqANWfLXOhCwzmDBF+xu1YTUf9cW4A88tDUYAHr X-Received: by 2002:a05:6a00:181d:b0:44d:8425:fbe3 with SMTP id y29-20020a056a00181d00b0044d8425fbe3mr25688107pfa.6.1635252146976; Tue, 26 Oct 2021 05:42:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635252146; cv=none; d=google.com; s=arc-20160816; b=c1hYXrBJzAFyqZm2zR+kKhaVTJ4E2Uhommsb2hTy1FsBE2g9J8eq5+UCOAJPI9hr4L o7lAIJ9RE5+Yl8DQqnVFUv7xorkAhvM+zQN2IVdSlobX675mnW91Eg/tzy7phGwWqIzG o2PscR0wKvdBmo4fzvVaACn5kJ9DthkM1FETu5XnRfcNkJu6YtGxoSfmd+WUQELzR+J9 866bloiM2r8+IUuwnXasw9BMHkd/QuRDpRhPgv3oavBpMjMQtss5tOU2SbyT00T8BMJM 4JPD+G4pVFtVtseQQruiJKsx/BxKK13b1374fCPO43Rmj46TlB1/CdccG2CTx5HkzltC TBLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=TgsEsJNiP0b2y8ORWxJDtG8GSO902rjuAtIwSFtBb+o=; b=Jpw46IvVb1oqqZ4jaA+5ua5C1Thzx60Yq5PYgQrQNXM5AzwpVLrhsxxW7Yf3Ys8u2E CkpujeU2DeDzvMgjDryOBFRcj7LqPecx9N/cFyOu6oh07ghdk10G3SDnFo17JIQNU/Si 3JJc4XeP7QGgDi7LyNuITCEOuPeYi6KTIxZXPx+Q54Rlny8LsNo3moebqPWnsMYyTA5p i6shZCkER60AcXDHvmpbl8wONreq9Jjm4/IaMoef8j2RaOKAcD1I1KUpLWmxTOmWmPHJ CAHN62fhqSgA2rX2ecNbjWdm5w/Z2NYhENHgyDI6Sojs21wZUDMHDhCuo5wpGNJuiIaI m6iQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bf2si26670844plb.35.2021.10.26.05.41.44; Tue, 26 Oct 2021 05:42:26 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234847AbhJZJ3t (ORCPT + 99 others); Tue, 26 Oct 2021 05:29:49 -0400 Received: from smtp23.cstnet.cn ([159.226.251.23]:52770 "EHLO cstnet.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234781AbhJZJ3T (ORCPT ); Tue, 26 Oct 2021 05:29:19 -0400 Received: from localhost.localdomain (unknown [124.16.138.128]) by APP-03 (Coremail) with SMTP id rQCowADnyebAyXdhyEH+BA--.24790S2; Tue, 26 Oct 2021 17:26:24 +0800 (CST) From: Jiasheng Jiang To: song@kernel.org, valentin.schneider@arm.com, peterz@infradead.org, mingo@kernel.org, dave.hansen@linux.intel.com, bristot@redhat.com, namit@vmware.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH] cpumask and md/raid5: Fix implicit type conversion Date: Tue, 26 Oct 2021 09:26:23 +0000 Message-Id: <1635240383-2568329-1-git-send-email-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: rQCowADnyebAyXdhyEH+BA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-IP: [124.16.138.128] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The description of the macro in `include/linux/cpumask.h` says the variable 'cpu' can be unsigned int. However in the for_each_cpu(), for_each_cpu_wrap() and for_each_cpu_and(), its value is assigned to -1. That doesn't make sense. Moreover in the cpumask_next(), cpumask_next_zero(), cpumask_next_wrap() and cpumask_next_and(), 'cpu' will be implicitly type conversed to int if the type is unsigned 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 fix the macro description of 'cpu' that remove the '(optionally unsigned)' and change the definition of 'cpu' in `drivers/md/raid5.c` from unsigned long to long. Fixes: c743f0a ("sched/fair, cpumask: Export for_each_cpu_wrap()") Fixes: 8bd93a2 ("rcu: Accelerate grace period if last non-dynticked CPU") Fixes: 984f2f3 ("cpumask: introduce new API, without changing anything, v3") Fixes: 738a273 ("md/raid5: fix allocation of 'scribble' array.") Signed-off-by: Jiasheng Jiang --- drivers/md/raid5.c | 2 +- include/linux/cpumask.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 7d4ff8a..32ef82b 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -2425,7 +2425,7 @@ static int scribble_alloc(struct raid5_percpu *percpu, static int resize_chunks(struct r5conf *conf, int new_disks, int new_sectors) { - unsigned long cpu; + long cpu; int err = 0; /* diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index bfc4690..ceaed99 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -232,7 +232,7 @@ int cpumask_any_distribute(const struct cpumask *srcp); /** * for_each_cpu - iterate over every cpu in a mask - * @cpu: the (optionally unsigned) integer iterator + * @cpu: the integer iterator * @mask: the cpumask pointer * * After the loop, cpu is >= nr_cpu_ids. @@ -244,7 +244,7 @@ int cpumask_any_distribute(const struct cpumask *srcp); /** * for_each_cpu_not - iterate over every cpu in a complemented mask - * @cpu: the (optionally unsigned) integer iterator + * @cpu: the integer iterator * @mask: the cpumask pointer * * After the loop, cpu is >= nr_cpu_ids. @@ -258,7 +258,7 @@ extern int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool /** * for_each_cpu_wrap - iterate over every cpu in a mask, starting at a specified location - * @cpu: the (optionally unsigned) integer iterator + * @cpu: the integer iterator * @mask: the cpumask poiter * @start: the start location * @@ -273,7 +273,7 @@ extern int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool /** * for_each_cpu_and - iterate over every cpu in both masks - * @cpu: the (optionally unsigned) integer iterator + * @cpu: the integer iterator * @mask1: the first cpumask pointer * @mask2: the second cpumask pointer * -- 2.7.4