From nobody Sat Sep 21 03:19:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1689177357648883.4098064211328; Wed, 12 Jul 2023 08:55:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.562643.879378 (Exim 4.92) (envelope-from ) id 1qJcBB-0003XL-Tb; Wed, 12 Jul 2023 15:55:01 +0000 Received: by outflank-mailman (output) from mailman id 562643.879378; Wed, 12 Jul 2023 15:55:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qJcBB-0003XE-QB; Wed, 12 Jul 2023 15:55:01 +0000 Received: by outflank-mailman (input) for mailman id 562643; Wed, 12 Jul 2023 15:55:00 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qJcBA-0003X8-0I for xen-devel@lists.xenproject.org; Wed, 12 Jul 2023 15:55:00 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 73d3d39f-20cc-11ee-b239-6b7b168915f2; Wed, 12 Jul 2023 17:54:58 +0200 (CEST) Received: from nico.bugseng.com (unknown [37.161.151.90]) by support.bugseng.com (Postfix) with ESMTPSA id 6D25A4EE0C89; Wed, 12 Jul 2023 17:54:56 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 73d3d39f-20cc-11ee-b239-6b7b168915f2 From: Nicola Vetrini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, michal.orzel@amd.com, xenia.ragiadakou@amd.com, ayan.kumar.halder@amd.com, consulting@bugseng.com, Nicola Vetrini , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Wei Liu Subject: [XEN PATCH] xen: fix violations of MISRA C:2012 Rule 3.1 Date: Wed, 12 Jul 2023 17:54:44 +0200 Message-Id: <9a27f6cbe552a00274f7ad32eec63f0e80e7644f.1689176790.git.nicola.vetrini@bugseng.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1689177359844100001 Content-Type: text/plain; charset="utf-8" In the file 'xen/common/xmalloc_tlsf.c' is not clear how the commented-out code should interact with the previous statement. To resolve the MISRA violation generated by the nested comment a #if .. #endif block with an explanatory comment substitutes the earlier construct. 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 Reviewed-by: Luca Fancellu Reviewed-by: Stefano Stabellini --- Following the suggestion of this message https://lore.kernel.org/xen-devel/536f3049-41f7-b127-ba94-81925e34ea0f@suse= .com/ an explanatory comment has been added. --- xen/common/xmalloc_tlsf.c | 13 ++++++++++--- xen/include/xen/atomic.h | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/xen/common/xmalloc_tlsf.c b/xen/common/xmalloc_tlsf.c index c21bf71e88..56c3849414 100644 --- a/xen/common/xmalloc_tlsf.c +++ b/xen/common/xmalloc_tlsf.c @@ -139,10 +139,17 @@ static inline void MAPPING_SEARCH(unsigned long *r, i= nt *fl, int *sl) *r =3D *r + t; *fl =3D flsl(*r) - 1; *sl =3D (*r >> (*fl - MAX_LOG2_SLI)) - MAX_SLI; - *fl -=3D FLI_OFFSET; - /*if ((*fl -=3D FLI_OFFSET) < 0) // FL will be always >0! - *fl =3D *sl =3D 0; + /*=20 + * It's unclear what was the purpose of the commented-out code tha= t now + * is in the #else branch. The current form is motivated by the co= rrection + * of a violation MISRA:C 2012 Rule 3.1 */ +#if 1 + *fl -=3D FLI_OFFSET; +#else + if ((*fl -=3D FLI_OFFSET) < 0) // FL will be always >0! + *fl =3D *sl =3D 0; +#endif *r &=3D ~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 =3D atomic_read(&v); * int new =3D old + 1; * if ( likely(old =3D=3D atomic_cmpxchg(&v, old, new)) ) - * break; // success! + * break; * } */ static inline int atomic_cmpxchg(atomic_t *v, int old, int new); --=20 2.34.1