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

Re: [XEN PATCH 09/13] xen/public: fixed violations of MISRA C:2012 Rule 7.2


  • To: Simone Ballarin <simone.ballarin@xxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 20 Jun 2023 15:00:25 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.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=CqxUeh3KPPvN+mv0Mu2fwlBD4Uuy4eC7AKdzDm94pPc=; b=f90qwR7HPt7bCv9GHWntEGftdQWUEtxvXVD7RUizvaQUKYDZ6Ntw5ig0TKWXj8C1SB58Mcsvgxai09F20dyh/dWCISJ32ZqRJkb8IaKNp1gvkGbDsFCmrJICWc+iB8qC9Ak4iZgACraeoKMO7+JYJdQEUPDPyWeroR0ilxjZMEHA9V3Fv0iJRYJiqF/NWv/FbIq1sNxhbidewf0hmKs/JTpNby3F4bT3mNGaqXXQStdc2q8xk9fVAhwtsUS0wQ3kOaKbL0VsD3TTn7nRiDmNbJhaQX2JFbV7Bz6acfO6NjR7DHeWMgTXFU4zM/syiBICFv2xHllvP2kcOZLRxRnYvg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zgou5EdjO2+6Yn0yFR55goWcCksNfl01y3tSAIWgKdGyCp9l91vHvBeKFFP45PhWiRTqZcJhIMdyuvLIP4jdgf9KtuusWgPdeI3C72ChO/v/vyacwTzK+F1nG8Wm6rMqpwKdgkagF7USDqEU92QhJmKndRfxrJhA3k6H2xz1/SvCmvxnoqC3dHz1EHYrKP+cg4qYa1qOAMGxBfD/DFRqZ/hdIuow29MIBXtoONZL1KFxqwnIc/SD/wYo2COXOLIckjHqYpfuS/Gjc2pVM7Odo0sl19JoZgTrCKmTEvNI8H5V/UQ79JWQQv5vTA3hajshQvvEA0i6hiXc7W0aht9biA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: consulting@xxxxxxxxxxx, Gianluca Luparini <gianluca.luparini@xxxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Xenia Ragiadakou <Xenia.Ragiadakou@xxxxxxx>, Ayan Kumar <ayan.kumar.halder@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 20 Jun 2023 13:01:09 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 20.06.2023 12:35, Simone Ballarin wrote:
> --- a/xen/include/public/io/ring.h
> +++ b/xen/include/public/io/ring.h
> @@ -36,11 +36,11 @@
>  typedef unsigned int RING_IDX;
>  
>  /* Round a 32-bit unsigned constant down to the nearest power of two. */
> -#define __RD2(_x)  (((_x) & 0x00000002) ? 0x2                  : ((_x) & 
> 0x1))
> -#define __RD4(_x)  (((_x) & 0x0000000c) ? __RD2((_x)>>2)<<2    : __RD2(_x))
> -#define __RD8(_x)  (((_x) & 0x000000f0) ? __RD4((_x)>>4)<<4    : __RD4(_x))
> -#define __RD16(_x) (((_x) & 0x0000ff00) ? __RD8((_x)>>8)<<8    : __RD8(_x))
> -#define __RD32(_x) (((_x) & 0xffff0000) ? __RD16((_x)>>16)<<16 : __RD16(_x))
> +#define __RD2(_x)  (((_x) & 0x00000002U) ? 0x2                  : ((_x) & 
> 0x1))
> +#define __RD4(_x)  (((_x) & 0x0000000cU) ? __RD2((_x)>>2)<<2    : __RD2(_x))
> +#define __RD8(_x)  (((_x) & 0x000000f0U) ? __RD4((_x)>>4)<<4    : __RD4(_x))
> +#define __RD16(_x) (((_x) & 0x0000ff00U) ? __RD8((_x)>>8)<<8    : __RD8(_x))
> +#define __RD32(_x) (((_x) & 0xffff0000U) ? __RD16((_x)>>16)<<16 : __RD16(_x))

While I don't mind the suffixes being added, I'm wondering how
the tool would have spotted the single violation here. Iirc we
don't use this header anywhere in the hypervisor.

If this block is to be touched, I think it wants correcting for
style at the same time: There are numerous blanks missing, and
especially in a public header we shouldn't use underscore-
prefixed names outside of their spec permitted purpose. (This is
about _x; I'm not convinced we can change the various __RD<n>.)

Furthermore, if I recall correctly Misra also mandates single
evaluation of macro arguments. While I don't immediately see how
to address that without resorting to compiler extensions, I don't
think it makes sense to address one violation here but not he
other (the more when the code in question doesn't affect the
hypervisor build).

Jan



 


Rackspace

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