diff mbox series

cxgb4: do conversion after string check

Message ID 20230330154703.36958-1-den-plotnikov@yandex-team.ru (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series cxgb4: do conversion after string check | 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/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: 18 this patch: 18
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 18 this patch: 18
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 success Errors and warnings before: 18 this patch: 18
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 12 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Denis Plotnikov March 30, 2023, 3:47 p.m. UTC
Static code analyzer complains to uncheck return value.
Indeed, the return value of kstrtouint "must be checked"
as the comment says.
Moreover, it looks like the string conversion  should be
after "end of string" or "new line" check.
This patch fixes these issues.

Signed-off-by: Denis Plotnikov <den-plotnikov@yandex-team.ru>
---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Simon Horman March 30, 2023, 7:52 p.m. UTC | #1
On Thu, Mar 30, 2023 at 06:47:03PM +0300, Denis Plotnikov wrote:
> Static code analyzer complains to uncheck return value.
> Indeed, the return value of kstrtouint "must be checked"
> as the comment says.
> Moreover, it looks like the string conversion  should be
> after "end of string" or "new line" check.
> This patch fixes these issues.
> 
> Signed-off-by: Denis Plotnikov <den-plotnikov@yandex-team.ru>
> ---
>  drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
> index 14e0d989c3ba5..a8d3616630cc6 100644
> --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
> +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
> @@ -1576,9 +1576,11 @@ inval:				count = -EINVAL;
>  		}
>  		if (*word == '@') {
>  			end = (char *)word + 1;
> -			ret = kstrtouint(end, 10, &j);
>  			if (*end && *end != '\n')
>  				goto inval;

I feel that I must be missing something very obvious.

My reading is that the code only gets to this line
if *end is either '\0' or '\n'. Which would not be the case
if end points to the string representation of number.
So I am confused about this code, both with and without your patch.

Perhaps the check is assuming that end is pointing
to the end of the string representation of the number.
Something like the endptr after a call to libc's strtoul(3).
But by my reading it is pointing to the beginning.

> +			ret = kstrtouint(end, 10, &j);
> +			if (ret)
> +				goto inval;
>  			if (j & 7)          /* doesn't start at multiple of 8 */
>  				goto inval;
>  			j /= 8;
> -- 
> 2.25.1
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
index 14e0d989c3ba5..a8d3616630cc6 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
@@ -1576,9 +1576,11 @@  inval:				count = -EINVAL;
 		}
 		if (*word == '@') {
 			end = (char *)word + 1;
-			ret = kstrtouint(end, 10, &j);
 			if (*end && *end != '\n')
 				goto inval;
+			ret = kstrtouint(end, 10, &j);
+			if (ret)
+				goto inval;
 			if (j & 7)          /* doesn't start at multiple of 8 */
 				goto inval;
 			j /= 8;