[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] cpumask: fix integer type in cpumask_first


  • To: Julien Grall <julien@xxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Fri, 29 Sep 2023 08:59:56 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=c7V3x9oVYCnwnwQ0ylQkJgK9flJdUkJoM1L/gTTnOsA=; b=Qd8HxMO2sR/9Ys7Gb20eS+D2uxVq38lu/rOlvCac38CcpUeFY4i5q9y+GYbmofm4lyDcAwRWBPUkbk9rsx3Rf7dxAN8AUGfh/2ppUtjak52PtU3OrhzpMJGXNY501BM+UCh96bF9X45EfWGw27uWIhMCd/vWQn8QjzOlUqAUNBrwSG+LzZBJXTZ7u8c2iMhJ3YgWsOCj5b/O7NQocPgiow8seeAYsbJLZ7iTkam3U0bErJfyhih7m6wjJlPKU8mIBpA63zjRvioQ8+X2T9aSw+VjftRacggMqUbElTTcGQp8kXHJhLjXcjoXdDwuq9EBHRoZ+5HDh+ZrQyUdS4sAMQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PH5BSLZGfx98Za4nIfuphyMs+uUTyElTs2BiLVhgNEoK/iVPT5VxKD5mwiUo//6iysKqNkXvML4aEZUmyeDCQ4fauh8IuPp8IXDd7bq/TldO3sHziJr1uuVW2Ht+/bRvkm8oSGUJoqrplVEoq79pum5T/R50XoF0ATaHvs917QtEBWSxqYzxJvvDtRYE3oSq1dTT37VT+wQx5fKwNGbaOEKyAp7kOG+5sM+iJ/YU3ItKlQibg1YMg8kTMFLKkqaF0pYRbSgw25lQvvDQwF5TvF/BTTyVI+3fp5gmaXerzdfrV3Z/69dn4aE0Xw9zqMcqxtAJ5WcPhPpDaMtQpUOjow==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, "andrew.cooper3@xxxxxxxxxx" <andrew.cooper3@xxxxxxxxxx>, "roger.pau@xxxxxxxxxx" <roger.pau@xxxxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, "george.dunlap@xxxxxxxxxx" <george.dunlap@xxxxxxxxxx>, "wl@xxxxxxx" <wl@xxxxxxx>
  • Delivery-date: Fri, 29 Sep 2023 09:00:36 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHZ8mQSonovcLbkmUGYIzmbCmvOrrAxaSkAgAAYpIA=
  • Thread-topic: [PATCH] cpumask: fix integer type in cpumask_first


> On 29 Sep 2023, at 08:31, Julien Grall <julien@xxxxxxx> wrote:
> 
> Hi Stefano,
> 
> On 29/09/2023 00:32, Stefano Stabellini wrote:
>> nr_cpu_ids is unsigned int, but find_first_bit returns unsigned long (at
>> least on arm).
> 
> find_* are meant to be used by common code. So I think the first step is to 
> correct the return type so it is consistent across all architectures.
> 
> I don't have a strong opinion on whether they should all return 'unsigned 
> long'.
> 
> Then we can discuss if the MISRA rule is still violated.
> 
>> Use the larger type for min_t to avoid larger-to-smaller
>> type assignments. This address 141 MISRA C 10.3 violations.
> 
> I find interesting you are saying this given that...
>> Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxx>
>> ---
>> diff --git a/xen/include/xen/cpumask.h b/xen/include/xen/cpumask.h
>> index 9826707909..a6ed6a28e8 100644
>> --- a/xen/include/xen/cpumask.h
>> +++ b/xen/include/xen/cpumask.h
>> @@ -208,7 +208,7 @@ static inline void cpumask_copy(cpumask_t *dstp, const 
>> cpumask_t *srcp)
>>    static inline int cpumask_first(const cpumask_t *srcp)
>>  {
>> - return min_t(int, nr_cpu_ids, find_first_bit(srcp->bits, nr_cpu_ids));
>> + return min_t(unsigned long, nr_cpu_ids, find_first_bit(srcp->bits, 
>> nr_cpu_ids));
> 
> ... cpumask_first() is return 'int'. So rather than fixing it, you seem to 
> have just moved the violation.
> 
>>  }
>>    static inline int cpumask_next(int n, const cpumask_t *srcp)

I’ve also found that find_first_bit returns:

 - unsigned int on x86
 - unsigned long on ppc
 - unsigned long on arm64
 - int on arm32 (seems that value is always >= 0

So maybe they can be all unsigned int, and cpumask_first can be as well 
unsigned int?


> 
> Cheers,
> 
> -- 
> Julien Grall
> 


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.