All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simone Ballarin <simone.ballarin@bugseng.com>
To: xen-devel@lists.xenproject.org
Cc: consulting@bugseng.com,
	Maria Celeste Cesario <maria.celeste.cesario@bugseng.com>,
	Simone Ballarin <simone.ballarin@bugseng.com>,
	Doug Goldstein <cardoe@cardoe.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	George Dunlap <george.dunlap@citrix.com>,
	Jan Beulich <jbeulich@suse.com>, Julien Grall <julien@xen.org>,
	Wei Liu <wl@xen.org>
Subject: [PATCH 8/9] xen: add deviations for Rule 11.8
Date: Thu, 14 Dec 2023 13:07:50 +0100	[thread overview]
Message-ID: <854747a97c4c7a70bfe1a30a038f2cc6aebfb566.1702555387.git.maria.celeste.cesario@bugseng.com> (raw)
In-Reply-To: <cover.1702555386.git.maria.celeste.cesario@bugseng.com>

From: Maria Celeste Cesario <maria.celeste.cesario@bugseng.com>

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  <maria.celeste.cesario@bugseng.com>
Signed-off-by: Simone Ballarin  <simone.ballarin@bugseng.com>
---
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
-- 
2.40.0



  parent reply	other threads:[~2023-12-14 12:09 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-14 12:07 [PATCH 0/9] xen: address violations of MISRA C:2012 Rule 11.8 Simone Ballarin
2023-12-14 12:07 ` [PATCH 1/9] xen/arm64: " Simone Ballarin
2023-12-14 21:38   ` Stefano Stabellini
2023-12-14 12:07 ` [PATCH 2/9] xen/arm: " Simone Ballarin
2023-12-14 21:42   ` Stefano Stabellini
2023-12-14 12:07 ` [PATCH 3/9] xen/efi: " Simone Ballarin
2023-12-14 16:32   ` Jan Beulich
2023-12-18 14:32     ` Simone Ballarin
2023-12-14 21:45   ` Stefano Stabellini
2023-12-14 12:07 ` [PATCH 4/9] ACPI: " Simone Ballarin
2023-12-14 16:36   ` Jan Beulich
2023-12-18 15:05     ` Simone Ballarin
2023-12-14 21:49   ` Stefano Stabellini
2023-12-14 12:07 ` [PATCH 5/9] xen/x86: " Simone Ballarin
2023-12-14 16:41   ` Jan Beulich
2023-12-14 21:50   ` Stefano Stabellini
2023-12-14 12:07 ` [PATCH 6/9] xen/ppc: " Simone Ballarin
2023-12-14 21:51   ` Stefano Stabellini
2023-12-14 12:07 ` [PATCH 7/9] x86/hvm: " Simone Ballarin
2023-12-14 16:43   ` Jan Beulich
2023-12-14 21:52   ` Stefano Stabellini
2023-12-14 12:07 ` Simone Ballarin [this message]
2023-12-14 12:46   ` [PATCH 8/9] xen: add deviations for " Jan Beulich
2023-12-14 12:07 ` [PATCH 9/9] xen: add SAF deviation for safe cast removal Simone Ballarin
2023-12-14 16:51   ` Jan Beulich
2023-12-14 22:04     ` Stefano Stabellini
2023-12-15  7:59       ` Jan Beulich
2023-12-15 21:02         ` Stefano Stabellini
2023-12-18  8:18           ` Jan Beulich
2023-12-19  1:23             ` Stefano Stabellini
2023-12-14 12:36 ` [PATCH 0/9] xen: address violations of MISRA C:2012 Rule 11.8 Jan Beulich
2023-12-18 14:28   ` Simone Ballarin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=854747a97c4c7a70bfe1a30a038f2cc6aebfb566.1702555387.git.maria.celeste.cesario@bugseng.com \
    --to=simone.ballarin@bugseng.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=cardoe@cardoe.com \
    --cc=consulting@bugseng.com \
    --cc=george.dunlap@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=maria.celeste.cesario@bugseng.com \
    --cc=sstabellini@kernel.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.