[PATCH] carl9170: Fix error return -EAGAIN if not started

Subsystems: atheros ath generic utilities, carl9170 linux community wireless driver, the rest

STALE1777d

6 messages, 4 authors, 2021-10-10 · open the first message on its own page

[PATCH] carl9170: Fix error return -EAGAIN if not started

From: Colin King <hidden>
Date: 2021-10-08 00:16:03

From: Colin Ian King <redacted>

There is an error return path where the error return is being
assigned to err rather than count and the error exit path does
not return -EAGAIN as expected. Fix this by setting the error
return to variable count as this is the value that is returned
at the end of the function.

Addresses-Coverity: ("Unused value")
Fixes: 00c4da27a421 ("carl9170: firmware parser and debugfs code")
Signed-off-by: Colin Ian King <redacted>
---
 drivers/net/wireless/ath/carl9170/debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/wireless/ath/carl9170/debug.c b/drivers/net/wireless/ath/carl9170/debug.c
index bb40889d7c72..f163c6bdac8f 100644
--- a/drivers/net/wireless/ath/carl9170/debug.c
+++ b/drivers/net/wireless/ath/carl9170/debug.c
@@ -628,7 +628,7 @@ static ssize_t carl9170_debugfs_bug_write(struct ar9170 *ar, const char *buf,
 
 	case 'R':
 		if (!IS_STARTED(ar)) {
-			err = -EAGAIN;
+			count = -EAGAIN;
 			goto out;
 		}
 
-- 
2.32.0

Re: [PATCH] carl9170: Fix error return -EAGAIN if not started

From: Dan Carpenter <hidden>
Date: 2021-10-08 05:59:50

On Fri, Oct 08, 2021 at 01:15:58AM +0100, Colin King wrote:
quoted hunk
From: Colin Ian King <redacted>

There is an error return path where the error return is being
assigned to err rather than count and the error exit path does
not return -EAGAIN as expected. Fix this by setting the error
return to variable count as this is the value that is returned
at the end of the function.

Addresses-Coverity: ("Unused value")
Fixes: 00c4da27a421 ("carl9170: firmware parser and debugfs code")
Signed-off-by: Colin Ian King <redacted>
---
 drivers/net/wireless/ath/carl9170/debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/wireless/ath/carl9170/debug.c b/drivers/net/wireless/ath/carl9170/debug.c
index bb40889d7c72..f163c6bdac8f 100644
--- a/drivers/net/wireless/ath/carl9170/debug.c
+++ b/drivers/net/wireless/ath/carl9170/debug.c
@@ -628,7 +628,7 @@ static ssize_t carl9170_debugfs_bug_write(struct ar9170 *ar, const char *buf,
 
 	case 'R':
 		if (!IS_STARTED(ar)) {
-			err = -EAGAIN;
+			count = -EAGAIN;
 			goto out;
This is ugly.  The bug wouldn't have happened with a direct return, it's
only the goto out which causes it.  Better to replace all the error
paths with direct returns.  There are two other direct returns so it's
not like a new thing...

Goto out on the success path is fine here, though.

regards,
dan carpenter

Re: [PATCH] carl9170: Fix error return -EAGAIN if not started

From: Colin Ian King <hidden>
Date: 2021-10-08 07:31:45

On 08/10/2021 06:58, Dan Carpenter wrote:
On Fri, Oct 08, 2021 at 01:15:58AM +0100, Colin King wrote:
quoted
From: Colin Ian King <redacted>

There is an error return path where the error return is being
assigned to err rather than count and the error exit path does
not return -EAGAIN as expected. Fix this by setting the error
return to variable count as this is the value that is returned
at the end of the function.

Addresses-Coverity: ("Unused value")
Fixes: 00c4da27a421 ("carl9170: firmware parser and debugfs code")
Signed-off-by: Colin Ian King <redacted>
---
  drivers/net/wireless/ath/carl9170/debug.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/wireless/ath/carl9170/debug.c b/drivers/net/wireless/ath/carl9170/debug.c
index bb40889d7c72..f163c6bdac8f 100644
--- a/drivers/net/wireless/ath/carl9170/debug.c
+++ b/drivers/net/wireless/ath/carl9170/debug.c
@@ -628,7 +628,7 @@ static ssize_t carl9170_debugfs_bug_write(struct ar9170 *ar, const char *buf,
  
  	case 'R':
  		if (!IS_STARTED(ar)) {
-			err = -EAGAIN;
+			count = -EAGAIN;
  			goto out;
This is ugly.  The bug wouldn't have happened with a direct return, it's
only the goto out which causes it.  Better to replace all the error
paths with direct returns.  There are two other direct returns so it's
not like a new thing...
Yep, I agree it was ugly, I was trying to keep to the coding style and 
reduce the patch delta size. I can do a V2 if the maintainers deem it's 
a cleaner solution.
Goto out on the success path is fine here, though.
Yep. I believe that a goto to one exit return point (may possibly?) make 
the code smaller rather than a sprinkling of returns in a function, so 
I'm never sure if this is a win or not with these kind of cases.

Colin
regards,
dan carpenter

Re: [PATCH] carl9170: Fix error return -EAGAIN if not started

From: Dan Carpenter <hidden>
Date: 2021-10-08 07:44:59

On Fri, Oct 08, 2021 at 08:31:29AM +0100, Colin Ian King wrote:
On 08/10/2021 06:58, Dan Carpenter wrote:
quoted
On Fri, Oct 08, 2021 at 01:15:58AM +0100, Colin King wrote:
quoted
From: Colin Ian King <redacted>

There is an error return path where the error return is being
assigned to err rather than count and the error exit path does
not return -EAGAIN as expected. Fix this by setting the error
return to variable count as this is the value that is returned
at the end of the function.

Addresses-Coverity: ("Unused value")
Fixes: 00c4da27a421 ("carl9170: firmware parser and debugfs code")
Signed-off-by: Colin Ian King <redacted>
---
  drivers/net/wireless/ath/carl9170/debug.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/wireless/ath/carl9170/debug.c b/drivers/net/wireless/ath/carl9170/debug.c
index bb40889d7c72..f163c6bdac8f 100644
--- a/drivers/net/wireless/ath/carl9170/debug.c
+++ b/drivers/net/wireless/ath/carl9170/debug.c
@@ -628,7 +628,7 @@ static ssize_t carl9170_debugfs_bug_write(struct ar9170 *ar, const char *buf,
  	case 'R':
  		if (!IS_STARTED(ar)) {
-			err = -EAGAIN;
+			count = -EAGAIN;
  			goto out;
This is ugly.  The bug wouldn't have happened with a direct return, it's
only the goto out which causes it.  Better to replace all the error
paths with direct returns.  There are two other direct returns so it's
not like a new thing...
Yep, I agree it was ugly, I was trying to keep to the coding style and
reduce the patch delta size. I can do a V2 if the maintainers deem it's a
cleaner solution.
quoted
Goto out on the success path is fine here, though.
Yep. I believe that a goto to one exit return point (may possibly?) make the
code smaller rather than a sprinkling of returns in a function, so I'm never
sure if this is a win or not with these kind of cases.
My default position is to hate goto out labels, but today I'm thinking
maybe they kind of make sense for read/write "return count;" functions...

This is debugfs code and debugfs code is always the worst code in any
driver...

The other style anti-patten here is to have two variables which store
error codes.  Maybe it would be better to do something like below.  Or
your patch is also find...  Let's just go with that.  It's fine.

regards,
dan carpenter
diff --git a/drivers/net/wireless/ath/carl9170/debug.c b/drivers/net/wireless/ath/carl9170/debug.c
index bb40889d7c72..8ccd0d3bea4c 100644
--- a/drivers/net/wireless/ath/carl9170/debug.c
+++ b/drivers/net/wireless/ath/carl9170/debug.c
@@ -616,7 +616,7 @@ DEBUGFS_DECLARE_RW_FILE(hw_ioread32, CARL9170_DEBUG_RING_SIZE * 40);
 static ssize_t carl9170_debugfs_bug_write(struct ar9170 *ar, const char *buf,
 					  size_t count)
 {
-	int err;
+	int err = 0;
 
 	if (count < 1)
 		return -EINVAL;
@@ -638,7 +638,7 @@ static ssize_t carl9170_debugfs_bug_write(struct ar9170 *ar, const char *buf,
 	case 'M':
 		err = carl9170_mac_reset(ar);
 		if (err < 0)
-			count = err;
+			goto out;
 
 		goto out;
 
@@ -646,7 +646,7 @@ static ssize_t carl9170_debugfs_bug_write(struct ar9170 *ar, const char *buf,
 		err = carl9170_set_channel(ar, ar->hw->conf.chandef.chan,
 			cfg80211_get_chandef_type(&ar->hw->conf.chandef));
 		if (err < 0)
-			count = err;
+			goto out;
 
 		goto out;
 
@@ -657,6 +657,8 @@ static ssize_t carl9170_debugfs_bug_write(struct ar9170 *ar, const char *buf,
 	carl9170_restart(ar, CARL9170_RR_USER_REQUEST);
 
 out:
+	if (err < 0)
+		return err;
 	return count;
 }
 

Re: [PATCH] carl9170: Fix error return -EAGAIN if not started

From: Christian Lamparter <hidden>
Date: 2021-10-08 15:15:44

Hello,

On 08/10/2021 09:31, Colin Ian King wrote:
On 08/10/2021 06:58, Dan Carpenter wrote:
quoted
On Fri, Oct 08, 2021 at 01:15:58AM +0100, Colin King wrote:
quoted
From: Colin Ian King <redacted>

There is an error return path where the error return is being
assigned to err rather than count and the error exit path does
not return -EAGAIN as expected. Fix this by setting the error
return to variable count as this is the value that is returned
at the end of the function.

Addresses-Coverity: ("Unused value")
Fixes: 00c4da27a421 ("carl9170: firmware parser and debugfs code")
Signed-off-by: Colin Ian King <redacted>
---
  drivers/net/wireless/ath/carl9170/debug.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/wireless/ath/carl9170/debug.c b/drivers/net/wireless/ath/carl9170/debug.c
index bb40889d7c72..f163c6bdac8f 100644
--- a/drivers/net/wireless/ath/carl9170/debug.c
+++ b/drivers/net/wireless/ath/carl9170/debug.c
@@ -628,7 +628,7 @@ static ssize_t carl9170_debugfs_bug_write(struct ar9170 *ar, const char *buf,
      case 'R':
          if (!IS_STARTED(ar)) {
-            err = -EAGAIN;
+            count = -EAGAIN;
              goto out;
This is ugly.  The bug wouldn't have happened with a direct return, it's
only the goto out which causes it.  Better to replace all the error
paths with direct returns.  There are two other direct returns so it's
not like a new thing...
Yep, I agree it was ugly, I was trying to keep to the coding style and reduce the patch delta size. I can do a V2 if the maintainers deem it's a cleaner solution.
Hm? I don't think there's any need to stick to a particular
coding style. This file hasn't been touched a lot since 2010.
Things moved on and replacing the gotos with straight return
is totally fine.

(It has to pass the build checkers of course. However I don't
think this will be a problem here...)

Cheers,
Christian

Re: [PATCH] carl9170: Fix error return -EAGAIN if not started

From: Kalle Valo <hidden>
Date: 2021-10-10 08:05:49

Colin King [off-list ref] wrote:
From: Colin Ian King <redacted>

There is an error return path where the error return is being
assigned to err rather than count and the error exit path does
not return -EAGAIN as expected. Fix this by setting the error
return to variable count as this is the value that is returned
at the end of the function.

Addresses-Coverity: ("Unused value")
Fixes: 00c4da27a421 ("carl9170: firmware parser and debugfs code")
Signed-off-by: Colin Ian King <redacted>
I assume there will be v2 so dropping this version.

Patch set to Changes Requested.

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/20211008001558.32416-1-colin.king@canonical.com/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help