diff mbox series

[wireless] wifi: ath10k: Fix an error code problem in ath10k_dbg_sta_write_peer_debug_trigger()

Message ID 20240417081736.2226586-1-suhui@nfschina.com (mailing list archive)
State Changes Requested
Delegated to: Kalle Valo
Headers show
Series [wireless] wifi: ath10k: Fix an error code problem in ath10k_dbg_sta_write_peer_debug_trigger() | expand

Commit Message

Su Hui April 17, 2024, 8:17 a.m. UTC
Clang Static Checker (scan-build) Warning:
drivers/net/wireless/ath/ath10k/debugfs_sta.c:line 429, column 3
Value stored to 'ret' is never read.

Return 'ret' rather than 'count' when 'ret' stores an error code.
By the way, remove some useless code.

Fixes: ee8b08a1be82 ("ath10k: add debugfs support to get per peer tids log via tracing")
Signed-off-by: Su Hui <suhui@nfschina.com>
---
 drivers/net/wireless/ath/ath10k/debugfs_sta.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Jeff Johnson April 19, 2024, 3:09 p.m. UTC | #1
On 4/17/2024 1:17 AM, Su Hui wrote:
> Clang Static Checker (scan-build) Warning:
> drivers/net/wireless/ath/ath10k/debugfs_sta.c:line 429, column 3
> Value stored to 'ret' is never read.
> 
> Return 'ret' rather than 'count' when 'ret' stores an error code.
> By the way, remove some useless code.
> 
> Fixes: ee8b08a1be82 ("ath10k: add debugfs support to get per peer tids log via tracing")
> Signed-off-by: Su Hui <suhui@nfschina.com>
> ---
>  drivers/net/wireless/ath/ath10k/debugfs_sta.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/wireless/ath/ath10k/debugfs_sta.c b/drivers/net/wireless/ath/ath10k/debugfs_sta.c
> index 394bf3c32abf..5525dabe390a 100644
> --- a/drivers/net/wireless/ath/ath10k/debugfs_sta.c
> +++ b/drivers/net/wireless/ath/ath10k/debugfs_sta.c
> @@ -415,7 +415,7 @@ ath10k_dbg_sta_write_peer_debug_trigger(struct file *file,
>  	struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
>  	struct ath10k *ar = arsta->arvif->ar;
>  	u8 peer_debug_trigger;
> -	int ret;
> +	int ret = 0;

this is unnecessary since this will be written in all paths that lead to the
return that reads it

>  
>  	if (kstrtou8_from_user(user_buf, count, 0, &peer_debug_trigger))
>  		return -EINVAL;
> @@ -432,14 +432,12 @@ ath10k_dbg_sta_write_peer_debug_trigger(struct file *file,
>  
>  	ret = ath10k_wmi_peer_set_param(ar, arsta->arvif->vdev_id, sta->addr,
>  					ar->wmi.peer_param->debug, peer_debug_trigger);
> -	if (ret) {
> +	if (ret)
>  		ath10k_warn(ar, "failed to set param to trigger peer tid logs for station ret: %d\n",
>  			    ret);
> -		goto out;
> -	}
>  out:
>  	mutex_unlock(&ar->conf_mutex);
> -	return count;
> +	return ret ?: count;
>  }
>  
>  static const struct file_operations fops_peer_debug_trigger = {

I'd suggest as an alternate solution that this function is a good candidate
for the the cleanup.h functionality. By scoping the mutex_lock() you can
simply return at each error location, and remove the explicit mutex_unlock().

But I'd accept this with the initializer change removed as well since I don't
think ath10k has any cleanup.h usages yet.

/jeff
Su Hui April 22, 2024, 3:32 a.m. UTC | #2
On 2024/4/19 23:09, Jeff Johnson wrote:
> On 4/17/2024 1:17 AM, Su Hui wrote:
>>   	u8 peer_debug_trigger;
>> -	int ret;
>> +	int ret = 0;
> this is unnecessary since this will be written in all paths that lead to the
> return that reads it
Yes, this is my fault. I will remove this in v2 patch.
>>   
>>   	if (kstrtou8_from_user(user_buf, count, 0, &peer_debug_trigger))
>>   		return -EINVAL;
>> @@ -432,14 +432,12 @@ ath10k_dbg_sta_write_peer_debug_trigger(struct file *file,
>>   
>>   	ret = ath10k_wmi_peer_set_param(ar, arsta->arvif->vdev_id, sta->addr,
>>   					ar->wmi.peer_param->debug, peer_debug_trigger);
>> -	if (ret) {
>> +	if (ret)
>>   		ath10k_warn(ar, "failed to set param to trigger peer tid logs for station ret: %d\n",
>>   			    ret);
>> -		goto out;
>> -	}
>>   out:
>>   	mutex_unlock(&ar->conf_mutex);
>> -	return count;
>> +	return ret ?: count;
>>   }
>>   
>>   static const struct file_operations fops_peer_debug_trigger = {
> I'd suggest as an alternate solution that this function is a good candidate
> for the the cleanup.h functionality. By scoping the mutex_lock() you can
> simply return at each error location, and remove the explicit mutex_unlock().

like guard(mutex)(&ar->conf_mutex)?

Maybe I can send a separate patch for this,  because there are more than 
one candidates

for the cleanup.h functionality.

> But I'd accept this with the initializer change removed as well since I don't
> think ath10k has any cleanup.h usages yet.

I will send v2 patch soon , thanks for your reply!

Su Hui
diff mbox series

Patch

diff --git a/drivers/net/wireless/ath/ath10k/debugfs_sta.c b/drivers/net/wireless/ath/ath10k/debugfs_sta.c
index 394bf3c32abf..5525dabe390a 100644
--- a/drivers/net/wireless/ath/ath10k/debugfs_sta.c
+++ b/drivers/net/wireless/ath/ath10k/debugfs_sta.c
@@ -415,7 +415,7 @@  ath10k_dbg_sta_write_peer_debug_trigger(struct file *file,
 	struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
 	struct ath10k *ar = arsta->arvif->ar;
 	u8 peer_debug_trigger;
-	int ret;
+	int ret = 0;
 
 	if (kstrtou8_from_user(user_buf, count, 0, &peer_debug_trigger))
 		return -EINVAL;
@@ -432,14 +432,12 @@  ath10k_dbg_sta_write_peer_debug_trigger(struct file *file,
 
 	ret = ath10k_wmi_peer_set_param(ar, arsta->arvif->vdev_id, sta->addr,
 					ar->wmi.peer_param->debug, peer_debug_trigger);
-	if (ret) {
+	if (ret)
 		ath10k_warn(ar, "failed to set param to trigger peer tid logs for station ret: %d\n",
 			    ret);
-		goto out;
-	}
 out:
 	mutex_unlock(&ar->conf_mutex);
-	return count;
+	return ret ?: count;
 }
 
 static const struct file_operations fops_peer_debug_trigger = {