From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, gregkh@linuxfoundation.org,
rafael@kernel.org, saravanak@google.com, mw@semihalf.com,
andrew@lunn.ch, jeremy.linton@arm.com, hkallweit1@gmail.com,
linux@armlinux.org.uk, robh+dt@kernel.org,
frowand.list@gmail.com, heikki.krogerus@linux.intel.com,
devicetree@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next v2 5/9] eth: fwnode: change the return type of mac address helpers
Date: Wed, 6 Oct 2021 08:44:22 -0700 [thread overview]
Message-ID: <20211006154426.3222199-6-kuba@kernel.org> (raw)
In-Reply-To: <20211006154426.3222199-1-kuba@kernel.org>
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>
---
v2: new patch
---
drivers/net/ethernet/apm/xgene-v2/main.c | 2 +-
.../net/ethernet/apm/xgene/xgene_enet_main.c | 2 +-
.../net/ethernet/broadcom/genet/bcmgenet.c | 2 +-
.../net/ethernet/cavium/thunder/thunder_bgx.c | 6 +--
drivers/net/ethernet/faraday/ftgmac100.c | 4 +-
drivers/net/ethernet/hisilicon/hns/hns_enet.c | 2 +-
.../net/ethernet/marvell/mvpp2/mvpp2_main.c | 2 +-
drivers/net/ethernet/microchip/enc28j60.c | 2 +-
drivers/net/ethernet/qualcomm/emac/emac.c | 2 +-
drivers/net/ethernet/socionext/netsec.c | 10 ++---
include/linux/etherdevice.h | 5 +--
net/ethernet/eth.c | 39 ++++++++++---------
12 files changed, 38 insertions(+), 40 deletions(-)
diff --git a/drivers/net/ethernet/apm/xgene-v2/main.c b/drivers/net/ethernet/apm/xgene-v2/main.c
index 80399c8980bd..c7253ecc0fa5 100644
--- a/drivers/net/ethernet/apm/xgene-v2/main.c
+++ b/drivers/net/ethernet/apm/xgene-v2/main.c
@@ -36,7 +36,7 @@ static int xge_get_resources(struct xge_pdata *pdata)
return -ENOMEM;
}
- if (!device_get_mac_address(dev, ndev->dev_addr, ETH_ALEN))
+ if (device_get_mac_address(dev, ndev->dev_addr, ETH_ALEN))
eth_hw_addr_random(ndev);
memcpy(ndev->perm_addr, ndev->dev_addr, ndev->addr_len);
diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c
index 5f1fc6582d74..268e099aa5e1 100644
--- a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c
+++ b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c
@@ -1731,7 +1731,7 @@ static int xgene_enet_get_resources(struct xgene_enet_pdata *pdata)
xgene_get_port_id_acpi(dev, pdata);
#endif
- if (!device_get_mac_address(dev, ndev->dev_addr, ETH_ALEN))
+ if (device_get_mac_address(dev, ndev->dev_addr, ETH_ALEN))
eth_hw_addr_random(ndev);
memcpy(ndev->perm_addr, ndev->dev_addr, ndev->addr_len);
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index 02fe98cbabb0..30c5dcaea802 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -4084,7 +4084,7 @@ static int bcmgenet_probe(struct platform_device *pdev)
if (pd && !IS_ERR_OR_NULL(pd->mac_address))
eth_hw_addr_set(dev, pd->mac_address);
else
- if (!device_get_mac_address(&pdev->dev, dev->dev_addr, ETH_ALEN))
+ if (device_get_mac_address(&pdev->dev, dev->dev_addr, ETH_ALEN))
if (has_acpi_companion(&pdev->dev))
bcmgenet_get_hw_addr(priv, dev->dev_addr);
diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
index db66d4beb28a..77ce81633cdc 100644
--- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
+++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
@@ -1387,10 +1387,10 @@ static int acpi_get_mac_address(struct device *dev, struct acpi_device *adev,
u8 *dst)
{
u8 mac[ETH_ALEN];
- u8 *addr;
+ int ret;
- addr = fwnode_get_mac_address(acpi_fwnode_handle(adev), mac, ETH_ALEN);
- if (!addr) {
+ ret = fwnode_get_mac_address(acpi_fwnode_handle(adev), mac, ETH_ALEN);
+ if (ret) {
dev_err(dev, "MAC address invalid: %pM\n", mac);
return -EINVAL;
}
diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
index ab9267225573..8de9c99a18fb 100644
--- a/drivers/net/ethernet/faraday/ftgmac100.c
+++ b/drivers/net/ethernet/faraday/ftgmac100.c
@@ -182,10 +182,8 @@ static void ftgmac100_initial_mac(struct ftgmac100 *priv)
u8 mac[ETH_ALEN];
unsigned int m;
unsigned int l;
- void *addr;
- addr = device_get_mac_address(priv->dev, mac, ETH_ALEN);
- if (addr) {
+ if (!device_get_mac_address(priv->dev, mac, ETH_ALEN)) {
eth_hw_addr_set(priv->netdev, mac);
dev_info(priv->dev, "Read MAC address %pM from device tree\n",
mac);
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index 2c4801e49aa1..12b916399ba7 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -1212,7 +1212,7 @@ static void hns_init_mac_addr(struct net_device *ndev)
{
struct hns_nic_priv *priv = netdev_priv(ndev);
- if (!device_get_mac_address(priv->dev, ndev->dev_addr, ETH_ALEN)) {
+ if (device_get_mac_address(priv->dev, ndev->dev_addr, ETH_ALEN)) {
eth_hw_addr_random(ndev);
dev_warn(priv->dev, "No valid mac, use random mac %pM",
ndev->dev_addr);
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 3197526455d9..b84f8b6fe9f4 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -6081,7 +6081,7 @@ static void mvpp2_port_copy_mac_addr(struct net_device *dev, struct mvpp2 *priv,
char hw_mac_addr[ETH_ALEN] = {0};
char fw_mac_addr[ETH_ALEN];
- if (fwnode_get_mac_address(fwnode, fw_mac_addr, ETH_ALEN)) {
+ if (!fwnode_get_mac_address(fwnode, fw_mac_addr, ETH_ALEN)) {
*mac_from = "firmware node";
eth_hw_addr_set(dev, fw_mac_addr);
return;
diff --git a/drivers/net/ethernet/microchip/enc28j60.c b/drivers/net/ethernet/microchip/enc28j60.c
index bf77e8adffbf..fa62311d326a 100644
--- a/drivers/net/ethernet/microchip/enc28j60.c
+++ b/drivers/net/ethernet/microchip/enc28j60.c
@@ -1572,7 +1572,7 @@ static int enc28j60_probe(struct spi_device *spi)
goto error_irq;
}
- if (device_get_mac_address(&spi->dev, macaddr, sizeof(macaddr)))
+ if (!device_get_mac_address(&spi->dev, macaddr, sizeof(macaddr)))
eth_hw_addr_set(dev, macaddr);
else
eth_hw_addr_random(dev);
diff --git a/drivers/net/ethernet/qualcomm/emac/emac.c b/drivers/net/ethernet/qualcomm/emac/emac.c
index fbfabfc5cc51..2e913508fbeb 100644
--- a/drivers/net/ethernet/qualcomm/emac/emac.c
+++ b/drivers/net/ethernet/qualcomm/emac/emac.c
@@ -549,7 +549,7 @@ static int emac_probe_resources(struct platform_device *pdev,
int ret = 0;
/* get mac address */
- if (device_get_mac_address(&pdev->dev, maddr, ETH_ALEN))
+ if (!device_get_mac_address(&pdev->dev, maddr, ETH_ALEN))
eth_hw_addr_set(netdev, maddr);
else
eth_hw_addr_random(netdev);
diff --git a/drivers/net/ethernet/socionext/netsec.c b/drivers/net/ethernet/socionext/netsec.c
index c7e56dc0a494..f8dd7fa5f632 100644
--- a/drivers/net/ethernet/socionext/netsec.c
+++ b/drivers/net/ethernet/socionext/netsec.c
@@ -1978,10 +1978,10 @@ static int netsec_register_mdio(struct netsec_priv *priv, u32 phy_addr)
static int netsec_probe(struct platform_device *pdev)
{
struct resource *mmio_res, *eeprom_res, *irq_res;
- u8 *mac, macbuf[ETH_ALEN];
struct netsec_priv *priv;
u32 hw_ver, phy_addr = 0;
struct net_device *ndev;
+ u8 macbuf[ETH_ALEN];
int ret;
mmio_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -2034,12 +2034,12 @@ static int netsec_probe(struct platform_device *pdev)
goto free_ndev;
}
- mac = device_get_mac_address(&pdev->dev, macbuf, sizeof(macbuf));
- if (mac)
- eth_hw_addr_set(ndev, mac);
+ ret = device_get_mac_address(&pdev->dev, macbuf, sizeof(macbuf));
+ if (!ret)
+ eth_hw_addr_set(ndev, macbuf);
if (priv->eeprom_base &&
- (!mac || !is_valid_ether_addr(ndev->dev_addr))) {
+ (ret || !is_valid_ether_addr(ndev->dev_addr))) {
void __iomem *macp = priv->eeprom_base +
NETSEC_EEPROM_MAC_ADDRESS;
diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index b3b6591d84c6..70f03f48ff06 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -31,9 +31,8 @@ struct fwnode_handle;
int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr);
unsigned char *arch_get_platform_mac_address(void);
int nvmem_get_mac_address(struct device *dev, void *addrbuf);
-void *device_get_mac_address(struct device *dev, char *addr, int alen);
-void *fwnode_get_mac_address(struct fwnode_handle *fwnode,
- char *addr, int alen);
+int device_get_mac_address(struct device *dev, char *addr, int alen);
+int fwnode_get_mac_address(struct fwnode_handle *fwnode, char *addr, int alen);
u32 eth_get_headlen(const struct net_device *dev, const void *data, u32 len);
__be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev);
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);
}
--
2.31.1
next prev parent reply other threads:[~2021-10-06 15:45 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-06 15:44 [PATCH net-next v2 0/9] net: add a helpers for loading netdev->dev_addr from FW Jakub Kicinski
2021-10-06 15:44 ` [PATCH net-next v2 1/9] of: net: move of_net under net/ Jakub Kicinski
2021-10-06 16:18 ` Rob Herring
2021-10-06 16:34 ` Andrew Lunn
2021-10-06 16:58 ` Rob Herring
2021-10-06 17:12 ` Jakub Kicinski
2021-10-06 19:02 ` Rob Herring
2021-10-06 19:49 ` Jakub Kicinski
2021-10-06 15:44 ` [PATCH net-next v2 2/9] of: net: add a helper for loading netdev->dev_addr Jakub Kicinski
2021-10-06 15:44 ` [PATCH net-next v2 3/9] ethernet: use of_get_ethdev_address() Jakub Kicinski
2021-10-06 15:44 ` [PATCH net-next v2 4/9] device property: move mac addr helpers to eth.c Jakub Kicinski
2021-10-06 16:06 ` Greg KH
2021-10-06 15:44 ` Jakub Kicinski [this message]
2021-10-06 15:44 ` [PATCH net-next v2 6/9] eth: fwnode: remove the addr len from mac helpers Jakub Kicinski
2021-10-06 15:44 ` [PATCH net-next v2 7/9] eth: fwnode: add a helper for loading netdev->dev_addr Jakub Kicinski
2021-10-06 18:13 ` Shannon Nelson
2021-10-06 15:44 ` [PATCH net-next v2 8/9] ethernet: use device_get_ethdev_address() Jakub Kicinski
2021-10-06 15:44 ` [PATCH net-next v2 9/9] ethernet: make more use of device_get_ethdev_address() Jakub Kicinski
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=20211006154426.3222199-6-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=frowand.list@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=hkallweit1@gmail.com \
--cc=jeremy.linton@arm.com \
--cc=linux@armlinux.org.uk \
--cc=mw@semihalf.com \
--cc=netdev@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=robh+dt@kernel.org \
--cc=saravanak@google.com \
/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).