Skip to contentSkip to conversation

ethtool: fix uninitialized return value

PATCH In review Ivan Vecera 4 participants 9 messages Jun 8, 2018 – Jun 13, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/6 ethtool: fix uninitialized return value

Fixes b0fe96d ("Ethtool: Implements ETHTOOL_PHY_GTUNABLE/ETHTOOL_PHY_STUNABLE and PHY downshift")
---
 ethtool.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
ethtool.c +3 -4
index 2e87384..e7495fe 100644
@@ -4723,8 +4723,8 @@ static int do_get_phy_tunable(struct cmd_context *ctx)
 {
 	int argc = ctx->argc;
 	char **argp = ctx->argp;
-	int err, i;
 	u8 downshift_changed = 0;
+	int i;
 
 	if (argc < 1)
 		exit_bad_args();
@@ -4750,8 +4750,7 @@ static int do_get_phy_tunable(struct cmd_context *ctx)
 		cont.ds.id = ETHTOOL_PHY_DOWNSHIFT;
 		cont.ds.type_id = ETHTOOL_TUNABLE_U8;
 		cont.ds.len = 1;
-		err = send_ioctl(ctx, &cont.ds);
-		if (err < 0) {
+		if (send_ioctl(ctx, &cont.ds) < 0) {
 			perror("Cannot Get PHY downshift count");
 			return 87;
 		}
@@ -4762,7 +4761,7 @@ static int do_get_phy_tunable(struct cmd_context *ctx)
 			fprintf(stdout, "Downshift disabled\n");
 	}
 
-	return err;
+	return 0;
 }
 
 static __u32 parse_reset(char *val, __u32 bitset, char *arg, __u32 *data)
Signature · 1 line
2.16.4
#1 lore raw

PATCH 2/6 ethtool: fix RING_VF assignment

Fixes 36ee712 ("ethtool: support queue and VF fields for rxclass filters")
Cc Jacob Keller <[email protected]>
---
 rxclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rxclass.c +1 -1
