All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] radix-tree: don't left-shift negative values
@ 2025-02-13 14:22 Jan Beulich
  2025-02-13 14:52 ` Nicola Vetrini
  2025-02-13 14:53 ` Andrew Cooper
  0 siblings, 2 replies; 13+ messages in thread
From: Jan Beulich @ 2025-02-13 14:22 UTC (permalink / raw)
  To: xen-devel@lists.xenproject.org
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
	Michal Orzel, Roger Pau Monné, Teddy Astie

Any (signed) integer is okay to pass into radix_tree_int_to_ptr(), yet
left shifting negative values is UB. Use an unsigned intermediate type,
reducing the impact to implementation defined behavior (for the
unsigned->signed conversion).

Also please Misra C:2012 rule 7.3 by dropping the lower case numeric 'l'
tag.

No difference in generated code, at least on x86.

Fixes: b004883e29bb ("Simplify and build-fix (for some gcc versions) radix_tree_int_to_ptr()")
Reported-by: Teddy Astie <teddy.astie@vates.tech>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
Bugseng: Why was the 7.3 violation not spotted by Eclair? According to
         tagging.ecl the codebase is clean for this rule, aiui.

--- a/xen/include/xen/radix-tree.h
+++ b/xen/include/xen/radix-tree.h
@@ -172,7 +172,7 @@ static inline void radix_tree_replace_sl
  */
 static inline void *radix_tree_int_to_ptr(int val)
 {
-    long _ptr = ((long)val << 2) | 0x2l;
+    long _ptr = ((unsigned long)val << 2) | 2;
     ASSERT((_ptr >> 2) == val);
     return (void *)_ptr;
 }


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2025-02-14  7:44 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-13 14:22 [PATCH] radix-tree: don't left-shift negative values Jan Beulich
2025-02-13 14:52 ` Nicola Vetrini
2025-02-13 15:00   ` Andrew Cooper
2025-02-13 15:01   ` Jan Beulich
2025-02-13 15:32     ` Nicola Vetrini
2025-02-13 15:42       ` Nicola Vetrini
2025-02-13 16:39         ` Luca Fancellu
2025-02-13 19:26           ` Stefano Stabellini
2025-02-13 19:39             ` Andrew Cooper
2025-02-13 21:46               ` Stefano Stabellini
2025-02-14  7:44                 ` Jan Beulich
2025-02-14  7:41             ` Jan Beulich
2025-02-13 14:53 ` Andrew Cooper

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.