Skip to contentSkip to conversation

selftests/futex: Fix storing address of local variable

PATCH Superseded Ankit Khushwaha 2 participants 3 messages Nov 18, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/futex: Fix storing address of local variable

In child_circular_list() address of local variable ‘struct lock_struct a’ is assigned to head.list.next raising the following warning.

robust_list.c: In function ‘child_circular_list’:
robust_list.c:522:24: warning: storing the address of local variable ‘a’ in ‘head.list.next’ [-Wdangling-pointer=]

  522 |         head.list.next = &a.list;
      |         ~~~~~~~~~~~~~~~^~~~~~~~~

robust_list.c:513:28: note: ‘a’ declared here
513 | struct lock_struct a, b, c;
| ^
robust_list.c:512:40: note: ‘head’ declared here
512 | static struct robust_list_head head;
| ^~~~

Defining the value with static keyword to fix this.

---
 tools/testing/selftests/futex/functional/robust_list.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/futex/functional/robust_list.c +1 -1
index e7d1254e18ca..d1aab1cc5a37 100644
@@ -510,7 +510,7 @@ TEST(test_robust_list_multiple_elements)
 static int child_circular_list(void *arg)
 {
 	static struct robust_list_head head;
-	struct lock_struct a, b, c;
+	static struct lock_struct a, b, c;
 	int ret;
 
 	ret = set_list(&head);

--
2.51.1

#1 lore raw

Em 18/11/2025 13:26, Ankit Khushwaha escreveu:

Quoted 28 lines

In child_circular_list() address of local variable ‘struct lock_struct a’ is assigned to head.list.next raising the following warning.

robust_list.c: In function ‘child_circular_list’:
robust_list.c:522:24: warning: storing the address of local variable ‘a’ in ‘head.list.next’ [-Wdangling-pointer=]

   522 |         head.list.next = &a.list;
       |         ~~~~~~~~~~~~~~~^~~~~~~~~

robust_list.c:513:28: note: ‘a’ declared here
513 | struct lock_struct a, b, c;
| ^
robust_list.c:512:40: note: ‘head’ declared here
512 | static struct robust_list_head head;
| ^~~~

Defining the value with static keyword to fix this.

---
  tools/testing/selftests/futex/functional/robust_list.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/futex/functional/robust_list.c +0 -0
index e7d1254e18ca..d1aab1cc5a37 100644

tools/testing/selftests/futex/functional/robust_list.c TEST(test_robust_list_multiple_elements) · line 513

Quoted 5 lines
tools/testing/selftests/futex/functional/robust_list.c +1 -1
@@ -510,7 +510,7 @@ TEST(test_robust_list_multiple_elements)
  static int child_circular_list(void *arg)
  {
  	static struct robust_list_head head;
-	struct lock_struct a, b, c;
+	static struct lock_struct a, b, c;

I believe that the right fix here would be to drop the static from head declaration, WDYT?

#2 lore raw
Quoted 5 lines · André Almeida
Quoted 5 lines
tools/testing/selftests/futex/functional/robust_list.c +0 -0
index e7d1254e18ca..d1aab1cc5a37 100644
@@ -510,7 +510,7 @@ TEST(test_robust_list_multiple_elements)
Quoted 8 lines

tools/testing/selftests/futex/functional/robust_list.c TEST(test_robust_list_multiple_elements) · line 513

Quoted 5 lines
tools/testing/selftests/futex/functional/robust_list.c +1 -1
  static int child_circular_list(void *arg)
  {
  	static struct robust_list_head head;
-	struct lock_struct a, b, c;
+	static struct lock_struct a, b, c;

I believe that the right fix here would be to drop the static from head declaration, WDYT?

Hi André,
I have tested your suggested changes.
It works fine. will send v2 patch for this.

Thanks,
-- Ankit