aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Moń <tomasz.mon@camlingroup.com>2022-08-19 12:10:49 +0200
committerMichal Kubecek <mkubecek@suse.cz>2022-08-22 01:02:36 +0200
commit95a8d982f1591335cfe6735faa58b65906d871bc (patch)
treef091b1438df1a5b8419532992c0566b6f7eb669b
parent38f5c9a67b957838e43d9dc6305774199e83efe0 (diff)
downloadethtool-95a8d982f1591335cfe6735faa58b65906d871bc.tar.gz
ethtool: fix EEPROM byte write
ethtool since version 1.8 supports EEPROM byte write: # ethtool -E DEVNAME [ magic N ] [ offset N ] [ value N ] ethtool 2.6.33 added EEPROM block write: # ethtool -E ethX [ magic N ] [ offset N ] [ length N ] [ value N ] EEPROM block write introduced in 2.6.33 is backwards compatible, i.e. when value is specified the length is forced to 1 (commandline length value is ignored). The byte write behaviour changed in ethtool 5.9 where the value write only works when value parameter is specified together with length 1. While byte writes to any offset other than 0, without length 1, simply fail with "offset & length out of bounds" error message, writing value to offset 0 basically erased whole EEPROM. That is, the provided byte value was written at offset 0, but the rest of the EEPROM was set to 0. Fix the issue by setting length to 1 when value is specified and length is omitted. Exit with error if length is specified to value other than 1 and value is specified. Fixes: 923c3f51c444 ("ioctl: check presence of eeprom length argument properly") Signed-off-by: Tomasz Moń <tomasz.mon@camlingroup.com>
-rw-r--r--ethtool.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/ethtool.c b/ethtool.c
index 89613ca..7b400da 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -3529,12 +3529,16 @@ static int do_seeprom(struct cmd_context *ctx)
return 74;
}
- if (seeprom_value_seen)
+ if (seeprom_value_seen && !seeprom_length_seen)
seeprom_length = 1;
-
- if (!seeprom_length_seen)
+ else if (!seeprom_length_seen)
seeprom_length = drvinfo.eedump_len;
+ if (seeprom_value_seen && (seeprom_length != 1)) {
+ fprintf(stderr, "value requires length 1\n");
+ return 1;
+ }
+
if (drvinfo.eedump_len < seeprom_offset + seeprom_length) {
fprintf(stderr, "offset & length out of bounds\n");
return 1;