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

Re: [XEN PATCH] xen: fixed violations of MISRA C:2012 Rule 3.1


  • To: nicola.vetrini@xxxxxxxxxxx
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 13 Jun 2023 09:17:45 +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=F531f/giZ3iCPJsfsXLG97Gf77R+b6XiuNGbz3dJ3vM=; b=UvLEhmC6UBDCr/irn/AZf0zrWJXDzrUTcD1KW9BhQDHAxY3YLXfzDB+f0YXYcvPmYyF7879aF9AOUHyMX53uHmpxuktsFG3gEzlyEQlaVJZYAy6E/IhvS8h3Yg2+GuR6n2u66bxIng9fd4flGxDsIwOGcTUSS0j0+64Lda2kMMnSY2ZcUPRHdoURVOCKVIY/boJDM7a2VxNorxPZz/PlskfODEPA/rtdtI0p/HRyibYq8qv64MqoZKmz2A00YiTKj9K/MrpkhsolGI1pp5RznhgswSl8o2pvr0S0pftv/D9glQhqapk0gYh0eYGbkET3TXlZqSFZoH+zycb2Ymz++g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JktSPI1gaqu2aUO8xum3XVPqOFbb+1fdXi/k48fL0GMnkIwh40Gcq55YyQcyc/Fs74DSyUYt5b0uAdfl9B8GxnK9+ltbW16nCf1jBQW0uy2ob0+FYP8tTG0hDBdnDxoz1z8PeP4dcRvr1PQ8EnplBvIJzIo+VE4OqHZzdmcrSzl9cDpYdKafOliW8znFnrT0NJHkwt7qozBn9lb96vt2JXMoJoFUBYJNPfCzo94Jm6Z8cgkcUUGz9EbahT0IEAr2PS1K3WXR/p+2uzoSbsJ0h1aushSGzpqaDa1RI57KM655G45Z/bXFF+ztZS/R10ZbbKQV3IVUtyqGyNHfHDGLXQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 13 Jun 2023 07:18:40 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 12.06.2023 18:10, nicola.vetrini@xxxxxxxxxxx wrote:
> From: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
> 
> The xen sources contain several violations of Rule 3.1 from MISRA C:2012,
> whose headline states:
> "The character sequences '/*' and '//' shall not be used within a comment".
> 
> Most of the violations are due to the presence of links to webpages within
> C-style comment blocks, such as:
> 
> xen/arch/arm/include/asm/smccc.h:37.1-41.3
> /*
>  * This file provides common defines for ARM SMC Calling Convention as
>  * specified in
>  * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html
>  */
> 
> In this case, we propose to deviate all of these occurrences with a
> project deviation to be captured by a tool configuration.

Here "propose" is appropriate in the description, as this is something
the patch does not do. Further down, however, you mean to describe what
the patch does, not what an eventual patch might do.

Somewhat similarly you don't want to use past tense in the title, as
that wants to describe what is being done, rather than describing a
patch that has already landed.

> There are, however, a few other violations that do not fall under this
> category, namely:
> 
> 1. in file "xen/arch/arm/include/asm/arm64/flushtlb.h" we propose to
> avoid the usage of a nested comment;
> 2. in file "xen/common/xmalloc_tlsf.c" we propose to substitute the
> commented-out if statement with a "#if 0 .. #endif;
> 3. in file "xen/include/xen/atomic.h" and
> "xen/drivers/passthrough/arm/smmu-v3.c" we propose to split the C-style
> comment containing the nested comment into two doxygen comments, clearly
> identifying the second as a code sample. This can then be captured with a
> project deviation by a tool configuration.

Finally I find the use of "we" somewhat suspicious. Who besides you is
it that you're talking about?

Also please don't forget to Cc relevant maintainers.

> --- a/xen/drivers/passthrough/arm/smmu-v3.c
> +++ b/xen/drivers/passthrough/arm/smmu-v3.c
> @@ -1045,15 +1045,18 @@ static int arm_smmu_atc_inv_domain(struct 
> arm_smmu_domain *smmu_domain,
>       /*
>        * Ensure that we've completed prior invalidation of the main TLBs
>        * before we read 'nr_ats_masters' in case of a concurrent call to
> -      * arm_smmu_enable_ats():
> +      * arm_smmu_enable_ats().
> +      */
> +     /**
> +      * Code sample: Ensures that we always see the incremented
> +      * 'nr_ats_masters' count if ATS was enabled at the PCI device before
> +      * completion of the TLBI.
>        *
>        *      // unmap()                      // arm_smmu_enable_ats()
>        *      TLBI+SYNC                       atomic_inc(&nr_ats_masters);
>        *      smp_mb();                       [...]
>        *      atomic_read(&nr_ats_masters);   pci_enable_ats() // writel()
>        *
> -      * Ensures that we always see the incremented 'nr_ats_masters' count if
> -      * ATS was enabled at the PCI device before completion of the TLBI.
>        */
>       smp_mb();
>       if (!atomic_read(&smmu_domain->nr_ats_masters))

I don't really know this code, but the use of inner comments looks
unnecessary to me here. The same could e.g. be achieved by

         *      unmap():                        arm_smmu_enable_ats():
         *      TLBI+SYNC                       atomic_inc(&nr_ats_masters);
         *      smp_mb();                       [...]
         *      atomic_read(&nr_ats_masters);   pci_enable_ats(); (i.e. 
writel())


and it would avoid the somewhat odd splitting of adjacent comments
(which then is at risk of someone later coming forward with a patch
re-combining them).

> --- a/xen/include/xen/atomic.h
> +++ b/xen/include/xen/atomic.h
> @@ -71,7 +71,10 @@ static inline void _atomic_set(atomic_t *v, int i);
>   * Returns the initial value in @v, hence succeeds when the return value
>   * matches that of @old.
>   *
> - * Sample (tries atomic increment of v until the operation succeeds):
> + */
> +/**
> + *
> + * Code sample: Tries atomic increment of v until the operation succeeds.
>   *
>   *  while(1)
>   *  {

Somewhat similarly here: I don't think the inner comment provides
much value, and could hence be dropped instead of splitting the comment.

Jan



 


Rackspace

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