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

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