From patchwork Thu Dec 14 12:07:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simone Ballarin X-Patchwork-Id: 13492950 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 333F8C10F13 for ; Thu, 14 Dec 2023 12:09:02 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.654520.1021487 (Exim 4.92) (envelope-from ) id 1rDkWH-0001Be-Ic; Thu, 14 Dec 2023 12:08:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 654520.1021487; Thu, 14 Dec 2023 12:08:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rDkWH-0001AS-Bl; Thu, 14 Dec 2023 12:08:49 +0000 Received: by outflank-mailman (input) for mailman id 654520; Thu, 14 Dec 2023 12:08:48 +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 1rDkWF-0000tI-VF for xen-devel@lists.xenproject.org; Thu, 14 Dec 2023 12:08:47 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 87e99b2e-9a79-11ee-9b0f-b553b5be7939; Thu, 14 Dec 2023 13:08:45 +0100 (CET) Received: from beta.station (net-37-182-35-120.cust.vodafonedsl.it [37.182.35.120]) by support.bugseng.com (Postfix) with ESMTPSA id 39B574EE0744; Thu, 14 Dec 2023 13:08:45 +0100 (CET) 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: 87e99b2e-9a79-11ee-9b0f-b553b5be7939 From: Simone Ballarin To: xen-devel@lists.xenproject.org Cc: consulting@bugseng.com, Maria Celeste Cesario , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Simone Ballarin Subject: [PATCH 1/9] xen/arm64: address violations of MISRA C:2012 Rule 11.8 Date: Thu, 14 Dec 2023 13:07:43 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 From: Maria Celeste Cesario The xen sources contain violations of MISRA C:2012 Rule 11.8 whose headline states: "A conversion shall not remove any const, volatile or _Atomic qualification from the type pointed to by a pointer". Add volatile qualifiers missing in casts. Arguments p and ptr are originally volatile-qualified. There's no reason to drop the qualifiers. No functional change. Signed-off-by: Maria Celeste Cesario Signed-off-by: Simone Ballarin Reviewed-by: Stefano Stabellini --- xen/arch/arm/arm64/lib/bitops.c | 6 ++++-- xen/arch/arm/include/asm/arm64/cmpxchg.h | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/arm64/lib/bitops.c b/xen/arch/arm/arm64/lib/bitops.c index 20e3f3d6ce..275a780329 100644 --- a/xen/arch/arm/arm64/lib/bitops.c +++ b/xen/arch/arm/arm64/lib/bitops.c @@ -32,7 +32,8 @@ static always_inline bool int_##name(int nr, volatile void *p, bool timeout,\ unsigned int max_try) \ { \ - volatile uint32_t *ptr = (uint32_t *)p + BITOP_WORD((unsigned int)nr); \ + volatile uint32_t *ptr = (volatile uint32_t *)p + \ + BITOP_WORD((unsigned int)nr); \ const uint32_t mask = BITOP_MASK((unsigned int)nr); \ unsigned long res, tmp; \ \ @@ -67,7 +68,8 @@ bool name##_timeout(int nr, volatile void *p, unsigned int max_try) \ static always_inline bool int_##name(int nr, volatile void *p, int *oldbit, \ bool timeout, unsigned int max_try) \ { \ - volatile uint32_t *ptr = (uint32_t *)p + BITOP_WORD((unsigned int)nr); \ + volatile uint32_t *ptr = (volatile uint32_t *)p + \ + BITOP_WORD((unsigned int)nr); \ unsigned int bit = (unsigned int)nr % BITOP_BITS_PER_WORD; \ const uint32_t mask = BITOP_MASK(bit); \ unsigned long res, tmp; \ diff --git a/xen/arch/arm/include/asm/arm64/cmpxchg.h b/xen/arch/arm/include/asm/arm64/cmpxchg.h index dbfaf91567..031fa6d92a 100644 --- a/xen/arch/arm/include/asm/arm64/cmpxchg.h +++ b/xen/arch/arm/include/asm/arm64/cmpxchg.h @@ -13,7 +13,7 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size "1: ldxrb %w0, %2\n" " stlxrb %w1, %w3, %2\n" " cbnz %w1, 1b\n" - : "=&r" (ret), "=&r" (tmp), "+Q" (*(u8 *)ptr) + : "=&r" (ret), "=&r" (tmp), "+Q" (*(volatile u8 *)ptr) : "r" (x) : "memory"); break; @@ -22,7 +22,7 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size "1: ldxrh %w0, %2\n" " stlxrh %w1, %w3, %2\n" " cbnz %w1, 1b\n" - : "=&r" (ret), "=&r" (tmp), "+Q" (*(u16 *)ptr) + : "=&r" (ret), "=&r" (tmp), "+Q" (*(volatile u16 *)ptr) : "r" (x) : "memory"); break; @@ -31,7 +31,7 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size "1: ldxr %w0, %2\n" " stlxr %w1, %w3, %2\n" " cbnz %w1, 1b\n" - : "=&r" (ret), "=&r" (tmp), "+Q" (*(u32 *)ptr) + : "=&r" (ret), "=&r" (tmp), "+Q" (*(volatile u32 *)ptr) : "r" (x) : "memory"); break; @@ -40,7 +40,7 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size "1: ldxr %0, %2\n" " stlxr %w1, %3, %2\n" " cbnz %w1, 1b\n" - : "=&r" (ret), "=&r" (tmp), "+Q" (*(u64 *)ptr) + : "=&r" (ret), "=&r" (tmp), "+Q" (*(volatile u64 *)ptr) : "r" (x) : "memory"); break; @@ -82,7 +82,7 @@ static inline bool __cmpxchg_case_##name(volatile void *ptr, \ " stxr" #sz " %w0, %" #w "4, %2\n" \ "1:\n" \ : "=&r" (res), "=&r" (oldval), \ - "+Q" (*(unsigned long *)ptr) \ + "+Q" (*(volatile unsigned long *)ptr) \ : "Ir" (*old), "r" (new) \ : "cc"); \ \ From patchwork Thu Dec 14 12:07:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simone Ballarin X-Patchwork-Id: 13492949 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 B8BE7C41535 for ; Thu, 14 Dec 2023 12:09:01 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.654522.1021499 (Exim 4.92) (envelope-from ) id 1rDkWI-0001ST-A7; Thu, 14 Dec 2023 12:08:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 654522.1021499; Thu, 14 Dec 2023 12:08:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rDkWI-0001Od-3X; Thu, 14 Dec 2023 12:08:50 +0000 Received: by outflank-mailman (input) for mailman id 654522; Thu, 14 Dec 2023 12:08:48 +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 1rDkWG-0000tI-KV for xen-devel@lists.xenproject.org; Thu, 14 Dec 2023 12:08:48 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 88302c32-9a79-11ee-9b0f-b553b5be7939; Thu, 14 Dec 2023 13:08:46 +0100 (CET) Received: from beta.station (net-37-182-35-120.cust.vodafonedsl.it [37.182.35.120]) by support.bugseng.com (Postfix) with ESMTPSA id B01994EE0742; Thu, 14 Dec 2023 13:08:45 +0100 (CET) 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: 88302c32-9a79-11ee-9b0f-b553b5be7939 From: Simone Ballarin To: xen-devel@lists.xenproject.org Cc: consulting@bugseng.com, Maria Celeste Cesario , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Simone Ballarin Subject: [PATCH 2/9] xen/arm: address violations of MISRA C:2012 Rule 11.8 Date: Thu, 14 Dec 2023 13:07:44 +0100 Message-Id: <1ad7937f9aa2086e76a87c8edf8105bd4476bf39.1702555387.git.maria.celeste.cesario@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 From: Maria Celeste Cesario The xen sources contain violations of MISRA C:2012 Rule 11.8 whose headline states: "A conversion shall not remove any const, volatile or _Atomic qualification from the type pointed to by a pointer". Add missing const qualifiers in casts. The variables are originally const-qualified. There's no reason to drop the qualifiers. No functional change. Signed-off-by: Maria Celeste Cesario Signed-off-by: Simone Ballarin --- xen/arch/arm/bootfdt.c | 6 +++--- xen/arch/arm/include/asm/alternative.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index f496a8cf94..e7948ea3e8 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -377,7 +377,7 @@ static int __init process_chosen_node(const void *fdt, int node, printk("linux,initrd-start property has invalid length %d\n", len); return -EINVAL; } - start = dt_read_paddr((void *)&prop->data, dt_size_to_cells(len)); + start = dt_read_paddr((const void *)&prop->data, dt_size_to_cells(len)); prop = fdt_get_property(fdt, node, "linux,initrd-end", &len); if ( !prop ) @@ -390,7 +390,7 @@ static int __init process_chosen_node(const void *fdt, int node, printk("linux,initrd-end property has invalid length %d\n", len); return -EINVAL; } - end = dt_read_paddr((void *)&prop->data, dt_size_to_cells(len)); + end = dt_read_paddr((const void *)&prop->data, dt_size_to_cells(len)); if ( start >= end ) { @@ -541,7 +541,7 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t paddr) add_boot_module(BOOTMOD_FDT, paddr, fdt_totalsize(fdt), false); - ret = device_tree_for_each_node((void *)fdt, 0, early_scan_node, NULL); + ret = device_tree_for_each_node((const void *)fdt, 0, early_scan_node, NULL); if ( ret ) panic("Early FDT parsing failed (%d)\n", ret); diff --git a/xen/arch/arm/include/asm/alternative.h b/xen/arch/arm/include/asm/alternative.h index d3210e82f9..c7632668b6 100644 --- a/xen/arch/arm/include/asm/alternative.h +++ b/xen/arch/arm/include/asm/alternative.h @@ -20,7 +20,7 @@ struct alt_instr { }; /* Xen: helpers used by common code. */ -#define __ALT_PTR(a,f) ((void *)&(a)->f + (a)->f) +#define __ALT_PTR(a,f) ((const void *)&(a)->f + (a)->f) #define ALT_ORIG_PTR(a) __ALT_PTR(a, orig_offset) #define ALT_REPL_PTR(a) __ALT_PTR(a, repl_offset) From patchwork Thu Dec 14 12:07:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simone Ballarin X-Patchwork-Id: 13492946 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 97A61C4167B for ; Thu, 14 Dec 2023 12:09:01 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.654524.1021515 (Exim 4.92) (envelope-from ) id 1rDkWJ-0001sB-Fj; Thu, 14 Dec 2023 12:08:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 654524.1021515; Thu, 14 Dec 2023 12:08: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 1rDkWJ-0001pJ-BU; Thu, 14 Dec 2023 12:08:51 +0000 Received: by outflank-mailman (input) for mailman id 654524; Thu, 14 Dec 2023 12:08:49 +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 1rDkWH-0000tI-KV for xen-devel@lists.xenproject.org; Thu, 14 Dec 2023 12:08:49 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8880a984-9a79-11ee-9b0f-b553b5be7939; Thu, 14 Dec 2023 13:08:46 +0100 (CET) Received: from beta.station (net-37-182-35-120.cust.vodafonedsl.it [37.182.35.120]) by support.bugseng.com (Postfix) with ESMTPSA id 3360D4EE0747; Thu, 14 Dec 2023 13:08:46 +0100 (CET) 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: 8880a984-9a79-11ee-9b0f-b553b5be7939 From: Simone Ballarin To: xen-devel@lists.xenproject.org Cc: consulting@bugseng.com, Maria Celeste Cesario , Jan Beulich , Andrew Cooper , George Dunlap , Julien Grall , Stefano Stabellini , Wei Liu , Simone Ballarin Subject: [PATCH 3/9] xen/efi: address violations of MISRA C:2012 Rule 11.8 Date: Thu, 14 Dec 2023 13:07:45 +0100 Message-Id: <4540a3850dae951dd6bc4f9b001c9816bde2e49e.1702555387.git.maria.celeste.cesario@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 From: Maria Celeste Cesario The xen sources contain violations of MISRA C:2012 Rule 11.8 whose headline states: "A conversion shall not remove any const, volatile or _Atomic qualification from the type pointed to by a pointer". Add missing const qualifiers in casts. The variables are originally const-qualified. There's no reason to drop the qualifiers. Signed-off-by: Maria Celeste Cesario Signed-off-by: Simone Ballarin Reviewed-by: Jan Beulich Reviewed-by: Stefano Stabellini --- xen/common/efi/boot.c | 6 +++--- xen/common/version.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 6110819918..efbec00af9 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -1248,10 +1248,10 @@ static void __init efi_exit_boot(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *Syste #endif /* Adjust pointers into EFI. */ - efi_ct = (void *)efi_ct + DIRECTMAP_VIRT_START; - efi_rs = (void *)efi_rs + DIRECTMAP_VIRT_START; + efi_ct = (const void *)efi_ct + DIRECTMAP_VIRT_START; + efi_rs = (const void *)efi_rs + DIRECTMAP_VIRT_START; efi_memmap = (void *)efi_memmap + DIRECTMAP_VIRT_START; - efi_fw_vendor = (void *)efi_fw_vendor + DIRECTMAP_VIRT_START; + efi_fw_vendor = (const void *)efi_fw_vendor + DIRECTMAP_VIRT_START; } /* SAF-1-safe */ diff --git a/xen/common/version.c b/xen/common/version.c index d320135208..6ac5a52700 100644 --- a/xen/common/version.c +++ b/xen/common/version.c @@ -178,7 +178,7 @@ void __init xen_build_init(void) if ( &n[1] >= __note_gnu_build_id_end ) return; - sz = (void *)__note_gnu_build_id_end - (void *)n; + sz = (const void *)__note_gnu_build_id_end - (const void *)n; rc = xen_build_id_check(n, sz, &build_id_p, &build_id_len); From patchwork Thu Dec 14 12:07:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simone Ballarin X-Patchwork-Id: 13492954 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 DF79CC46CA2 for ; Thu, 14 Dec 2023 12:09:02 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.654519.1021481 (Exim 4.92) (envelope-from ) id 1rDkWH-00018Q-80; Thu, 14 Dec 2023 12:08:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 654519.1021481; Thu, 14 Dec 2023 12:08:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rDkWH-00018J-4l; Thu, 14 Dec 2023 12:08:49 +0000 Received: by outflank-mailman (input) for mailman id 654519; Thu, 14 Dec 2023 12:08:47 +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 1rDkWF-0000tC-Lc for xen-devel@lists.xenproject.org; Thu, 14 Dec 2023 12:08:47 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 88b622c6-9a79-11ee-98e9-6d05b1d4d9a1; Thu, 14 Dec 2023 13:08:47 +0100 (CET) Received: from beta.station (net-37-182-35-120.cust.vodafonedsl.it [37.182.35.120]) by support.bugseng.com (Postfix) with ESMTPSA id B2FEA4EE0C8A; Thu, 14 Dec 2023 13:08:46 +0100 (CET) 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: 88b622c6-9a79-11ee-98e9-6d05b1d4d9a1 From: Simone Ballarin To: xen-devel@lists.xenproject.org Cc: consulting@bugseng.com, Maria Celeste Cesario , Jan Beulich , Simone Ballarin Subject: [PATCH 4/9] ACPI: address violations of MISRA C:2012 Rule 11.8 Date: Thu, 14 Dec 2023 13:07:46 +0100 Message-Id: <44c8f94bcfe4f0e33e53a7eb8aef826e7d906196.1702555387.git.maria.celeste.cesario@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 From: Maria Celeste Cesario The xen sources contain violations of MISRA C:2012 Rule 11.8 whose headline states: "A conversion shall not remove any const, volatile or _Atomic qualification from the type pointed to by a pointer". Add missing const qualifiers missing in casting. There's no reason to drop the const qualifier in ACPI_COMPARE_NAME since the macro arguments are not modified in its body. Signed-off-by: Maria Celeste Cesario Signed-off-by: Simone Ballarin --- xen/include/acpi/acmacros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/include/acpi/acmacros.h b/xen/include/acpi/acmacros.h index 86c503c20f..d7c74c5769 100644 --- a/xen/include/acpi/acmacros.h +++ b/xen/include/acpi/acmacros.h @@ -116,7 +116,7 @@ #define ACPI_PTR_TO_PHYSADDR(i) ACPI_TO_INTEGER(i) #ifndef ACPI_MISALIGNMENT_NOT_SUPPORTED -#define ACPI_COMPARE_NAME(a,b) (*ACPI_CAST_PTR (u32,(a)) == *ACPI_CAST_PTR (u32,(b))) +#define ACPI_COMPARE_NAME(a,b) (*ACPI_CAST_PTR (const u32,(a)) == *ACPI_CAST_PTR (const u32,(b))) #else #define ACPI_COMPARE_NAME(a,b) (!ACPI_STRNCMP (ACPI_CAST_PTR (char,(a)), ACPI_CAST_PTR (char,(b)), ACPI_NAME_SIZE)) #endif From patchwork Thu Dec 14 12:07:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simone Ballarin X-Patchwork-Id: 13492953 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 7E4B3C46CC6 for ; Thu, 14 Dec 2023 12:09:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.654521.1021493 (Exim 4.92) (envelope-from ) id 1rDkWH-0001Ef-UZ; Thu, 14 Dec 2023 12:08:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 654521.1021493; Thu, 14 Dec 2023 12:08:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rDkWH-0001D0-Jv; Thu, 14 Dec 2023 12:08:49 +0000 Received: by outflank-mailman (input) for mailman id 654521; Thu, 14 Dec 2023 12:08:48 +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 1rDkWG-0000tC-BR for xen-devel@lists.xenproject.org; Thu, 14 Dec 2023 12:08:48 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 88f990b8-9a79-11ee-98e9-6d05b1d4d9a1; Thu, 14 Dec 2023 13:08:47 +0100 (CET) Received: from beta.station (net-37-182-35-120.cust.vodafonedsl.it [37.182.35.120]) by support.bugseng.com (Postfix) with ESMTPSA id 118C74EE0743; Thu, 14 Dec 2023 13:08:47 +0100 (CET) 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: 88f990b8-9a79-11ee-98e9-6d05b1d4d9a1 From: Simone Ballarin To: xen-devel@lists.xenproject.org Cc: consulting@bugseng.com, Maria Celeste Cesario , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Simone Ballarin Subject: [PATCH 5/9] xen/x86: address violations of MISRA C:2012 Rule 11.8 Date: Thu, 14 Dec 2023 13:07:47 +0100 Message-Id: <68e28c7631f1233df1527674cfc27cf3f44797a7.1702555387.git.maria.celeste.cesario@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 From: Maria Celeste Cesario The xen sources contain violations of MISRA C:2012 Rule 11.8 whose headline states: "A conversion shall not remove any const, volatile or _Atomic qualification from the type pointed to by a pointer". Add missing const qualifiers in casts. Macro get_mb2_data returns values that are const-qualified. The results are stored in const struct pointers, hence there's no need to cast away the const qualifiers. Signed-off-by: Maria Celeste Cesario Signed-off-by: Simone Ballarin Acked-by: Jan Beulich Reviewed-by: Stefano Stabellini --- xen/arch/x86/boot/reloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c index df0bc710a7..77fdb2be05 100644 --- a/xen/arch/x86/boot/reloc.c +++ b/xen/arch/x86/boot/reloc.c @@ -300,8 +300,8 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out) const struct vesa_mode_info *mi; video = _p(video_out); - ci = (void *)get_mb2_data(tag, vbe, vbe_control_info); - mi = (void *)get_mb2_data(tag, vbe, vbe_mode_info); + ci = (const void *)get_mb2_data(tag, vbe, vbe_control_info); + mi = (const void *)get_mb2_data(tag, vbe, vbe_mode_info); if ( ci->version >= 0x0200 && (mi->attrib & 0x9b) == 0x9b ) { From patchwork Thu Dec 14 12:07:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simone Ballarin X-Patchwork-Id: 13492948 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 E440BC4167D for ; Thu, 14 Dec 2023 12:09:01 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.654526.1021534 (Exim 4.92) (envelope-from ) id 1rDkWK-0002DQ-U5; Thu, 14 Dec 2023 12:08:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 654526.1021534; Thu, 14 Dec 2023 12:08:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rDkWK-0002Bh-FA; Thu, 14 Dec 2023 12:08:52 +0000 Received: by outflank-mailman (input) for mailman id 654526; Thu, 14 Dec 2023 12:08:50 +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 1rDkWI-0000tI-KY for xen-devel@lists.xenproject.org; Thu, 14 Dec 2023 12:08:50 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 892a5a09-9a79-11ee-9b0f-b553b5be7939; Thu, 14 Dec 2023 13:08:48 +0100 (CET) Received: from beta.station (net-37-182-35-120.cust.vodafonedsl.it [37.182.35.120]) by support.bugseng.com (Postfix) with ESMTPSA id 7D10A4EE0C8F; Thu, 14 Dec 2023 13:08:47 +0100 (CET) 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: 892a5a09-9a79-11ee-9b0f-b553b5be7939 From: Simone Ballarin To: xen-devel@lists.xenproject.org Cc: consulting@bugseng.com, Maria Celeste Cesario , Shawn Anastasio , Simone Ballarin Subject: [PATCH 6/9] xen/ppc: address violations of MISRA C:2012 Rule 11.8. Date: Thu, 14 Dec 2023 13:07:48 +0100 Message-Id: <0dcaf3a85f3293168b993c42303dfd55684a7bb7.1702555387.git.maria.celeste.cesario@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 From: Maria Celeste Cesario The xen sources contain violations of MISRA C:2012 Rule 11.8 whose headline states: "A conversion shall not remove any const, volatile or _Atomic qualification from the type pointed to by a pointer". Fix violation by adding missing const qualifier in cast. Signed-off-by: Maria Celeste Cesario Signed-off-by: Simone Ballarin Reviewed-by: Stefano Stabellini --- Adaptation requested by the community to make the code more consistent. --- xen/arch/ppc/include/asm/atomic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/arch/ppc/include/asm/atomic.h b/xen/arch/ppc/include/asm/atomic.h index 64168aa3f1..fe778579fb 100644 --- a/xen/arch/ppc/include/asm/atomic.h +++ b/xen/arch/ppc/include/asm/atomic.h @@ -16,7 +16,7 @@ static inline int atomic_read(const atomic_t *v) { - return *(volatile int *)&v->counter; + return *(const volatile int *)&v->counter; } static inline int _atomic_read(atomic_t v) From patchwork Thu Dec 14 12:07:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simone Ballarin X-Patchwork-Id: 13492955 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 ACB9EC4167B for ; Thu, 14 Dec 2023 12:09:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.654523.1021507 (Exim 4.92) (envelope-from ) id 1rDkWI-0001Yl-QR; Thu, 14 Dec 2023 12:08:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 654523.1021507; Thu, 14 Dec 2023 12:08:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rDkWI-0001Wq-GK; Thu, 14 Dec 2023 12:08:50 +0000 Received: by outflank-mailman (input) for mailman id 654523; Thu, 14 Dec 2023 12:08:49 +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 1rDkWH-0000tC-BT for xen-devel@lists.xenproject.org; Thu, 14 Dec 2023 12:08:49 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 896fae79-9a79-11ee-98e9-6d05b1d4d9a1; Thu, 14 Dec 2023 13:08:48 +0100 (CET) Received: from beta.station (net-37-182-35-120.cust.vodafonedsl.it [37.182.35.120]) by support.bugseng.com (Postfix) with ESMTPSA id CEBE34EE0C8D; Thu, 14 Dec 2023 13:08:47 +0100 (CET) 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: 896fae79-9a79-11ee-98e9-6d05b1d4d9a1 From: Simone Ballarin To: xen-devel@lists.xenproject.org Cc: consulting@bugseng.com, Maria Celeste Cesario , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Simone Ballarin Subject: [PATCH 7/9] x86/hvm: address violations of MISRA C:2012 Rule 11.8 Date: Thu, 14 Dec 2023 13:07:49 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 From: Maria Celeste Cesario The xen sources contain violations of MISRA C:2012 Rule 11.8 whose headline states: "A conversion shall not remove any const, volatile or _Atomic qualification from the type pointed to by a pointer". Remove unnecessary cast. from is a const-qualified pointer to void and the function hvm_copy_to_guest_linear requires a const void* type argument, therefore the cast to void* is not necessary. No functional change. Signed-off-by: Maria Celeste Cesario Signed-off-by: Simone Ballarin Reviewed-by: Jan Beulich Reviewed-by: Stefano Stabellini --- xen/arch/x86/hvm/hvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 35a30df3b1..523e0df57c 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -3462,7 +3462,7 @@ unsigned int copy_to_user_hvm(void *to, const void *from, unsigned int len) return 0; } - rc = hvm_copy_to_guest_linear((unsigned long)to, (void *)from, len, 0, NULL); + rc = hvm_copy_to_guest_linear((unsigned long)to, from, len, 0, NULL); return rc ? len : 0; /* fake a copy_to_user() return code */ } From patchwork Thu Dec 14 12:07:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simone Ballarin X-Patchwork-Id: 13492951 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 75A24C46CC5 for ; Thu, 14 Dec 2023 12:09:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.654525.1021524 (Exim 4.92) (envelope-from ) id 1rDkWK-00021z-72; Thu, 14 Dec 2023 12:08:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 654525.1021524; Thu, 14 Dec 2023 12:08:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rDkWJ-00020q-Uo; Thu, 14 Dec 2023 12:08:51 +0000 Received: by outflank-mailman (input) for mailman id 654525; Thu, 14 Dec 2023 12:08: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 1rDkWI-0000tC-BU for xen-devel@lists.xenproject.org; Thu, 14 Dec 2023 12:08:50 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 89c53d18-9a79-11ee-98e9-6d05b1d4d9a1; Thu, 14 Dec 2023 13:08:49 +0100 (CET) Received: from beta.station (net-37-182-35-120.cust.vodafonedsl.it [37.182.35.120]) by support.bugseng.com (Postfix) with ESMTPSA id 46A274EE0C81; Thu, 14 Dec 2023 13:08:48 +0100 (CET) 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: 89c53d18-9a79-11ee-98e9-6d05b1d4d9a1 From: Simone Ballarin To: xen-devel@lists.xenproject.org Cc: consulting@bugseng.com, Maria Celeste Cesario , Simone Ballarin , Doug Goldstein , Stefano Stabellini , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Wei Liu Subject: [PATCH 8/9] xen: add deviations for Rule 11.8 Date: Thu, 14 Dec 2023 13:07:50 +0100 Message-Id: <854747a97c4c7a70bfe1a30a038f2cc6aebfb566.1702555387.git.maria.celeste.cesario@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 From: Maria Celeste Cesario The xen sources contain violations of MISRA C:2012 Rule 11.8 whose headline states: "A conversion shall not remove any const, volatile or _Atomic qualification from the type pointed to by a pointer". Deviate use of macro container_of. Deviate use of function ERR_CAST. Signed-off-by: Maria Celeste Cesario Signed-off-by: Simone Ballarin --- container_of: Fixing this violation would require the declaration of a new macro taking advantage of the return value of the ternary operator ?: : its return value preserves qualifiers present on both expression, hence returning void* or qualified void* depending on pointer type, like in this macro: '#define same_constness_void_ptr(ptr) ((typeof((false ? (void*) 1 : (ptr)))) (ptr))' The result could then be used with a Generic to avoid the cast. --- automation/eclair_analysis/ECLAIR/deviations.ecl | 12 ++++++++++++ docs/misra/deviations.rst | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/eclair_analysis/ECLAIR/deviations.ecl index 683f2bbfe8..d3e32a6ac8 100644 --- a/automation/eclair_analysis/ECLAIR/deviations.ecl +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl @@ -292,6 +292,18 @@ constant expressions are required.\"" # Series 11 # +-doc_begin="Violations caused by container_of are due to pointer arithmetic operations +with the provided offset. The resulting pointer is then immediately cast back to its +original type, which preserves the qualifier. This use can be deemed as safe. +Fixing this violation would require to increase code complexity and lower readability." +-config=MC3R1.R11.8,reports+={safe,"any_area(any_loc(any_exp(macro(^container_of$))))"} +-doc_end + +-doc_begin="This function is made to explicitly cast an error-valued pointer to a void +pointer type to make it clear that's what's going on, so the violation is deliberate." +-config=MC3R1.R11.8,reports+={deliberate,"all_area(context(^ERR_CAST\\(.*$))"} +-doc_end + -doc_begin="This construct is used to check if the type is scalar, and for this purpose the use of 0 as a null pointer constant is deliberate." -config=MC3R1.R11.9,reports+={deliberate, "any_area(any_loc(any_exp(macro(^__ACCESS_ONCE$))))" } diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst index eda3c8100c..98733d636d 100644 --- a/docs/misra/deviations.rst +++ b/docs/misra/deviations.rst @@ -248,6 +248,19 @@ Deviations related to MISRA C:2012 Rules: If no bits are set, 0 is returned. - Tagged as `safe` for ECLAIR. + * - R11.8 + - Violations caused by container_of are due to pointer arithmetic operations + with the provided offset. The resulting pointer is then immediately cast back to its + original type, which preserves the qualifier. This use can be deemed as safe. + Fixing this violation would require to increase code complexity and lower readability. + - Tagged as `safe` for ECLAIR. + + * - R11.8 + - This function is made to explicitly cast an error-valued pointer to a + void pointer type to make it clear that's what's going on, so the + violation is deliberate. + - Tagged ad `deliberate` for ECLAIR. + * - R11.9 - __ACCESS_ONCE uses an integer, which happens to be zero, as a compile time check. The typecheck uses a cast. The usage of zero or other From patchwork Thu Dec 14 12:07:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simone Ballarin X-Patchwork-Id: 13492952 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 343B0C46CA3 for ; Thu, 14 Dec 2023 12:09:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.654527.1021550 (Exim 4.92) (envelope-from ) id 1rDkWM-0002ll-E9; Thu, 14 Dec 2023 12:08:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 654527.1021550; Thu, 14 Dec 2023 12:08: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 1rDkWL-0002hP-V2; Thu, 14 Dec 2023 12:08:53 +0000 Received: by outflank-mailman (input) for mailman id 654527; Thu, 14 Dec 2023 12:08:51 +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 1rDkWJ-0000tI-Kj for xen-devel@lists.xenproject.org; Thu, 14 Dec 2023 12:08:51 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8a19fd92-9a79-11ee-9b0f-b553b5be7939; Thu, 14 Dec 2023 13:08:49 +0100 (CET) Received: from beta.station (net-37-182-35-120.cust.vodafonedsl.it [37.182.35.120]) by support.bugseng.com (Postfix) with ESMTPSA id D060B4EE0C91; Thu, 14 Dec 2023 13:08:48 +0100 (CET) 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: 8a19fd92-9a79-11ee-9b0f-b553b5be7939 From: Simone Ballarin To: xen-devel@lists.xenproject.org Cc: consulting@bugseng.com, Maria Celeste Cesario , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Simone Ballarin Subject: [PATCH 9/9] xen: add SAF deviation for safe cast removal. Date: Thu, 14 Dec 2023 13:07:51 +0100 Message-Id: <36e996b864853dba26a9c9fb9c9c674e92cc935e.1702555387.git.maria.celeste.cesario@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 From: Maria Celeste Cesario The xen sources contain violations of MISRA C:2012 Rule 11.8 whose headline states: "A conversion shall not remove any const, volatile or _Atomic qualification from the type pointed to by a pointer". In function __hvm_copy, the const qualifier is cast away to comply with its function signature. There's no modification of the pointee during its execution, therefore its use can be deemed as safe. Signed-off-by: Maria Celeste Cesario Signed-off-by: Simone Ballarin --- docs/misra/safe.json | 8 ++++++++ xen/arch/x86/hvm/hvm.c | 1 + 2 files changed, 9 insertions(+) diff --git a/docs/misra/safe.json b/docs/misra/safe.json index 952324f85c..e748bc6cf5 100644 --- a/docs/misra/safe.json +++ b/docs/misra/safe.json @@ -28,6 +28,14 @@ }, { "id": "SAF-3-safe", + "analyser": { + "eclair": "MC3R1.R11.8" + }, + "name": "MC3R1.R11.8: removal of const qualifier to comply with function signature", + "text": "It is safe to cast away const qualifiers to comply with function signature if the function does not modify the pointee." + }, + { + "id": "SAF-4-safe", "analyser": {}, "name": "Sentinel", "text": "Next ID to be used" diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 523e0df57c..414853254f 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -3413,6 +3413,7 @@ static enum hvm_translation_result __hvm_copy( enum hvm_translation_result hvm_copy_to_guest_phys( paddr_t paddr, const void *buf, unsigned int size, struct vcpu *v) { + /* SAF-3-safe */ return __hvm_copy((void *)buf /* HVMCOPY_to_guest doesn't modify */, paddr, size, v, HVMCOPY_to_guest | HVMCOPY_phys, 0, NULL);