Skip to contentSkip to conversation

XArray: Fix xa_to_node by adding xa_is_node

PATCH In review Jiasheng Jiang 2 participants 2 messages Oct 12, 2021 – Oct 18, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 XArray: Fix xa_to_node by adding xa_is_node

Directly using xa_to_node may lead to the compulsory type conversion of unknown type,which is unsafe.
So it might be better that adding xa_is_node before.

Fixes 58d6ea3 ("xarray: Add XArray unconditional store operations")
---
 lib/test_xarray.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/test_xarray.c +4 -2
index 8b1c318..7ad3d51 100644
@@ -606,8 +606,10 @@ static noinline void check_multi_store(struct xarray *xa)
 	XA_BUG_ON(xa, xa_load(xa, 1) != xa_mk_value(0));
 	XA_BUG_ON(xa, xa_load(xa, 2) != NULL);
 	rcu_read_lock();
-	XA_BUG_ON(xa, xa_to_node(xa_head(xa))->count != 2);
-	XA_BUG_ON(xa, xa_to_node(xa_head(xa))->nr_values != 2);
+	if (xa_is_node(xa_head(xa))) {
+		XA_BUG_ON(xa, xa_to_node(xa_head(xa))->count != 2);
+		XA_BUG_ON(xa, xa_to_node(xa_head(xa))->nr_values != 2);
+	}
 	rcu_read_unlock();
 
 	/* Storing adjacent to the value does not alter the value */
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 3 lines · Jiasheng Jiang

Directly using xa_to_node may lead to the compulsory type conversion of unknown type,which is unsafe.
So it might be better that adding xa_is_node before.

No. This is test code, and it knows what it's doing.
I suppose we could add an XA_BUG_ON(xa, !xa_is_node(xa_head(xa))); but that seems pointless. This patch is definitely wrong.

Quoted 26 lines
Fixes 58d6ea3 ("xarray: Add XArray unconditional store operations")
---
 lib/test_xarray.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/test_xarray.c +4 -2
index 8b1c318..7ad3d51 100644
@@ -606,8 +606,10 @@ static noinline void check_multi_store(struct xarray *xa)
 	XA_BUG_ON(xa, xa_load(xa, 1) != xa_mk_value(0));
 	XA_BUG_ON(xa, xa_load(xa, 2) != NULL);
 	rcu_read_lock();
-	XA_BUG_ON(xa, xa_to_node(xa_head(xa))->count != 2);
-	XA_BUG_ON(xa, xa_to_node(xa_head(xa))->nr_values != 2);
+	if (xa_is_node(xa_head(xa))) {
+		XA_BUG_ON(xa, xa_to_node(xa_head(xa))->count != 2);
+		XA_BUG_ON(xa, xa_to_node(xa_head(xa))->nr_values != 2);
+	}
 	rcu_read_unlock();
 
 	/* Storing adjacent to the value does not alter the value */
Signature · 1 line
2.7.4