Skip to contentSkip to conversation

x86/bitops and MISRA C:2012 Rule 5.5

DISCUSSION Federico Serafini 2 participants 3 messages Mar 15, 2024

lore
Share & tools
lore
#0 lore raw

Hello everyone,

there are violations of Rule 5.5 ("Identifiers shall be distinct from macro names") in xen/arch/x86/include/asm/bitops.h. You can see them at [1].

Do you agree to distinguish between function-like macros and inline functions by adding a suffix to the functions? I thought about "_unsafe" or "_nocheck" suffixes. As an example:

@@ -32,14 +32,14 @@ extern void __bitop_bad_size(void);
* Note that @nr may be almost arbitrarily large; this function is not
* restricted to acting on a single-word quantity.
*/
-static inline void set_bit(int nr, volatile void *addr) +static inline void set_bit_unsafe(int nr, volatile void *addr)

 {
     asm volatile ( "lock; btsl %1,%0"
                    : "+m" (ADDR) : "Ir" (nr) : "memory");
 }
 #define set_bit(nr, addr) ({                            \
     if ( bitop_bad_size(addr) ) __bitop_bad_size();     \
-    set_bit(nr, addr);                                  \
+    set_bit_unsafe(nr, addr);                           \

})

[1]
https://saas.eclairit.com:3787/fs/var/local/eclair/XEN.ecdf/ECLAIR_normal/staging/X86_64-BUGSENG/575/PROJECT.ecd;/by_service/MC3R1.R5.5.html#{"select":true,"selection":{"hiddenAreaKinds":[],"hiddenSubareaKinds":[],"show":true,"selector":{"enabled":true,"negated":false,"kind":2,"children":[{"enabled":true,"negated":false,"kind":0,"domain":"file","inputs":[{"enabled":true,"text":"xen/arch/x86/include/asm/bitops.h"}]}]}}}

Signature · 3 lines
Federico Serafini, M.Sc.

Software Engineer, BUGSENG (http://bugseng.com)
#1 lore raw
Quoted 8 lines · Federico Serafini

Hello everyone,

there are violations of Rule 5.5 ("Identifiers shall be distinct from macro names") in xen/arch/x86/include/asm/bitops.h. You can see them at [1].

Do you agree to distinguish between function-like macros and inline functions by adding a suffix to the functions?

Please see the other bitops thread, which you're also CC'd on.

Although it's not got to these functions yet, this is going to be fixed by having set_bit() be common, and arch_set_bit() be the per-arch implemenation.

Neither _unsafe nor _nocheck are remotely appropriate here.

~Andrew

#2 lore raw
Quoted 10 lines · Andrew Cooper
Quoted 8 lines · Federico Serafini

Hello everyone,

there are violations of Rule 5.5 ("Identifiers shall be distinct from macro names") in xen/arch/x86/include/asm/bitops.h. You can see them at [1].

Do you agree to distinguish between function-like macros and inline functions by adding a suffix to the functions?

Quoted 7 lines

Please see the other bitops thread, which you're also CC'd on.

Although it's not got to these functions yet, this is going to be fixed by having set_bit() be common, and arch_set_bit() be the per-arch implemenation.

Neither _unsafe nor _nocheck are remotely appropriate here.

Thanks, I missed it.

Signature · 3 lines
Federico Serafini, M.Sc.

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