From patchwork Mon Sep 30 12:49:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Federico Serafini X-Patchwork-Id: 13816274 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 8F3DFCF64A6 for ; Mon, 30 Sep 2024 12:50:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.807350.1218763 (Exim 4.92) (envelope-from ) id 1svFqc-0006BF-Br; Mon, 30 Sep 2024 12:49:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 807350.1218763; Mon, 30 Sep 2024 12:49:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1svFqc-0006B8-8B; Mon, 30 Sep 2024 12:49:54 +0000 Received: by outflank-mailman (input) for mailman id 807350; Mon, 30 Sep 2024 12:49:52 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1svFqa-0005el-DJ for xen-devel@lists.xenproject.org; Mon, 30 Sep 2024 12:49:52 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7b738270-7f2a-11ef-99a2-01e77a169b0f; Mon, 30 Sep 2024 14:49:51 +0200 (CEST) Received: from truciolo.bugseng.com (unknown [37.161.44.57]) by support.bugseng.com (Postfix) with ESMTPSA id 8E5524EE074C; Mon, 30 Sep 2024 14:49:49 +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: 7b738270-7f2a-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=bugseng.com; s=mail; t=1727700590; bh=tAlH5qx3tE+Jaw9OwhxZVte9uodMsa8rU6Z7XQGTGJU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u3kEpWfdlOTNaxngRs6M4fiXbraQFOJoW1z9LpehVzN30ejy7IH0qIhKVkSoXPcuF O64OCK9wymMLkdpbhbuA3R1Wt5prdinNMm1tsWl4zNUSzt6xWFyV7eGLqH0fGXoCto JQ0LIV/uPGoBfM+oAcKBrnV/fHf9Uqyiru5+sX35nmasde1EsUtcJs85Bge3BUwoL6 /Y0PkOqHNxakut4CAUdGe0tKJ4L8OX5aIXElC3Qjbo/1yNl8SgkUKxx9BbHviEBXyp 1ZsUCtvkx1A58MLDIh9EZuD9f8Nk0wEkr/TO2gnnxXgwiJlZ9iakwAPxTZ3/pF+Vuo OMrK/E1pqxwQg== From: Federico Serafini To: xen-devel@lists.xenproject.org Cc: consulting@bugseng.com, Federico Serafini , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [XEN PATCH v2 2/3] xen/gnttab: address a violation of MISRA C Rule 13.6 Date: Mon, 30 Sep 2024 14:49:16 +0200 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 guest_handle_ok()'s expansion contains a sizeof() involving its first argument guest_handle_cast(). The expansion of the latter, in turn, contains a variable initialization. Since MISRA considers the initialization (even of a local variable) a side effect, the chain of expansions mentioned above violates MISRA C:2012 Rule 13.6 (The operand of the `sizeof' operator shall not contain any expression which has potential side effect). Refactor the code to address the rule violation. Suggested-by: Andrew Cooper Signed-off-by: Federico Serafini Reviewed-by: Stefano Stabellini --- Changes in v2: - better description; - preserved original indentation. --- xen/common/compat/grant_table.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/xen/common/compat/grant_table.c b/xen/common/compat/grant_table.c index 5ad0debf96..bbb717bf64 100644 --- a/xen/common/compat/grant_table.c +++ b/xen/common/compat/grant_table.c @@ -78,12 +78,15 @@ int compat_grant_table_op( cmd_op = cmd; switch ( cmd_op ) { -#define CASE(name) \ - case GNTTABOP_##name: \ - if ( unlikely(!guest_handle_okay(guest_handle_cast(uop, \ - gnttab_##name##_compat_t), \ - count)) ) \ - rc = -EFAULT; \ +#define CASE(name) \ + case GNTTABOP_ ## name: \ + { \ + XEN_GUEST_HANDLE_PARAM(gnttab_ ## name ## _compat_t) h = \ + guest_handle_cast(uop, gnttab_ ## name ## _compat_t); \ + \ + if ( unlikely(!guest_handle_okay(h, count)) ) \ + rc = -EFAULT; \ + } \ break #ifndef CHECK_gnttab_map_grant_ref