index ce4b382..42d122d 100644
@@ -1066,7 +1066,7 @@ static int rxclass_get_val(char *str, unsigned char *p, u32 *flags,
 		val++;
 
 		*(u64 *)&p[opt->offset] &= ~ETHTOOL_RX_FLOW_SPEC_RING_VF;
-		*(u64 *)&p[opt->offset] = (u64)val << ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
+		*(u64 *)&p[opt->offset] |= (u64)val << ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
 		break;
 	}
 	case OPT_RING_QUEUE: {
Signature · 1 line
2.16.4
#2 lore raw

RE: [PATCH ethtool 2/6] ethtool: fix RING_VF assignment

Quoted 28 lines

-----Original Message-----
From: Ivan Vecera [mailto:[email protected]]
Sent: Friday, June 08, 2018 2:20 AM
To: [email protected]
Cc: [email protected]; Keller, Jacob E <[email protected]>
Subject: [PATCH ethtool 2/6] ethtool: fix RING_VF assignment

Fixes 36ee712 ("ethtool: support queue and VF fields for rxclass filters")
Cc Jacob Keller <[email protected]>
---
 rxclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rxclass.c +1 -1
index ce4b382..42d122d 100644
@@ -1066,7 +1066,7 @@ static int rxclass_get_val(char *str, unsigned char *p,
 u32 *flags,
 		val++;
 
 		*(u64 *)&p[opt->offset] &=
 ~ETHTOOL_RX_FLOW_SPEC_RING_VF;
-		*(u64 *)&p[opt->offset] = (u64)val <<
 ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
+		*(u64 *)&p[opt->offset] |= (u64)val <<

ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;

rxclass.c

Quoted 2 lines
rxclass.c +0 -0
 		break;
 	}

Hah. Good catch.

Thanks,
Jake

Quoted 3 lines

case OPT_RING_QUEUE: {
--
2.16.4

#3 lore raw

PATCH 3/6 ethtool: remove unused global variable

In reply to Ivan Vecera
Fixes 2c2ee7a ("ethtool: Add support for sfc register dumps")
---
 sfc.c | 3 ---
 1 file changed, 3 deletions(-)
sfc.c +0 -3
index 9478b38..b4c590f 100644
@@ -3083,9 +3083,6 @@ static const struct efx_nic_reg_field efx_nic_reg_fields_TX_PACE[] = {
 	REGISTER_FIELD_BZ(TX_PACE_SB_AF),
 	REGISTER_FIELD_BZ(TX_PACE_SB_NOT_AF),
 };
-static const struct efx_nic_reg_field efx_nic_reg_fields_TX_PACE_DROP_QID[] = {
-	REGISTER_FIELD_BZ(TX_PACE_QID_DRP_CNT),
-};
 static const struct efx_nic_reg_field efx_nic_reg_fields_TX_VLAN[] = {
 	REGISTER_FIELD_BB(TX_VLAN0),
 	REGISTER_FIELD_BB(TX_VLAN0_PORT0_EN),
Signature · 1 line
2.16.4
#4 lore raw

PATCH 4/6 ethtool: several fixes in do_gregs()

In reply to Ivan Vecera

- correctly close gregs_dump_file in case of fstat() failure
- check for error from realloc

Fixes be4c2d0 ("ethtool.c: fix dump_regs heap corruption")
Cc David Decotigny <[email protected]>
---
 ethtool.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
ethtool.c +10 -1
index e7495fe..2b90984 100644
@@ -3179,17 +3179,26 @@ static int do_gregs(struct cmd_context *ctx)
 	if (!gregs_dump_raw && gregs_dump_file != NULL) {
 		/* overwrite reg values from file dump */
 		FILE *f = fopen(gregs_dump_file, "r");
+		struct ethtool_regs *nregs;
 		struct stat st;
 		size_t nread;
 
 		if (!f || fstat(fileno(f), &st) < 0) {
 			fprintf(stderr, "Can't open '%s': %s\n",
 				gregs_dump_file, strerror(errno));
+			if (f)
+				fclose(f);
 			free(regs);
 			return 75;
 		}
 
-		regs = realloc(regs, sizeof(*regs) + st.st_size);
+		nregs = realloc(regs, sizeof(*regs) + st.st_size);
+		if (!nregs) {
+			perror("Cannot allocate memory for register dump");
+			free(regs); /* was not freed by realloc */
+			return 73;
+		}
+		regs = nregs;
 		regs->len = st.st_size;
 		nread = fread(regs->data, regs->len, 1, f);
 		fclose(f);
Signature · 1 line
2.16.4
#5 lore raw

PATCH 5/6 ethtool: correctly free hkey when get_stringset() fails

In reply to Ivan Vecera

Memory allocated for 'hkey' is not freed when get_stringset(..., ETH_SS_RSS_HASH_FUNCS...) fails.

Fixes b888f35 ("ethtool: Support for configurable RSS hash function")
Cc Gal Pressman <[email protected]>
---
 ethtool.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
ethtool.c +6 -7
index 2b90984..fb93ae8 100644
@@ -3910,7 +3910,7 @@ static int do_srxfhindir(struct cmd_context *ctx, int rxfhindir_default,
 static int do_srxfh(struct cmd_context *ctx)
 {
 	struct ethtool_rxfh rss_head = {0};
-	struct ethtool_rxfh *rss;
+	struct ethtool_rxfh *rss = NULL;
 	struct ethtool_rxnfc ring_count;
 	int rxfhindir_equal = 0, rxfhindir_default = 0;
 	struct ethtool_gstrings *hfuncs = NULL;
@@ -4064,7 +4064,8 @@ static int do_srxfh(struct cmd_context *ctx)
 		hfuncs = get_stringset(ctx, ETH_SS_RSS_HASH_FUNCS, 0, 1);
 		if (!hfuncs) {
 			perror("Cannot get hash functions names");
-			return 1;
+			err = 1;
+			goto free;
 		}
 
 		for (i = 0; i < hfuncs->len && !req_hfunc ; i++) {
@@ -4078,8 +4079,8 @@ static int do_srxfh(struct cmd_context *ctx)
 		if (!req_hfunc) {
 			fprintf(stderr,
 				"Unknown hash function: %s\n", req_hfunc_name);
-			free(hfuncs);
-			return 1;
+			err = 1;
+			goto free;
 		}
 	}
 
@@ -4120,9 +4121,7 @@ static int do_srxfh(struct cmd_context *ctx)
 	}
 
 free:
-	if (hkey)
-		free(hkey);
-
+	free(hkey);
 	free(rss);
 	free(hfuncs);
 	return err;
Signature · 1 line
2.16.4
#6 lore raw

Re: [PATCH ethtool 5/6] ethtool: correctly free hkey when get_stringset() fails

Quoted 4 lines · Ivan Vecera

Memory allocated for 'hkey' is not freed when get_stringset(..., ETH_SS_RSS_HASH_FUNCS...) fails.

Fixes b888f35 ("ethtool: Support for configurable RSS hash function")

Thanks for fixing this!
Please use the first 12 characters of the sha1 in the Fixes line.

Quoted 52 lines
---
 ethtool.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
ethtool.c +6 -7
index 2b90984..fb93ae8 100644
@@ -3910,7 +3910,7 @@ static int do_srxfhindir(struct cmd_context *ctx, int rxfhindir_default,
 static int do_srxfh(struct cmd_context *ctx)
 {
 	struct ethtool_rxfh rss_head = {0};
-	struct ethtool_rxfh *rss;
+	struct ethtool_rxfh *rss = NULL;
 	struct ethtool_rxnfc ring_count;
 	int rxfhindir_equal = 0, rxfhindir_default = 0;
 	struct ethtool_gstrings *hfuncs = NULL;
@@ -4064,7 +4064,8 @@ static int do_srxfh(struct cmd_context *ctx)
 		hfuncs = get_stringset(ctx, ETH_SS_RSS_HASH_FUNCS, 0, 1);
 		if (!hfuncs) {
 			perror("Cannot get hash functions names");
-			return 1;
+			err = 1;
+			goto free;
 		}
 
 		for (i = 0; i < hfuncs->len && !req_hfunc ; i++) {
@@ -4078,8 +4079,8 @@ static int do_srxfh(struct cmd_context *ctx)
 		if (!req_hfunc) {
 			fprintf(stderr,
 				"Unknown hash function: %s\n", req_hfunc_name);
-			free(hfuncs);
-			return 1;
+			err = 1;
+			goto free;
 		}
 	}
 
@@ -4120,9 +4121,7 @@ static int do_srxfh(struct cmd_context *ctx)
 	}
 
 free:
-	if (hkey)
-		free(hkey);
-
+	free(hkey);
 	free(rss);
 	free(hfuncs);
 	return err;
#7 lore raw

PATCH 6/6 ethtool: remove unreachable code

In reply to Ivan Vecera

The default switch case is unreachable as the MAX_CHANNEL_NUM == 4.

Fixes a5e73bb ("ethtool:QSFP Plus/QSFP28 Diagnostics Information Support")
Cc Vidya Sagar Ravipati <[email protected]>
---
 qsfp.c | 3 ---
 1 file changed, 3 deletions(-)
qsfp.c +0 -3
index aecd5bb..32e195d 100644
@@ -661,9 +661,6 @@ static void sff8636_dom_parse(const __u8 *id, struct sff_diags *sd)
 			tx_power_offset = SFF8636_TX_PWR_4_OFFSET;
 			tx_bias_offset = SFF8636_TX_BIAS_4_OFFSET;
 			break;
-		default:
-			printf(" Invalid channel: %d\n", i);
-			break;
 		}
 		sd->scd[i].bias_cur = OFFSET_TO_U16(tx_bias_offset);
 		sd->scd[i].rx_power = OFFSET_TO_U16(rx_power_offset);
Signature · 1 line
2.16.4