Skip to contentSkip to conversation

net: unix: Fix undefined 'other' error

PATCH In review Purva Yeshi 2 participants 3 messages Feb 9, 2025 – Feb 10, 2025

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

PATCH 1/1 net: unix: Fix undefined 'other' error

Fix issue detected by smatch tool:
An "undefined 'other'" error occur in __releases() annotation.

The issue occurs because __releases(&unix_sk(other)->lock) is placed at the function signature level, where other is not yet in scope.

Fix this by replacing it with __releases(&u->lock), using u, a local variable, which is properly defined inside the function.

---
 net/unix/af_unix.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/unix/af_unix.c +4 -1
index 34945de1f..37b01605a 100644
@@ -1508,7 +1508,10 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
 }
 
 static long unix_wait_for_peer(struct sock *other, long timeo)
-	__releases(&unix_sk(other)->lock)
+	/*
+	 * Use local variable instead of function parameter
+	 */
+	__releases(&u->lock)
 {
 	struct unix_sock *u = unix_sk(other);
 	int sched;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 2 lines

[PATCH] net: unix: Fix undefined 'other' error

Please add net-next after PATCH and start with af_unix: as with other commits when you post v2.

[PATCH net-next v2]: af_unix: ...

From: Purva Yeshi <[email protected]>
Date: Mon, 10 Feb 2025 00:13:55 +0530

Quoted 8 lines

Fix issue detected by smatch tool:
An "undefined 'other'" error occur in __releases() annotation.

The issue occurs because __releases(&unix_sk(other)->lock) is placed at the function signature level, where other is not yet in scope.

Fix this by replacing it with __releases(&u->lock), using u, a local variable, which is properly defined inside the function.

Tweaking an annotation with a comment for a static analyzer to fix a warning for yet another static analyzer is too much.

Please remove sparse annotation instead.

Here's the only place where sparse is used in AF_UNIX code, and we don't use sparse even for /proc/net/unix.

Quoted 24 lines
---
 net/unix/af_unix.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/unix/af_unix.c +4 -1
index 34945de1f..37b01605a 100644
@@ -1508,7 +1508,10 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
 }
 
 static long unix_wait_for_peer(struct sock *other, long timeo)
-	__releases(&unix_sk(other)->lock)
+	/*
+	 * Use local variable instead of function parameter
+	 */
+	__releases(&u->lock)
 {
 	struct unix_sock *u = unix_sk(other);
 	int sched;
Signature · 1 line
2.34.1
#2 lore raw
Quoted 20 lines · Kuniyuki Iwashima
Quoted 2 lines

[PATCH] net: unix: Fix undefined 'other' error

Please add net-next after PATCH and start with af_unix: as with other commits when you post v2.

[PATCH net-next v2]: af_unix: ...

From: Purva Yeshi <[email protected]>
Date: Mon, 10 Feb 2025 00:13:55 +0530

Quoted 8 lines

Fix issue detected by smatch tool:
An "undefined 'other'" error occur in __releases() annotation.

The issue occurs because __releases(&unix_sk(other)->lock) is placed at the function signature level, where other is not yet in scope.

Fix this by replacing it with __releases(&u->lock), using u, a local variable, which is properly defined inside the function.

Quoted 7 lines

Tweaking an annotation with a comment for a static analyzer to fix a warning for yet another static analyzer is too much.

Please remove sparse annotation instead.

Here's the only place where sparse is used in AF_UNIX code, and we don't use sparse even for /proc/net/unix.

Thank you for the feedback. As per your suggestion, I have removed the Sparse annotation instead of modifying it. I have updated the patch accordingly and will send v2 with the corrected subject line and commit message.

Best regards,
Purva Yeshi

Quoted 26 lines
Quoted 26 lines
---
  net/unix/af_unix.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
net/unix/af_unix.c +4 -1
index 34945de1f..37b01605a 100644
@@ -1508,7 +1508,10 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
  }
 
  static long unix_wait_for_peer(struct sock *other, long timeo)
-	__releases(&unix_sk(other)->lock)
+	/*
+	 * Use local variable instead of function parameter
+	 */
+	__releases(&u->lock)
  {
  	struct unix_sock *u = unix_sk(other);
  	int sched;
Signature · 1 line
2.34.1