[XEN PATCH v2 3/3] xen: fix violations of MISRA C:2012 Rule 3.1

Nicola Vetrini posted 3 patches 2 years, 7 months ago
There is a newer version of this series
[XEN PATCH v2 3/3] xen: fix violations of MISRA C:2012 Rule 3.1
Posted by Nicola Vetrini 2 years, 7 months ago
In the files modified by this patch there are a few occurrences of nested '//'
character sequences inside C-style comment blocks, which violate Rule 3.1.
The patch aims to resolve those by removing the nested comments.

In the file `xen/common/xmalloc_tlsf.c' the comment has been deleted,
following the suggestion of a review comment.

In the file `xen/include/xen/atomic.h' the nested comment has been removed,
since the code sample is already explained by the preceding comment.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com
Changes:
- Resending the patch with the right maintainers in CC.
Changes in V2:
- Split the patch into a series and reworked the fix.
- Apply the fix to the arm32 `flushtlb.h' file, for consistency
Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
 xen/common/xmalloc_tlsf.c | 3 ---
 xen/include/xen/atomic.h  | 2 +-
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/xen/common/xmalloc_tlsf.c b/xen/common/xmalloc_tlsf.c
index 75bdf18c4e..4f9f60a39d 100644
--- a/xen/common/xmalloc_tlsf.c
+++ b/xen/common/xmalloc_tlsf.c
@@ -140,9 +140,6 @@ static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl)
         *fl = flsl(*r) - 1;
         *sl = (*r >> (*fl - MAX_LOG2_SLI)) - MAX_SLI;
         *fl -= FLI_OFFSET;
-        /*if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
-         *fl = *sl = 0;
-         */
         *r &= ~t;
     }
 }
diff --git a/xen/include/xen/atomic.h b/xen/include/xen/atomic.h
index 529213ebbb..fa750a18ae 100644
--- a/xen/include/xen/atomic.h
+++ b/xen/include/xen/atomic.h
@@ -78,7 +78,7 @@ static inline void _atomic_set(atomic_t *v, int i);
  *      int old = atomic_read(&v);
  *      int new = old + 1;
  *      if ( likely(old == atomic_cmpxchg(&v, old, new)) )
- *          break; // success!
+ *          break;
  *  }
  */
 static inline int atomic_cmpxchg(atomic_t *v, int old, int new);
-- 
2.34.1
Re: [XEN PATCH v2 3/3] xen: fix violations of MISRA C:2012 Rule 3.1
Posted by Jan Beulich 2 years, 7 months ago
On 19.06.2023 11:56, Nicola Vetrini wrote:
> --- a/xen/common/xmalloc_tlsf.c
> +++ b/xen/common/xmalloc_tlsf.c
> @@ -140,9 +140,6 @@ static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl)
>          *fl = flsl(*r) - 1;
>          *sl = (*r >> (*fl - MAX_LOG2_SLI)) - MAX_SLI;
>          *fl -= FLI_OFFSET;
> -        /*if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
> -         *fl = *sl = 0;
> -         */
>          *r &= ~t;
>      }
>  }

As indicated before, I don't think simply dropping the commented out code
is appropriate here. Personally I'd prefer if it was kept (using #if/#else),
but I'd also be okay with replacing it by a respective assertion. That said,
if other maintainers think this is the way to go, then I don't mean to
stand in the way.

Jan
Re: [XEN PATCH v2 3/3] xen: fix violations of MISRA C:2012 Rule 3.1
Posted by Nicola Vetrini 2 years, 7 months ago

On 19/06/23 12:29, Jan Beulich wrote:
> On 19.06.2023 11:56, Nicola Vetrini wrote:
>> --- a/xen/common/xmalloc_tlsf.c
>> +++ b/xen/common/xmalloc_tlsf.c
>> @@ -140,9 +140,6 @@ static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl)
>>           *fl = flsl(*r) - 1;
>>           *sl = (*r >> (*fl - MAX_LOG2_SLI)) - MAX_SLI;
>>           *fl -= FLI_OFFSET;
>> -        /*if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
>> -         *fl = *sl = 0;
>> -         */
>>           *r &= ~t;
>>       }
>>   }
> 
> As indicated before, I don't think simply dropping the commented out code
> is appropriate here. Personally I'd prefer if it was kept (using #if/#else),
> but I'd also be okay with replacing it by a respective assertion. That said,
> if other maintainers think this is the way to go, then I don't mean to
> stand in the way.
> 

As Andrew Cooper suggested in the previous patch revision 
(https://lore.kernel.org/xen-devel/6bac57d5-c30e-f763-3abe-b3f335f366f7@suse.com/T/#m5722285215bb30d7f1202b9921e2c92d5ea98d6a), 
I removed the commented-out code, since it contains unused logic, but I 
would be okay with replacing it with an assertion, if you think it's better.

Regards,

-- 
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)