[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [XEN PATCH] misra: merge the two R14.3 invariant-condition deviations


  • To: Shuaidong Chen <shuaidong.chen@xxxxxxx>
  • From: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
  • Date: Mon, 26 Oct 2026 11:49:22 +0100
  • Arc-authentication-results: i=1; bugseng.com; arc=none smtp.remote-ip=162.55.131.47
  • Arc-message-signature: i=1; d=bugseng.com; s=openarc; a=rsa-sha256; c=relaxed/relaxed; t=1793011762; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:X-Sender:Organization:Content-Type: Content-Transfer-Encoding; bh=pGeqiRbBcJZmwJHs0M8oZ31tUUfyu6RxU8e5//3ky9k=; b=x1VidAV2Z1l+thqyHYEI219K/UX/odTdZrjJiGu+EmVdsg5H35xtLDniI+6DbkJsAk7M wZCYjXLBAcy5WDHapkKnsiM1xAl/eAG2lQyUcfn8jeM+33aasX7KmMnqSeE7p18M/Rfcg p0lbmQH0jv/Zd9rZJhfteuAyihfQZeWGMP7W2aiApSMBsfzdOR8YFGYgVoPaxzfIhwrOC lBoV0B9ibC0jSWaaALOc5Ux4PHkY/J+8ItWmxozlnssWxIpLppPsJXfr0wvcvB57vv/Yd rAgiQnIYfTQ74/vtuHtwgNoqPaLhzJVhlBDGRArbnOPvlWGZ8vVY5fxE+P2/vLFydqlFD +FMFm2H7fGUmlxTbrptpRp2wbCKzvfxJVUYv1mwXyqauff6OTWre1BKHVtpN6hTXuXTzv e0LyKyzHnaDhEeBUTbSGQqkd0Trk94PBzmg9Z9ywoVu1r8Fz/Tt4cTHGAmNzblsVB+oiO vGW8ajZDmt2AxhmdnM+3+D79s16OlVp8l5xgExjDc1mEm/PSxoNAeegreVIffx2+COstY znEaRmgCA0BfA5F5Fd9TRh8UvHRKj5Uq1Rtzlpq1KKzcI3wd7cgAox/XZeecwDpv/sTen V+lmuB1Emhu+hOMbXnL7+jiqhUweVLkS/CDJmQ/dVJUgDH02zUoDturtTKZ4KzE=
  • Arc-seal: i=1; d=bugseng.com; s=openarc; a=rsa-sha256; cv=none; t=1793011762; b=FC9yYpFOo78Hl/+J7mOA3jW+Zj+B7TXPM7Lup9BVz8Xq3ltJpQoFC/LOhPGGbiTfH0X7 blENp7g4WMyfgEwb45ZpWEacjBwhv3vptBnSn2OJDJdK+tGMV9He4lNS/g6mlgJuG74Cn o0ueBWTv1AANHigYp2MW0MQ30t5ZTDTl+rmFH9QV7Intfo0OGyehax/6FVerXhaIxSbgi 89fzmRQ5sOJZ9PBiAmWFqvojbO/g34LmQeGUDDvocetKPWF/jAr6OSTcyZuuizSSSN5Mp OolmHnHOqbajvBZEjSU+BOKTMC/BJOC/cfdZWf6nO9E3GKNmRefBHOuaMqD8ch5xDLf4X aEIUHAhMtcGK25FTabIDvjjusmqASK5r3IuW+RC8cODeLOHJ7kbEYPg6fzbFk2qpTD2EJ Q9qSzobqQOwaf8GrTEd+gxCuiuk/Zq+Fum712Q8P7PLVke2cCHh7iitEAwbIhtxeQdkKk hpycTADNPzh5pjjpOuU1Q2DAIlMMlq5kFwy2SSDYPGtpCCj8WFsy5Ppdzl+m7ahE0Krfj 7uRXuV9PWJeC3aKs7Dz6q2tt74LiIONpghHglHQ4J6V0iWvJqGtMyfy9AkJtGJ1ojQaU5 g67goTrNkhliBiTnmyilmKZjKUAMyoIr0rxLhxBYklu4nZp+O3mfvMXSaqs7TFM=
  • Authentication-results: eu.smtp.expurgate.cloud; none
  • Authentication-results: bugseng.com; arc=none smtp.remote-ip=162.55.131.47
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Doug Goldstein <cardoe@xxxxxxxxxx>, Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>, Grygorii Strashko <grygorii_strashko@xxxxxxxx>, Penny Zheng <penny.zheng@xxxxxxx>, Ray Huang <Ray.Huang@xxxxxxx>
  • Delivery-date: Mon, 26 Oct 2026 10:49:30 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 2026-10-26 04:03, Shuaidong Chen wrote:
MC3A2.R14.3 ("Controlling expressions shall not be invariant") is
deviated by two separate entries.  One covers 'if' statements and
conditional operators and places no restriction on where the invariant
condition comes from.  The other covers 'switch' statements, but only
when the controlling expression is a 'sizeof' operator.

The rationale recorded for the two is the same: the condition is
deliberate.  Nothing about a 'switch' makes an invariant condition less
deliberate than the same condition in an 'if', so the 'sizeof'
restriction reads as an artefact of that entry having been added for
read_atomic() and friends in arch/x86/include/asm/atomic.h rather than
as a considered limit.

Fold switch_stmt into the general entry and drop the 'sizeof'-restricted
one, which the general predicate now subsumes.  Invariant 'switch'
conditions that are not a 'sizeof' become deliberate as a result; that
is the intent.

Signed-off-by: Shuaidong Chen <shuaidong.chen@xxxxxxx>

Assuming maintainers are ok with this relaxation:

Acked-by: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>

---
 automation/eclair_analysis/ECLAIR/deviations.ecl | 8 ++------
 docs/misra/deviations.rst                        | 8 ++------
 2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/eclair_analysis/ECLAIR/deviations.ecl
index 7f3fd35a33d..08a88ddfa62 100644
--- a/automation/eclair_analysis/ECLAIR/deviations.ecl
+++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
@@ -472,12 +472,8 @@ activity."
 -config=MC3A2.R14.2,reports+={disapplied,"any()"}
 -doc_end

--doc_begin="The XEN team relies on the fact that invariant conditions of 'if' statements and conditional operators are deliberate" --config=MC3A2.R14.3,statements+={deliberate, "wrapped(any(),node(if_stmt||conditional_operator||binary_conditional_operator))" }
--doc_end
-
--doc_begin="Switches having a 'sizeof' operator as the condition are deliberate and have limited scope." --config=MC3A2.R14.3,statements+={deliberate, "wrapped(any(),node(switch_stmt)&&child(cond, operator(sizeof)))" } +-doc_begin="The XEN team relies on the fact that invariant conditions of 'if' statements, conditional operators and 'switch' statements are deliberate" +-config=MC3A2.R14.3,statements+={deliberate, "wrapped(any(),node(if_stmt||conditional_operator||binary_conditional_operator||switch_stmt))" }
 -doc_end

-doc_begin="The use of an invariant size argument in {put,get}_unsafe_size and array_access_ok, as defined in arch/x86(_64)?/include/asm/uaccess.h is deliberate and is deemed safe."
diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst
index 32713172067..99a1b2332c2 100644
--- a/docs/misra/deviations.rst
+++ b/docs/misra/deviations.rst
@@ -458,12 +458,8 @@ Deviations related to MISRA C:2012 Rules:

    * - R14.3
- The Xen team relies on the fact that invariant conditions of 'if'
-       statements and conditional operators are deliberate.
-     - Tagged as `deliberate` for ECLAIR.
-
-   * - R14.3
- - Switches having a 'sizeof' operator as the condition are deliberate and
-       have limited scope.
+       statements, conditional operators and 'switch' statements are
+       deliberate.
      - Tagged as `deliberate` for ECLAIR.

    * - R14.3

--
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.