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

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