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

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