From patchwork Wed Jul 12 15:54:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13310599 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F7E1EB64DD for ; Wed, 12 Jul 2023 15:55:40 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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 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, int *fl, int *sl) *r = *r + t; *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; + /* + * It's unclear what was the purpose of the commented-out code that now + * is in the #else branch. The current form is motivated by the correction + * of a violation MISRA:C 2012 Rule 3.1 */ +#if 1 + *fl -= FLI_OFFSET; +#else + if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0! + *fl = *sl = 0; +#endif *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);