diff mbox series

[v2] ioctl: only memset non-NULL link settings

Message ID 20200827095033.3265848-1-hegtvedt@cisco.com
State Accepted
Delegated to: Michal Kubecek
Headers show
Series [v2] ioctl: only memset non-NULL link settings | expand

Commit Message

Hans-Christian Noren Egtvedt Aug. 27, 2020, 9:50 a.m. UTC
In commit bef780467fa ('ioctl: do not pass transceiver value back to
kernel') a regression slipped in. If we have a kernel that does not
support the ETHTOOL_xLINKSETTINGS API, then the do_ioctl_glinksettings()
function will return a NULL pointer.

Hence before memset'ing the pointer to zero we must first check it is
valid, as NULL return is perfectly fine when running on old kernels.

Fixes: bef780467fa7 ("ioctl: do not pass transceiver value back to kernel")
Signed-off-by: Hans-Christian Noren Egtvedt <hegtvedt@cisco.com>
---
 ethtool.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Michal Kubecek Aug. 27, 2020, 10:36 a.m. UTC | #1
On Thu, Aug 27, 2020 at 11:50:33AM +0200, Hans-Christian Noren Egtvedt wrote:
> In commit bef780467fa ('ioctl: do not pass transceiver value back to
> kernel') a regression slipped in. If we have a kernel that does not
> support the ETHTOOL_xLINKSETTINGS API, then the do_ioctl_glinksettings()
> function will return a NULL pointer.
> 
> Hence before memset'ing the pointer to zero we must first check it is
> valid, as NULL return is perfectly fine when running on old kernels.
> 
> Fixes: bef780467fa7 ("ioctl: do not pass transceiver value back to kernel")
> Signed-off-by: Hans-Christian Noren Egtvedt <hegtvedt@cisco.com>

Applied, thank you.

Michal

> ---
>  ethtool.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/ethtool.c b/ethtool.c
> index e32a93b..606af3e 100644
> --- a/ethtool.c
> +++ b/ethtool.c
> @@ -3048,10 +3048,11 @@ static int do_sset(struct cmd_context *ctx)
>  		struct ethtool_link_usettings *link_usettings;
>  
>  		link_usettings = do_ioctl_glinksettings(ctx);
> -		memset(&link_usettings->deprecated, 0,
> -		       sizeof(link_usettings->deprecated));
>  		if (link_usettings == NULL)
>  			link_usettings = do_ioctl_gset(ctx);
> +		else
> +			memset(&link_usettings->deprecated, 0,
> +			       sizeof(link_usettings->deprecated));
>  		if (link_usettings == NULL) {
>  			perror("Cannot get current device settings");
>  			err = -1;
> -- 
> 2.25.1
>
diff mbox series

Patch

diff --git a/ethtool.c b/ethtool.c
index e32a93b..606af3e 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -3048,10 +3048,11 @@  static int do_sset(struct cmd_context *ctx)
 		struct ethtool_link_usettings *link_usettings;
 
 		link_usettings = do_ioctl_glinksettings(ctx);
-		memset(&link_usettings->deprecated, 0,
-		       sizeof(link_usettings->deprecated));
 		if (link_usettings == NULL)
 			link_usettings = do_ioctl_gset(ctx);
+		else
+			memset(&link_usettings->deprecated, 0,
+			       sizeof(link_usettings->deprecated));
 		if (link_usettings == NULL) {
 			perror("Cannot get current device settings");
 			err = -1;