Skip to contentSkip to conversation

automation/eclair: add deviation for MISRA C:2012 Rule 16.3

PATCH In review Federico Serafini 2 participants 7 messages Feb 19, 2024 – Feb 20, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 automation/eclair: add deviation for MISRA C:2012 Rule 16.3

Update ECLAIR configuration to consider safe switch clauses ending with __{get,put}_user_bad().

Update docs/misra/deviations.rst accordingly.

---
 automation/eclair_analysis/ECLAIR/deviations.ecl | 4 ++++
 docs/misra/deviations.rst                        | 6 ++++++
 2 files changed, 10 insertions(+)
automation/eclair_analysis/ECLAIR/deviations.ecl +4 -0
index fd32ff8a9c..831b5d4c67 100644
@@ -368,6 +368,10 @@ safe."
 -config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(/BUG\\(\\);/))))"}
 -doc_end
 
+-doc_begin="Switch clauses ending with constructs \"__get_user_bad()\" and \"__put_user_bad()\" are safe: they denote an unreachable program point."
+-config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(/__(put|get)_user_bad\\(\\);/))))"}
+-doc_end
+
 -doc_begin="Switch clauses not ending with the break statement are safe if an
 explicit comment indicating the fallthrough intention is present."
 -config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(^(?s).*/\\* [fF]all ?through.? \\*/.*$,0..1))))"}
docs/misra/deviations.rst +6 -0
index 123c78e20a..58f4fac18e 100644
@@ -307,6 +307,12 @@ Deviations related to MISRA C:2012 Rules:
      - Switch clauses ending with failure method \"BUG()\" are safe.
      - Tagged as `safe` for ECLAIR.
 
+   * - R16.3
+     - Switch clauses ending with constructs
+       \"__get_user_bad()\" and \"__put_user_bad()\" are safe:
+       they denote an unreachable program point.
+     - Tagged as `safe` for ECLAIR.
+
    * - R16.3
      - Existing switch clauses not ending with the break statement are safe if
        an explicit comment indicating the fallthrough intention is present.
Signature · 1 line
2.34.1
#1 lore raw
Quoted 6 lines · Federico Serafini

Update ECLAIR configuration to consider safe switch clauses ending with __{get,put}_user_bad().

Update docs/misra/deviations.rst accordingly.

As mentioned I'm not happy with this, not the least because of it being unclear why these two would be deviated, when there's no sign of a similar deviation for, say, __bad_atomic_size(). Imo this approach doesn't scale, and that's already leaving aside that the purpose of identically named (pseudo-)helpers could differ between architectures, thus putting under question ...

automation/eclair_analysis/ECLAIR/deviations.ecl safe." · line 373

Quoted 9 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +3 -0
@@ -368,6 +368,10 @@ safe."
 -config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(/BUG\\(\\);/))))"}
 -doc_end
 
+-doc_begin="Switch clauses ending with constructs \"__get_user_bad()\" and \"__put_user_bad()\" are safe: they denote an unreachable program point."
+-config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(/__(put|get)_user_bad\\(\\);/))))"}
+-doc_end

... the global scope of such a deviation. While it may not be a good idea, even within an arch such (pseudo-)helpers could be used for multiple distinct purposes.

Jan

#2 lore raw
Quoted 21 lines · Jan Beulich
Quoted 6 lines · Federico Serafini

Update ECLAIR configuration to consider safe switch clauses ending with __{get,put}_user_bad().

Update docs/misra/deviations.rst accordingly.

As mentioned I'm not happy with this, not the least because of it being unclear why these two would be deviated, when there's no sign of a similar deviation for, say, __bad_atomic_size(). Imo this approach doesn't scale, and that's already leaving aside that the purpose of identically named (pseudo-)helpers could differ between architectures, thus putting under question ...

Quoted 6 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +0 -0
@@ -368,6 +368,10 @@ safe."
  -config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(/BUG\\(\\);/))))"}
  -doc_end
 
Quoted 7 lines

automation/eclair_analysis/ECLAIR/deviations.ecl safe." · line 373

