Bläddra i källkod

radix-tree: Fix UBSAN warning

get_slot_offset() can be called with a NULL 'parent' argument.
In this case, the calculated value will not be used, but calculating
it is undefined.  Rather than fixing the caller (__radix_tree_delete)
to not call get_slot_offset(), make get_slot_offset() robust against
being called with a NULL parent.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
Matthew Wilcox 7 år sedan
förälder
incheckning
76f070b413
1 ändrade filer med 1 tillägg och 1 borttagningar
  1. 1 1
      lib/radix-tree.c

+ 1 - 1
lib/radix-tree.c

@@ -120,7 +120,7 @@ bool is_sibling_entry(const struct radix_tree_node *parent, void *node)
 static inline unsigned long
 static inline unsigned long
 get_slot_offset(const struct radix_tree_node *parent, void __rcu **slot)
 get_slot_offset(const struct radix_tree_node *parent, void __rcu **slot)
 {
 {
-	return slot - parent->slots;
+	return parent ? slot - parent->slots : 0;
 }
 }
 
 
 static unsigned int radix_tree_descend(const struct radix_tree_node *parent,
 static unsigned int radix_tree_descend(const struct radix_tree_node *parent,