netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michal Kubecek <mkubecek@suse.cz>
To: netdev@vger.kernel.org
Subject: [PATCH ethtool 2/7] ioctl: check presence of eeprom length argument properly
Date: Sun,  9 Aug 2020 23:24:22 +0200 (CEST)	[thread overview]
Message-ID: <fb0a0177b4cb7d477ff964a64c9293f7267fdd5c.1597007533.git.mkubecek@suse.cz> (raw)
In-Reply-To: <cover.1597007532.git.mkubecek@suse.cz>

In do_geeprom(), do_seprom() and do_getmodule(), check if user used
"length" command line argument is done by setting the value to -1 before
parsing and checking if it changed. This is quite ugly and also causes
compiler warnings as the variable is u32.

Use proper "seen" flag to let parser tell us if the argument was used.

Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
---
 ethtool.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/ethtool.c b/ethtool.c
index c4ad186cd390..4fa7a2c1716f 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -3184,10 +3184,12 @@ static int do_geeprom(struct cmd_context *ctx)
 	int geeprom_changed = 0;
 	int geeprom_dump_raw = 0;
 	u32 geeprom_offset = 0;
-	u32 geeprom_length = -1;
+	u32 geeprom_length = 0;
+	int geeprom_length_seen = 0;
 	struct cmdline_info cmdline_geeprom[] = {
 		{ "offset", CMDL_U32, &geeprom_offset, NULL },
-		{ "length", CMDL_U32, &geeprom_length, NULL },
+		{ "length", CMDL_U32, &geeprom_length, NULL,
+		  0, &geeprom_length_seen },
 		{ "raw", CMDL_BOOL, &geeprom_dump_raw, NULL },
 	};
 	int err;
@@ -3204,7 +3206,7 @@ static int do_geeprom(struct cmd_context *ctx)
 		return 74;
 	}
 
-	if (geeprom_length == -1)
+	if (!geeprom_length_seen)
 		geeprom_length = drvinfo.eedump_len;
 
 	if (drvinfo.eedump_len < geeprom_offset + geeprom_length)
@@ -3234,14 +3236,16 @@ static int do_seeprom(struct cmd_context *ctx)
 {
 	int seeprom_changed = 0;
 	u32 seeprom_magic = 0;
-	u32 seeprom_length = -1;
+	u32 seeprom_length = 0;
 	u32 seeprom_offset = 0;
 	u8 seeprom_value = 0;
+	int seeprom_length_seen = 0;
 	int seeprom_value_seen = 0;
 	struct cmdline_info cmdline_seeprom[] = {
 		{ "magic", CMDL_U32, &seeprom_magic, NULL },
 		{ "offset", CMDL_U32, &seeprom_offset, NULL },
-		{ "length", CMDL_U32, &seeprom_length, NULL },
+		{ "length", CMDL_U32, &seeprom_length, NULL,
+		  0, &seeprom_length_seen },
 		{ "value", CMDL_U8, &seeprom_value, NULL,
 		  0, &seeprom_value_seen },
 	};
@@ -3262,7 +3266,7 @@ static int do_seeprom(struct cmd_context *ctx)
 	if (seeprom_value_seen)
 		seeprom_length = 1;
 
-	if (seeprom_length == -1)
+	if (!seeprom_length_seen)
 		seeprom_length = drvinfo.eedump_len;
 
 	if (drvinfo.eedump_len < seeprom_offset + seeprom_length) {
@@ -4538,15 +4542,17 @@ static int do_getmodule(struct cmd_context *ctx)
 	struct ethtool_modinfo modinfo;
 	struct ethtool_eeprom *eeprom;
 	u32 geeprom_offset = 0;
-	u32 geeprom_length = -1;
+	u32 geeprom_length = 0;
 	int geeprom_changed = 0;
 	int geeprom_dump_raw = 0;
 	int geeprom_dump_hex = 0;
+	int geeprom_length_seen = 0;
 	int err;
 
 	struct cmdline_info cmdline_geeprom[] = {
 		{ "offset", CMDL_U32, &geeprom_offset, NULL },
-		{ "length", CMDL_U32, &geeprom_length, NULL },
+		{ "length", CMDL_U32, &geeprom_length, NULL,
+		  0, &geeprom_length_seen },
 		{ "raw", CMDL_BOOL, &geeprom_dump_raw, NULL },
 		{ "hex", CMDL_BOOL, &geeprom_dump_hex, NULL },
 	};
@@ -4566,7 +4572,7 @@ static int do_getmodule(struct cmd_context *ctx)
 		return 1;
 	}
 
-	if (geeprom_length == -1)
+	if (!geeprom_length_seen)
 		geeprom_length = modinfo.eeprom_len;
 
 	if (modinfo.eeprom_len < geeprom_offset + geeprom_length)
-- 
2.28.0


  parent reply	other threads:[~2020-08-09 21:24 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-09 21:24 [PATCH ethtool 0/7] compiler warnings cleanup, part 2 Michal Kubecek
2020-08-09 21:24 ` [PATCH ethtool 1/7] netlink: get rid of signed/unsigned comparison warnings Michal Kubecek
2020-08-10 14:11   ` Andrew Lunn
2020-08-11 20:30     ` Michal Kubecek
2020-08-09 21:24 ` Michal Kubecek [this message]
2020-08-10 14:12   ` [PATCH ethtool 2/7] ioctl: check presence of eeprom length argument properly Andrew Lunn
2020-08-09 21:24 ` [PATCH ethtool 3/7] ioctl: get rid of signed/unsigned comparison warnings Michal Kubecek
2020-08-10 14:19   ` Andrew Lunn
2020-08-10 14:24     ` David Laight
2020-08-11 21:20     ` Michal Kubecek
2020-08-09 21:24 ` [PATCH ethtool 4/7] get rid of signed/unsigned comparison warnings in register dump parsers Michal Kubecek
2020-08-10 14:20   ` Andrew Lunn
2020-08-09 21:24 ` [PATCH ethtool 5/7] settings: simplify link_mode_info[] initializers Michal Kubecek
2020-08-10 14:21   ` Andrew Lunn
2020-08-09 21:24 ` [PATCH ethtool 6/7] ioctl: convert cmdline_info arrays to named initializers Michal Kubecek
2020-08-10 14:21   ` Andrew Lunn
2020-08-09 21:24 ` [PATCH ethtool 7/7] build: add -Wextra to default CFLAGS Michal Kubecek
2020-08-10 14:22   ` Andrew Lunn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fb0a0177b4cb7d477ff964a64c9293f7267fdd5c.1597007533.git.mkubecek@suse.cz \
    --to=mkubecek@suse.cz \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).