Blame SOURCES/0012-ioctl-only-memset-non-NULL-link-settings.patch

c96cf6
From a4186edd5bcb44d3236852816c21752eb82e5039 Mon Sep 17 00:00:00 2001
c96cf6
From: Hans-Christian Noren Egtvedt <hegtvedt@cisco.com>
c96cf6
Date: Thu, 27 Aug 2020 11:50:33 +0200
c96cf6
Subject: [PATCH 12/17] ioctl: only memset non-NULL link settings
c96cf6
c96cf6
In commit bef780467fa ("ioctl: do not pass transceiver value back to
c96cf6
kernel") a regression slipped in. If we have a kernel that does not
c96cf6
support the ETHTOOL_xLINKSETTINGS API, then the do_ioctl_glinksettings()
c96cf6
function will return a NULL pointer.
c96cf6
c96cf6
Hence before memset'ing the pointer to zero we must first check it is
c96cf6
valid, as NULL return is perfectly fine when running on old kernels.
c96cf6
c96cf6
Fixes: bef780467fa7 ("ioctl: do not pass transceiver value back to kernel")
c96cf6
Signed-off-by: Hans-Christian Noren Egtvedt <hegtvedt@cisco.com>
c96cf6
Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
c96cf6
(cherry picked from commit cf12872ebe7d8fac2088e7d2cd5e2a0a5f03499d)
c96cf6
---
c96cf6
 ethtool.c | 5 +++--
c96cf6
 1 file changed, 3 insertions(+), 2 deletions(-)
c96cf6
c96cf6
diff --git a/ethtool.c b/ethtool.c
c96cf6
index e32a93b41088..606af3e6b48f 100644
c96cf6
--- a/ethtool.c
c96cf6
+++ b/ethtool.c
c96cf6
@@ -3048,10 +3048,11 @@ static int do_sset(struct cmd_context *ctx)
c96cf6
 		struct ethtool_link_usettings *link_usettings;
c96cf6
 
c96cf6
 		link_usettings = do_ioctl_glinksettings(ctx);
c96cf6
-		memset(&link_usettings->deprecated, 0,
c96cf6
-		       sizeof(link_usettings->deprecated));
c96cf6
 		if (link_usettings == NULL)
c96cf6
 			link_usettings = do_ioctl_gset(ctx);
c96cf6
+		else
c96cf6
+			memset(&link_usettings->deprecated, 0,
c96cf6
+			       sizeof(link_usettings->deprecated));
c96cf6
 		if (link_usettings == NULL) {
c96cf6
 			perror("Cannot get current device settings");
c96cf6
 			err = -1;
c96cf6
-- 
c96cf6
2.26.2
c96cf6