All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ethtool: remove extra checks
@ 2020-06-06 12:49 Vasily Averin
  2020-06-06 13:48 ` Michal Kubecek
  0 siblings, 1 reply; 2+ messages in thread
From: Vasily Averin @ 2020-06-06 12:49 UTC (permalink / raw)
  To: netdev; +Cc: David S. Miller, Jakub Kicinski

Found by smatch:
net/ethtool/linkmodes.c:356 ethnl_set_linkmodes() warn:
 variable dereferenced before check 'info' (see line 332)
net/ethtool/linkinfo.c:143 ethnl_set_linkinfo() warn:
 variable dereferenced before check 'info' (see line 119

In both cases non-zero 'info' is always provided by caller.

Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
---
 net/ethtool/linkinfo.c  | 3 +--
 net/ethtool/linkmodes.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/net/ethtool/linkinfo.c b/net/ethtool/linkinfo.c
index 677068d..5eaf173 100644
--- a/net/ethtool/linkinfo.c
+++ b/net/ethtool/linkinfo.c
@@ -140,8 +140,7 @@ int ethnl_set_linkinfo(struct sk_buff *skb, struct genl_info *info)
 
 	ret = __ethtool_get_link_ksettings(dev, &ksettings);
 	if (ret < 0) {
-		if (info)
-			GENL_SET_ERR_MSG(info, "failed to retrieve link settings");
+		GENL_SET_ERR_MSG(info, "failed to retrieve link settings");
 		goto out_ops;
 	}
 	lsettings = &ksettings.base;
diff --git a/net/ethtool/linkmodes.c b/net/ethtool/linkmodes.c
index 452608c..b759133 100644
--- a/net/ethtool/linkmodes.c
+++ b/net/ethtool/linkmodes.c
@@ -353,8 +353,7 @@ int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info)
 
 	ret = __ethtool_get_link_ksettings(dev, &ksettings);
 	if (ret < 0) {
-		if (info)
-			GENL_SET_ERR_MSG(info, "failed to retrieve link settings");
+		GENL_SET_ERR_MSG(info, "failed to retrieve link settings");
 		goto out_ops;
 	}
 
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ethtool: remove extra checks
  2020-06-06 12:49 [PATCH] ethtool: remove extra checks Vasily Averin
@ 2020-06-06 13:48 ` Michal Kubecek
  0 siblings, 0 replies; 2+ messages in thread
From: Michal Kubecek @ 2020-06-06 13:48 UTC (permalink / raw)
  To: Vasily Averin; +Cc: netdev, David S. Miller, Jakub Kicinski

[-- Attachment #1: Type: text/plain, Size: 1846 bytes --]

On Sat, Jun 06, 2020 at 03:49:05PM +0300, Vasily Averin wrote:
> Found by smatch:
> net/ethtool/linkmodes.c:356 ethnl_set_linkmodes() warn:
>  variable dereferenced before check 'info' (see line 332)
> net/ethtool/linkinfo.c:143 ethnl_set_linkinfo() warn:
>  variable dereferenced before check 'info' (see line 119
> 
> In both cases non-zero 'info' is always provided by caller.
> 
> Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
> ---
>  net/ethtool/linkinfo.c  | 3 +--
>  net/ethtool/linkmodes.c | 3 +--
>  2 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/net/ethtool/linkinfo.c b/net/ethtool/linkinfo.c
> index 677068d..5eaf173 100644
> --- a/net/ethtool/linkinfo.c
> +++ b/net/ethtool/linkinfo.c
> @@ -140,8 +140,7 @@ int ethnl_set_linkinfo(struct sk_buff *skb, struct genl_info *info)
>  
>  	ret = __ethtool_get_link_ksettings(dev, &ksettings);
>  	if (ret < 0) {
> -		if (info)
> -			GENL_SET_ERR_MSG(info, "failed to retrieve link settings");
> +		GENL_SET_ERR_MSG(info, "failed to retrieve link settings");
>  		goto out_ops;
>  	}
>  	lsettings = &ksettings.base;

This change is already in net tree as commit 178f67b1288b ("ethtool:
linkinfo: remove an unnecessary NULL check").

> diff --git a/net/ethtool/linkmodes.c b/net/ethtool/linkmodes.c
> index 452608c..b759133 100644
> --- a/net/ethtool/linkmodes.c
> +++ b/net/ethtool/linkmodes.c
> @@ -353,8 +353,7 @@ int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info)
>  
>  	ret = __ethtool_get_link_ksettings(dev, &ksettings);
>  	if (ret < 0) {
> -		if (info)
> -			GENL_SET_ERR_MSG(info, "failed to retrieve link settings");
> +		GENL_SET_ERR_MSG(info, "failed to retrieve link settings");
>  		goto out_ops;
>  	}
>  

For this part, 

Reviewed-by: Michal Kubecek <mkubecek@suse.cz>

Michal

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-06 13:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-06 12:49 [PATCH] ethtool: remove extra checks Vasily Averin
2020-06-06 13:48 ` Michal Kubecek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.