diff mbox series

net: unix: Fix undefined 'other' error

Message ID 20250209184355.16257-1-purvayeshi550@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: unix: Fix undefined 'other' error | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: kuniyu@amazon.com
netdev/build_clang success Errors and warnings before: 2 this patch: 2
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 4 this patch: 9
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 11 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Purva Yeshi Feb. 9, 2025, 6:43 p.m. UTC
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.

Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
---
 net/unix/af_unix.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Kuniyuki Iwashima Feb. 10, 2025, 12:26 a.m. UTC | #1
> [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 <purvayeshi550@gmail.com>
Date: Mon, 10 Feb 2025 00:13:55 +0530
> 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.


> 
> Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
> ---
>  net/unix/af_unix.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
> index 34945de1f..37b01605a 100644
> --- a/net/unix/af_unix.c
> +++ b/net/unix/af_unix.c
> @@ -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;
> -- 
> 2.34.1
Purva Yeshi Feb. 10, 2025, 7:45 a.m. UTC | #2
On 10/02/25 05:56, Kuniyuki Iwashima wrote:
> 
>> [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 <purvayeshi550@gmail.com>
> Date: Mon, 10 Feb 2025 00:13:55 +0530
>> 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.

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

> 
> 
>>
>> Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
>> ---
>>   net/unix/af_unix.c | 5 ++++-
>>   1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
>> index 34945de1f..37b01605a 100644
>> --- a/net/unix/af_unix.c
>> +++ b/net/unix/af_unix.c
>> @@ -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;
>> -- 
>> 2.34.1
diff mbox series

Patch

diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 34945de1f..37b01605a 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -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;