diff mbox series

net: dsa: Remove unsigned expression compared with zero

Message ID 1621421391-36681-1-git-send-email-jiapeng.chong@linux.alibaba.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: dsa: Remove unsigned expression compared with zero | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Jiapeng Chong May 19, 2021, 10:49 a.m. UTC
Variable val is "u32" always >= 0, so val >= 0 condition are redundant.

Clean up the following coccicheck warning:

./drivers/net/dsa/qca8k.c:732:5-8: WARNING: Unsigned expression compared
with zero: val >= 0.

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
 drivers/net/dsa/qca8k.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Vladimir Oltean May 19, 2021, 6:24 p.m. UTC | #1
Hi Jiapeng,

On Wed, May 19, 2021 at 06:49:51PM +0800, Jiapeng Chong wrote:
> Variable val is "u32" always >= 0, so val >= 0 condition are redundant.
> 
> Clean up the following coccicheck warning:
> 
> ./drivers/net/dsa/qca8k.c:732:5-8: WARNING: Unsigned expression compared
> with zero: val >= 0.
> 
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
>  drivers/net/dsa/qca8k.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c
> index 4753228..7b38b8d 100644
> --- a/drivers/net/dsa/qca8k.c
> +++ b/drivers/net/dsa/qca8k.c
> @@ -729,8 +729,7 @@
>  
>  	mutex_unlock(&bus->mdio_lock);
>  
> -	if (val >= 0)
> -		val &= QCA8K_MDIO_MASTER_DATA_MASK;
> +	val &= QCA8K_MDIO_MASTER_DATA_MASK;
>  
>  	return val;
>  }
> -- 
> 1.8.3.1
> 

The qca8k driver has some problems with the handling of signed/unsigned
return values. I would suggest a better approach to be to make
qca8k_mii_read32 to return an int value, and keep this check as is.
diff mbox series

Patch

diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c
index 4753228..7b38b8d 100644
--- a/drivers/net/dsa/qca8k.c
+++ b/drivers/net/dsa/qca8k.c
@@ -729,8 +729,7 @@ 
 
 	mutex_unlock(&bus->mdio_lock);
 
-	if (val >= 0)
-		val &= QCA8K_MDIO_MASTER_DATA_MASK;
+	val &= QCA8K_MDIO_MASTER_DATA_MASK;
 
 	return val;
 }