diff options
author | Leah Rowe <leah@libreboot.org> | 2023-04-06 20:22:58 +0100 |
---|---|---|
committer | Leah Rowe <leah@libreboot.org> | 2023-04-06 20:22:58 +0100 |
commit | 8771551162844731cc843391ed645f387dfd0eb0 (patch) | |
tree | bc765adcb68764f229d7e55994f21cb096a05852 /util/nvmutil/nvmutil.c | |
parent | 9372ae3ddcb63377b1ab0b77e4db4086deef3244 (diff) |
util/nvmutil: remove duplicated logic
the byteswap() function is used for big endian host
compatibility, but it can also be used to swap words
in the stored mac address
Diffstat (limited to 'util/nvmutil/nvmutil.c')
-rw-r--r-- | util/nvmutil/nvmutil.c | 9 |
1 files changed, 1 insertions, 8 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index a58f66a1..508f76ee 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -189,19 +189,12 @@ cmd_setmac(const char *strMac) if (parseMacAddress(strMac, mac) == -1) err(errno = ECANCELED, "Bad MAC address"); - /* nvm words are little endian, *except* the mac address. swap bytes */ - for (int w = 0; w < 3; w++) { - uint8_t *b = (uint8_t *) &mac[w]; - b[0] ^= b[1]; - b[1] ^= b[0]; - b[0] ^= b[1]; - } - for (int partnum = 0; partnum < 2; partnum++) { if (!validChecksum(partnum)) continue; for (int w = 0; w < 3; w++) setWord(w, partnum, mac[w]); /* do not use memcpy! */ + byteswap(6, partnum); /* mac words are stored big-endian */ part = partnum; cmd_setchecksum(); } |