From patchwork Mon Sep 30 12:49:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Federico Serafini X-Patchwork-Id: 13816275 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 88FB0CF64B0 for ; Mon, 30 Sep 2024 12:50:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.807348.1218742 (Exim 4.92) (envelope-from ) id 1svFqZ-0005gP-S1; Mon, 30 Sep 2024 12:49:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 807348.1218742; Mon, 30 Sep 2024 12:49:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1svFqZ-0005gI-PU; Mon, 30 Sep 2024 12:49:51 +0000 Received: by outflank-mailman (input) for mailman id 807348; Mon, 30 Sep 2024 12:49:50 +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 1svFqX-0005M5-Vk for xen-devel@lists.xenproject.org; Mon, 30 Sep 2024 12:49:50 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7aa7dad5-7f2a-11ef-a0ba-8be0dac302b0; Mon, 30 Sep 2024 14:49:49 +0200 (CEST) Received: from truciolo.bugseng.com (unknown [37.161.44.57]) by support.bugseng.com (Postfix) with ESMTPSA id 86F224EE0746; Mon, 30 Sep 2024 14:49:47 +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: 7aa7dad5-7f2a-11ef-a0ba-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=bugseng.com; s=mail; t=1727700589; bh=QeRq5WatM5/gynhxqWft0r5yBBUgCUUQ3Qn003k14R0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F2S5X2u1gO2RIoVnDJLQE2s1VuP3OmT57wAOwC51Lbs5wJ2TwvrrlmuDBAaxR7ypG LHQnkUq0vQqmulVdxcox1DXj8M32lActpeOB9RoJT4Bmc2ianwWVn6+iRbu+9jvvKK BODpWPz8C9zigzTwJak1zE9YHOgQIsfPtw3EzjOLuxHsIX7jbcEzv1JbejDNkmMnpg 5TVD0xVp3KBxQt2H5aXbbGLvzr2KL6JmmO4XtRuCbooYgDLjRPBJWMrG8MpYaMXM9K W9EXToQhI3fUrprZ2tScNMK9eOTgOAV0hkf+F1KRvJe9aA8BITrdZtaDp2Uf87AUxV AapPGP0Usim8A== From: Federico Serafini To: xen-devel@lists.xenproject.org Cc: consulting@bugseng.com, Federico Serafini , "Daniel P. Smith" , =?utf-8?q?Marek_Marczykow?= =?utf-8?q?ski-G=C3=B3recki?= , Jan Beulich , Stefano Stabellini , Andrew Cooper Subject: [XEN PATCH v2 1/3] EFI: address a violation of MISRA C Rule 13.6 Date: Mon, 30 Sep 2024 14:49:15 +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 which is 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 Acked-by: Marek Marczykowski-Górecki --- Changes in v2: - better description. --- xen/common/efi/runtime.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/xen/common/efi/runtime.c b/xen/common/efi/runtime.c index d03e5c90ce..acf08dcaa3 100644 --- a/xen/common/efi/runtime.c +++ b/xen/common/efi/runtime.c @@ -250,14 +250,20 @@ int efi_get_info(uint32_t idx, union xenpf_efi_info *info) info->cfg.addr = __pa(efi_ct); info->cfg.nent = efi_num_ct; break; + case XEN_FW_EFI_VENDOR: + { + XEN_GUEST_HANDLE_PARAM(CHAR16) vendor_name = + guest_handle_cast(info->vendor.name, CHAR16); + if ( !efi_fw_vendor ) return -EOPNOTSUPP; + info->vendor.revision = efi_fw_revision; n = info->vendor.bufsz / sizeof(*efi_fw_vendor); - if ( !guest_handle_okay(guest_handle_cast(info->vendor.name, - CHAR16), n) ) + if ( !guest_handle_okay(vendor_name, n) ) return -EFAULT; + for ( i = 0; i < n; ++i ) { if ( __copy_to_guest_offset(info->vendor.name, i, @@ -267,6 +273,8 @@ int efi_get_info(uint32_t idx, union xenpf_efi_info *info) break; } break; + } + case XEN_FW_EFI_MEM_INFO: for ( i = 0; i < efi_memmap_size; i += efi_mdesc_size ) {