Blame SOURCES/0004-ioctl-check-presence-of-eeprom-length-argument-prope.patch

c96cf6
From ce297bec23dd0054600678b4297f6e73ecdc540d Mon Sep 17 00:00:00 2001
c96cf6
From: Michal Kubecek <mkubecek@suse.cz>
c96cf6
Date: Sun, 23 Aug 2020 21:40:21 +0200
c96cf6
Subject: [PATCH 04/17] ioctl: check presence of eeprom length argument
c96cf6
 properly
c96cf6
c96cf6
In do_geeprom(), do_seprom() and do_getmodule(), check if user used
c96cf6
"length" command line argument is done by setting the value to -1 before
c96cf6
parsing and checking if it changed. This is quite ugly and also causes
c96cf6
compiler warnings as the variable is u32.
c96cf6
c96cf6
Use proper "seen" flag to let parser tell us if the argument was used.
c96cf6
c96cf6
Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
c96cf6
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
c96cf6
(cherry picked from commit 923c3f51c4442a5f25afb529bd49ec2ef4f185a3)
c96cf6
---
c96cf6
 ethtool.c | 24 +++++++++++++++---------
c96cf6
 1 file changed, 15 insertions(+), 9 deletions(-)
c96cf6
c96cf6
diff --git a/ethtool.c b/ethtool.c
c96cf6
index c4ad186cd390..4fa7a2c1716f 100644
c96cf6
--- a/ethtool.c
c96cf6
+++ b/ethtool.c
c96cf6
@@ -3184,10 +3184,12 @@ static int do_geeprom(struct cmd_context *ctx)
c96cf6
 	int geeprom_changed = 0;
c96cf6
 	int geeprom_dump_raw = 0;
c96cf6
 	u32 geeprom_offset = 0;
c96cf6
-	u32 geeprom_length = -1;
c96cf6
+	u32 geeprom_length = 0;
c96cf6
+	int geeprom_length_seen = 0;
c96cf6
 	struct cmdline_info cmdline_geeprom[] = {
c96cf6
 		{ "offset", CMDL_U32, &geeprom_offset, NULL },
c96cf6
-		{ "length", CMDL_U32, &geeprom_length, NULL },
c96cf6
+		{ "length", CMDL_U32, &geeprom_length, NULL,
c96cf6
+		  0, &geeprom_length_seen },
c96cf6
 		{ "raw", CMDL_BOOL, &geeprom_dump_raw, NULL },
c96cf6
 	};
c96cf6
 	int err;
c96cf6
@@ -3204,7 +3206,7 @@ static int do_geeprom(struct cmd_context *ctx)
c96cf6
 		return 74;
c96cf6
 	}
c96cf6
 
c96cf6
-	if (geeprom_length == -1)
c96cf6
+	if (!geeprom_length_seen)
c96cf6
 		geeprom_length = drvinfo.eedump_len;
c96cf6
 
c96cf6
 	if (drvinfo.eedump_len < geeprom_offset + geeprom_length)
c96cf6
@@ -3234,14 +3236,16 @@ static int do_seeprom(struct cmd_context *ctx)
c96cf6
 {
c96cf6
 	int seeprom_changed = 0;
c96cf6
 	u32 seeprom_magic = 0;
c96cf6
-	u32 seeprom_length = -1;
c96cf6
+	u32 seeprom_length = 0;
c96cf6
 	u32 seeprom_offset = 0;
c96cf6
 	u8 seeprom_value = 0;
c96cf6
+	int seeprom_length_seen = 0;
c96cf6
 	int seeprom_value_seen = 0;
c96cf6
 	struct cmdline_info cmdline_seeprom[] = {
c96cf6
 		{ "magic", CMDL_U32, &seeprom_magic, NULL },
c96cf6
 		{ "offset", CMDL_U32, &seeprom_offset, NULL },
c96cf6
-		{ "length", CMDL_U32, &seeprom_length, NULL },
c96cf6
+		{ "length", CMDL_U32, &seeprom_length, NULL,
c96cf6
+		  0, &seeprom_length_seen },
c96cf6
 		{ "value", CMDL_U8, &seeprom_value, NULL,
c96cf6
 		  0, &seeprom_value_seen },
c96cf6
 	};
c96cf6
@@ -3262,7 +3266,7 @@ static int do_seeprom(struct cmd_context *ctx)
c96cf6
 	if (seeprom_value_seen)
c96cf6
 		seeprom_length = 1;
c96cf6
 
c96cf6
-	if (seeprom_length == -1)
c96cf6
+	if (!seeprom_length_seen)
c96cf6
 		seeprom_length = drvinfo.eedump_len;
c96cf6
 
c96cf6
 	if (drvinfo.eedump_len < seeprom_offset + seeprom_length) {
c96cf6
@@ -4538,15 +4542,17 @@ static int do_getmodule(struct cmd_context *ctx)
c96cf6
 	struct ethtool_modinfo modinfo;
c96cf6
 	struct ethtool_eeprom *eeprom;
c96cf6
 	u32 geeprom_offset = 0;
c96cf6
-	u32 geeprom_length = -1;
c96cf6
+	u32 geeprom_length = 0;
c96cf6
 	int geeprom_changed = 0;
c96cf6
 	int geeprom_dump_raw = 0;
c96cf6
 	int geeprom_dump_hex = 0;
c96cf6
+	int geeprom_length_seen = 0;
c96cf6
 	int err;
c96cf6
 
c96cf6
 	struct cmdline_info cmdline_geeprom[] = {
c96cf6
 		{ "offset", CMDL_U32, &geeprom_offset, NULL },
c96cf6
-		{ "length", CMDL_U32, &geeprom_length, NULL },
c96cf6
+		{ "length", CMDL_U32, &geeprom_length, NULL,
c96cf6
+		  0, &geeprom_length_seen },
c96cf6
 		{ "raw", CMDL_BOOL, &geeprom_dump_raw, NULL },
c96cf6
 		{ "hex", CMDL_BOOL, &geeprom_dump_hex, NULL },
c96cf6
 	};
c96cf6
@@ -4566,7 +4572,7 @@ static int do_getmodule(struct cmd_context *ctx)
c96cf6
 		return 1;
c96cf6
 	}
c96cf6
 
c96cf6
-	if (geeprom_length == -1)
c96cf6
+	if (!geeprom_length_seen)
c96cf6
 		geeprom_length = modinfo.eeprom_len;
c96cf6
 
c96cf6
 	if (modinfo.eeprom_len < geeprom_offset + geeprom_length)
c96cf6
-- 
c96cf6
2.26.2
c96cf6