diff options
author | Jakub Kicinski <kuba@kernel.org> | 2021-10-07 04:06:58 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2021-10-07 15:39:51 +0300 |
commit | 8017c4d8173cfe086420dc5710d631cabd03ef67 (patch) | |
tree | c2bf02641bbbf8eef2b8bf3c2c494ecb9ffe57cf /net/ethernet | |
parent | 433baf0719d6a81d0587ea27545a120a3880abf6 (diff) | |
download | linux-8017c4d8173cfe086420dc5710d631cabd03ef67.tar.xz |
eth: fwnode: change the return type of mac address helpers
fwnode_get_mac_address() and device_get_mac_address()
return a pointer to the buffer that was passed to them
on success or NULL on failure. None of the callers
care about the actual value, only if it's NULL or not.
These semantics differ from of_get_mac_address() which
returns an int so to avoid confusion make the device
helpers return an errno.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ethernet')
-rw-r--r-- | net/ethernet/eth.c | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index 9ea45aae04ee..70692f5b514c 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c @@ -560,15 +560,21 @@ int nvmem_get_mac_address(struct device *dev, void *addrbuf) } EXPORT_SYMBOL(nvmem_get_mac_address); -static void *fwnode_get_mac_addr(struct fwnode_handle *fwnode, - const char *name, char *addr, - int alen) +static int fwnode_get_mac_addr(struct fwnode_handle *fwnode, + const char *name, char *addr, int alen) { - int ret = fwnode_property_read_u8_array(fwnode, name, addr, alen); + int ret; - if (ret == 0 && alen == ETH_ALEN && is_valid_ether_addr(addr)) - return addr; - return NULL; + if (alen != ETH_ALEN) + return -EINVAL; + + ret = fwnode_property_read_u8_array(fwnode, name, addr, alen); + if (ret) + return ret; + + if (!is_valid_ether_addr(addr)) + return -EINVAL; + return 0; } /** @@ -594,19 +600,14 @@ static void *fwnode_get_mac_addr(struct fwnode_handle *fwnode, * In this case, the real MAC is in 'local-mac-address', and 'mac-address' * exists but is all zeros. */ -void *fwnode_get_mac_address(struct fwnode_handle *fwnode, char *addr, int alen) +int fwnode_get_mac_address(struct fwnode_handle *fwnode, char *addr, int alen) { - char *res; - - res = fwnode_get_mac_addr(fwnode, "mac-address", addr, alen); - if (res) - return res; - - res = fwnode_get_mac_addr(fwnode, "local-mac-address", addr, alen); - if (res) - return res; + if (!fwnode_get_mac_addr(fwnode, "mac-address", addr, alen) || + !fwnode_get_mac_addr(fwnode, "local-mac-address", addr, alen) || + !fwnode_get_mac_addr(fwnode, "address", addr, alen)) + return 0; - return fwnode_get_mac_addr(fwnode, "address", addr, alen); + return -ENOENT; } EXPORT_SYMBOL(fwnode_get_mac_address); @@ -616,7 +617,7 @@ EXPORT_SYMBOL(fwnode_get_mac_address); * @addr: Address of buffer to store the MAC in * @alen: Length of the buffer pointed to by addr, should be ETH_ALEN */ -void *device_get_mac_address(struct device *dev, char *addr, int alen) +int device_get_mac_address(struct device *dev, char *addr, int alen) { return fwnode_get_mac_address(dev_fwnode(dev), addr, alen); } |