diff mbox series

net: dsa: Fix return value check of wait_for_completion_timeout

Message ID 20220412024541.17572-1-linmq006@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: dsa: Fix return value check of wait_for_completion_timeout | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
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/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 85 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Miaoqian Lin April 12, 2022, 2:45 a.m. UTC
wait_for_completion_timeout() returns unsigned long not int.
It returns 0 if timed out, and positive if completed.
The check for <= 0 is ambiguous and should be == 0 here
indicating timeout which is the only error case.

Fixes: 2cd548566384 ("net: dsa: qca8k: add support for phy read/write with mgmt Ethernet")
Fixes: 5950c7c0a68c ("net: dsa: qca8k: add support for mgmt read/write in Ethernet packet")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/net/dsa/qca8k.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

Comments

Andrew Lunn April 12, 2022, 12:53 p.m. UTC | #1
On Tue, Apr 12, 2022 at 02:45:40AM +0000, Miaoqian Lin wrote:
> wait_for_completion_timeout() returns unsigned long not int.
> It returns 0 if timed out, and positive if completed.
> The check for <= 0 is ambiguous and should be == 0 here
> indicating timeout which is the only error case.

Please fix your subject line to indicate which driver you are patching.

Please also read the netdev FAQ which will point out a few other
process issues.

> 
> Fixes: 2cd548566384 ("net: dsa: qca8k: add support for phy read/write with mgmt Ethernet")
> Fixes: 5950c7c0a68c ("net: dsa: qca8k: add support for mgmt read/write in Ethernet packet")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
>  drivers/net/dsa/qca8k.c | 25 +++++++++++++------------
>  1 file changed, 13 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c
> index d3ed0a7f8077..bd8c238955a8 100644
> --- a/drivers/net/dsa/qca8k.c
> +++ b/drivers/net/dsa/qca8k.c
> @@ -300,7 +300,7 @@ static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
>  	struct qca8k_mgmt_eth_data *mgmt_eth_data = &priv->mgmt_eth_data;
>  	struct sk_buff *skb;
>  	bool ack;
> -	int ret;
> +	unsigned long ret;

Please sort variables longest to shortest, reverse christmass tree.

>  
>  	skb = qca8k_alloc_mdio_header(MDIO_READ, reg, NULL,
>  				      QCA8K_ETHERNET_MDIO_PRIORITY, len);
> @@ -338,7 +338,7 @@ static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
>  
>  	mutex_unlock(&mgmt_eth_data->mutex);
>  
> -	if (ret <= 0)
> +	if (ret == 0)
>  		return -ETIMEDOUT;

Given this change, what happens if -ERESTARTSYS is returned?

Please consider the same question for all cases you change <= to ==.

       Andrew
diff mbox series

Patch

diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c
index d3ed0a7f8077..bd8c238955a8 100644
--- a/drivers/net/dsa/qca8k.c
+++ b/drivers/net/dsa/qca8k.c
@@ -300,7 +300,7 @@  static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
 	struct qca8k_mgmt_eth_data *mgmt_eth_data = &priv->mgmt_eth_data;
 	struct sk_buff *skb;
 	bool ack;
-	int ret;
+	unsigned long ret;
 
 	skb = qca8k_alloc_mdio_header(MDIO_READ, reg, NULL,
 				      QCA8K_ETHERNET_MDIO_PRIORITY, len);
@@ -338,7 +338,7 @@  static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
 
 	mutex_unlock(&mgmt_eth_data->mutex);
 
-	if (ret <= 0)
+	if (ret == 0)
 		return -ETIMEDOUT;
 
 	if (!ack)
@@ -352,7 +352,7 @@  static int qca8k_write_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
 	struct qca8k_mgmt_eth_data *mgmt_eth_data = &priv->mgmt_eth_data;
 	struct sk_buff *skb;
 	bool ack;
-	int ret;
+	unsigned long ret;
 
 	skb = qca8k_alloc_mdio_header(MDIO_WRITE, reg, val,
 				      QCA8K_ETHERNET_MDIO_PRIORITY, len);
@@ -386,7 +386,7 @@  static int qca8k_write_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
 
 	mutex_unlock(&mgmt_eth_data->mutex);
 
-	if (ret <= 0)
+	if (ret == 0)
 		return -ETIMEDOUT;
 
 	if (!ack)
@@ -956,7 +956,7 @@  qca8k_phy_eth_busy_wait(struct qca8k_mgmt_eth_data *mgmt_eth_data,
 {
 	struct sk_buff *skb = skb_copy(read_skb, GFP_KERNEL);
 	bool ack;
-	int ret;
+	unsigned long ret;
 
 	reinit_completion(&mgmt_eth_data->rw_done);
 
@@ -972,7 +972,7 @@  qca8k_phy_eth_busy_wait(struct qca8k_mgmt_eth_data *mgmt_eth_data,
 
 	ack = mgmt_eth_data->ack;
 
-	if (ret <= 0)
+	if (ret == 0)
 		return -ETIMEDOUT;
 
 	if (!ack)
@@ -993,6 +993,7 @@  qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy,
 	struct net_device *mgmt_master;
 	int ret, ret1;
 	bool ack;
+	unsigned long time_left;
 
 	if (regnum >= QCA8K_MDIO_MASTER_MAX_REG)
 		return -EINVAL;
@@ -1059,12 +1060,12 @@  qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy,
 
 	dev_queue_xmit(write_skb);
 
-	ret = wait_for_completion_timeout(&mgmt_eth_data->rw_done,
-					  QCA8K_ETHERNET_TIMEOUT);
+	time_left = wait_for_completion_timeout(&mgmt_eth_data->rw_done,
+						QCA8K_ETHERNET_TIMEOUT);
 
 	ack = mgmt_eth_data->ack;
 
-	if (ret <= 0) {
+	if (time_left == 0) {
 		ret = -ETIMEDOUT;
 		kfree_skb(read_skb);
 		goto exit;
@@ -1096,12 +1097,12 @@  qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy,
 
 		dev_queue_xmit(read_skb);
 
-		ret = wait_for_completion_timeout(&mgmt_eth_data->rw_done,
-						  QCA8K_ETHERNET_TIMEOUT);
+		time_left = wait_for_completion_timeout(&mgmt_eth_data->rw_done,
+							QCA8K_ETHERNET_TIMEOUT);
 
 		ack = mgmt_eth_data->ack;
 
-		if (ret <= 0) {
+		if (time_left == 0) {
 			ret = -ETIMEDOUT;
 			goto exit;
 		}