Quoted 3 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +3 -0
+-doc_begin="Switch clauses ending with constructs \"__get_user_bad()\" and \"__put_user_bad()\" are safe: they denote an unreachable program point."
+-config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(/__(put|get)_user_bad\\(\\);/))))"}
+-doc_end

... the global scope of such a deviation. While it may not be a good idea, even within an arch such (pseudo-)helpers could be used for multiple distinct purposes.

Would you agree with adding the missing break statement after the uses of __{put,get}_user_bad() (as it is already happening for uses of __bad_atomic_size())?

Signature · 3 lines
Federico Serafini, M.Sc.

Software Engineer, BUGSENG (http://bugseng.com)
#3 lore raw
Quoted 30 lines · Federico Serafini
Quoted 21 lines · Jan Beulich
Quoted 6 lines · Federico Serafini

Update ECLAIR configuration to consider safe switch clauses ending with __{get,put}_user_bad().

Update docs/misra/deviations.rst accordingly.

As mentioned I'm not happy with this, not the least because of it being unclear why these two would be deviated, when there's no sign of a similar deviation for, say, __bad_atomic_size(). Imo this approach doesn't scale, and that's already leaving aside that the purpose of identically named (pseudo-)helpers could differ between architectures, thus putting under question ...

Quoted 6 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +0 -0
@@ -368,6 +368,10 @@ safe."
  -config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(/BUG\\(\\);/))))"}
  -doc_end
 
Quoted 7 lines

automation/eclair_analysis/ECLAIR/deviations.ecl safe." · line 373

Quoted 3 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +3 -0
+-doc_begin="Switch clauses ending with constructs \"__get_user_bad()\" and \"__put_user_bad()\" are safe: they denote an unreachable program point."
+-config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(/__(put|get)_user_bad\\(\\);/))))"}
+-doc_end

... the global scope of such a deviation. While it may not be a good idea, even within an arch such (pseudo-)helpers could be used for multiple distinct purposes.

Quoted 3 lines

Would you agree with adding the missing break statement after the uses of __{put,get}_user_bad() (as it is already happening for uses of __bad_atomic_size())?

I probably wouldn't mind that (despite being a little pointless). Perhaps declaring them as noreturn would also help?

Jan

#4 lore raw
Quoted 31 lines · Jan Beulich
Quoted 30 lines · Federico Serafini
Quoted 28 lines · Jan Beulich
Quoted 6 lines · Federico Serafini

Update ECLAIR configuration to consider safe switch clauses ending with __{get,put}_user_bad().

Update docs/misra/deviations.rst accordingly.

As mentioned I'm not happy with this, not the least because of it being unclear why these two would be deviated, when there's no sign of a similar deviation for, say, __bad_atomic_size(). Imo this approach doesn't scale, and that's already leaving aside that the purpose of identically named (pseudo-)helpers could differ between architectures, thus putting under question ...

automation/eclair_analysis/ECLAIR/deviations.ecl safe." · line 373

Quoted 9 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +3 -0
@@ -368,6 +368,10 @@ safe."
   -config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(/BUG\\(\\);/))))"}
   -doc_end
 
+-doc_begin="Switch clauses ending with constructs \"__get_user_bad()\" and \"__put_user_bad()\" are safe: they denote an unreachable program point."
+-config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(/__(put|get)_user_bad\\(\\);/))))"}
+-doc_end

... the global scope of such a deviation. While it may not be a good idea, even within an arch such (pseudo-)helpers could be used for multiple distinct purposes.

Quoted 6 lines
Quoted 3 lines

Would you agree with adding the missing break statement after the uses of __{put,get}_user_bad() (as it is already happening for uses of __bad_atomic_size())?

I probably wouldn't mind that (despite being a little pointless). Perhaps declaring them as noreturn would also help?

Yes, it will help.
Is there any reason to have long as __get_user_bad()'s return value? It would be nicer to declare it as a void function and then add the noreturn attribute.

Signature · 3 lines
Federico Serafini, M.Sc.

Software Engineer, BUGSENG (http://bugseng.com)
#5 lore raw
Quoted 36 lines · Federico Serafini
Quoted 35 lines · Jan Beulich
Quoted 33 lines · Federico Serafini
Quoted 21 lines · Jan Beulich
Quoted 6 lines · Federico Serafini

Update ECLAIR configuration to consider safe switch clauses ending with __{get,put}_user_bad().

Update docs/misra/deviations.rst accordingly.

As mentioned I'm not happy with this, not the least because of it being unclear why these two would be deviated, when there's no sign of a similar deviation for, say, __bad_atomic_size(). Imo this approach doesn't scale, and that's already leaving aside that the purpose of identically named (pseudo-)helpers could differ between architectures, thus putting under question ...

Quoted 6 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +0 -0
@@ -368,6 +368,10 @@ safe."
   -config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(/BUG\\(\\);/))))"}
   -doc_end
 
Quoted 7 lines

automation/eclair_analysis/ECLAIR/deviations.ecl safe." · line 373

Quoted 3 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +3 -0
+-doc_begin="Switch clauses ending with constructs \"__get_user_bad()\" and \"__put_user_bad()\" are safe: they denote an unreachable program point."
+-config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(/__(put|get)_user_bad\\(\\);/))))"}
+-doc_end

... the global scope of such a deviation. While it may not be a good idea, even within an arch such (pseudo-)helpers could be used for multiple distinct purposes.

Would you agree with adding the missing break statement after the uses of __{put,get}_user_bad() (as it is already happening for uses of __bad_atomic_size())?

Quoted 7 lines
Quoted 2 lines

I probably wouldn't mind that (despite being a little pointless). Perhaps declaring them as noreturn would also help?

Yes, it will help.
Is there any reason to have long as __get_user_bad()'s return value? It would be nicer to declare it as a void function and then add the noreturn attribute.

That's a historical leftover, which can be changed. Xen originally derived quite a bit of code from Linux. If you go look at Linux 2.6.16, you'll find why it was declared that way.

Jan

#6 lore raw
Quoted 40 lines · Jan Beulich
Quoted 39 lines · Federico Serafini
Quoted 37 lines · Jan Beulich
Quoted 30 lines · Federico Serafini
Quoted 21 lines · Jan Beulich
Quoted 6 lines · Federico Serafini

Update ECLAIR configuration to consider safe switch clauses ending with __{get,put}_user_bad().

Update docs/misra/deviations.rst accordingly.

As mentioned I'm not happy with this, not the least because of it being unclear why these two would be deviated, when there's no sign of a similar deviation for, say, __bad_atomic_size(). Imo this approach doesn't scale, and that's already leaving aside that the purpose of identically named (pseudo-)helpers could differ between architectures, thus putting under question ...

Quoted 6 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +0 -0
@@ -368,6 +368,10 @@ safe."
    -config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(/BUG\\(\\);/))))"}
    -doc_end
 
Quoted 7 lines

automation/eclair_analysis/ECLAIR/deviations.ecl safe." · line 373

Quoted 3 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +3 -0
+-doc_begin="Switch clauses ending with constructs \"__get_user_bad()\" and \"__put_user_bad()\" are safe: they denote an unreachable program point."
+-config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(/__(put|get)_user_bad\\(\\);/))))"}
+-doc_end

... the global scope of such a deviation. While it may not be a good idea, even within an arch such (pseudo-)helpers could be used for multiple distinct purposes.

Quoted 3 lines

Would you agree with adding the missing break statement after the uses of __{put,get}_user_bad() (as it is already happening for uses of __bad_atomic_size())?

I probably wouldn't mind that (despite being a little pointless). Perhaps declaring them as noreturn would also help?

Quoted 8 lines
Quoted 4 lines

Yes, it will help.
Is there any reason to have long as __get_user_bad()'s return value? It would be nicer to declare it as a void function and then add the noreturn attribute.

That's a historical leftover, which can be changed. Xen originally derived quite a bit of code from Linux. If you go look at Linux 2.6.16, you'll find why it was declared that way.

Thank you, I'll send a v2.

Signature · 3 lines
Federico Serafini, M.Sc.

Software Engineer, BUGSENG (http://bugseng.com)