Commit 9593dc35 authored by David S. Miller's avatar David S. Miller

Merge branch 'of_get_mac_address-fixes'

Petr Štetiar says:

====================
of_get_mac_address fixes

this patch series is hopefuly the last series of the fixes which are related
to the introduction of NVMEM support into of_get_mac_address.

First patch is removing `nvmem-mac-address` property which was wrong idea as
I've allocated the property with devm_kzalloc and then added it to DT, so then
2 entities would be refcounting the allocation.  So if the driver unbinds, the
buffer is freed, but DT code would be still referencing that memory.

Second patch fixes some unwanted references to the Linux API in the DT
bindings documentation.

Patches 3-5 should hopefully make compilers and thus kbuild test robot happy.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 0655f994 1b9705d9
...@@ -139,9 +139,9 @@ Optional properties: ...@@ -139,9 +139,9 @@ Optional properties:
sub-module attached to this interface. sub-module attached to this interface.
The MAC address will be determined using the optional properties defined in The MAC address will be determined using the optional properties defined in
ethernet.txt, as provided by the of_get_mac_address API and only if efuse-mac ethernet.txt and only if efuse-mac is set to 0. If all of the optional MAC
is set to 0. If any of the optional MAC address properties are not present, address properties are not present, then the driver will use a random MAC
then the driver will use random MAC address. address.
Example binding: Example binding:
......
...@@ -16,8 +16,8 @@ Optional properties: ...@@ -16,8 +16,8 @@ Optional properties:
- ieee80211-freq-limit: See ieee80211.txt - ieee80211-freq-limit: See ieee80211.txt
- mediatek,mtd-eeprom: Specify a MTD partition + offset containing EEPROM data - mediatek,mtd-eeprom: Specify a MTD partition + offset containing EEPROM data
The driver is using of_get_mac_address API, so the MAC address can be as well The MAC address can as well be set with corresponding optional properties
be set with corresponding optional properties defined in net/ethernet.txt. defined in net/ethernet.txt.
Optional nodes: Optional nodes:
- led: Properties for a connected LED - led: Properties for a connected LED
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/export.h> #include <linux/export.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/etherdevice.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/of_net.h> #include <linux/of_net.h>
#include <asm/tsi108.h> #include <asm/tsi108.h>
...@@ -106,7 +107,7 @@ static int __init tsi108_eth_of_init(void) ...@@ -106,7 +107,7 @@ static int __init tsi108_eth_of_init(void)
mac_addr = of_get_mac_address(np); mac_addr = of_get_mac_address(np);
if (!IS_ERR(mac_addr)) if (!IS_ERR(mac_addr))
memcpy(tsi_eth_data.mac_addr, mac_addr, 6); ether_addr_copy(tsi_eth_data.mac_addr, mac_addr);
ph = of_get_property(np, "mdio-handle", NULL); ph = of_get_property(np, "mdio-handle", NULL);
mdio = of_find_node_by_phandle(*ph); mdio = of_find_node_by_phandle(*ph);
......
...@@ -871,7 +871,7 @@ static int emac_probe(struct platform_device *pdev) ...@@ -871,7 +871,7 @@ static int emac_probe(struct platform_device *pdev)
/* Read MAC-address from DT */ /* Read MAC-address from DT */
mac_addr = of_get_mac_address(np); mac_addr = of_get_mac_address(np);
if (!IS_ERR(mac_addr)) if (!IS_ERR(mac_addr))
memcpy(ndev->dev_addr, mac_addr, ETH_ALEN); ether_addr_copy(ndev->dev_addr, mac_addr);
/* Check if the MAC address is valid, if not get a random one */ /* Check if the MAC address is valid, if not get a random one */
if (!is_valid_ether_addr(ndev->dev_addr)) { if (!is_valid_ether_addr(ndev->dev_addr)) {
......
...@@ -961,7 +961,7 @@ int arc_emac_probe(struct net_device *ndev, int interface) ...@@ -961,7 +961,7 @@ int arc_emac_probe(struct net_device *ndev, int interface)
mac_addr = of_get_mac_address(dev->of_node); mac_addr = of_get_mac_address(dev->of_node);
if (!IS_ERR(mac_addr)) if (!IS_ERR(mac_addr))
memcpy(ndev->dev_addr, mac_addr, ETH_ALEN); ether_addr_copy(ndev->dev_addr, mac_addr);
else else
eth_hw_addr_random(ndev); eth_hw_addr_random(ndev);
......
...@@ -1504,7 +1504,7 @@ static int octeon_mgmt_probe(struct platform_device *pdev) ...@@ -1504,7 +1504,7 @@ static int octeon_mgmt_probe(struct platform_device *pdev)
mac = of_get_mac_address(pdev->dev.of_node); mac = of_get_mac_address(pdev->dev.of_node);
if (!IS_ERR(mac)) if (!IS_ERR(mac))
memcpy(netdev->dev_addr, mac, ETH_ALEN); ether_addr_copy(netdev->dev_addr, mac);
else else
eth_hw_addr_random(netdev); eth_hw_addr_random(netdev);
......
...@@ -1413,7 +1413,7 @@ static struct dm9000_plat_data *dm9000_parse_dt(struct device *dev) ...@@ -1413,7 +1413,7 @@ static struct dm9000_plat_data *dm9000_parse_dt(struct device *dev)
mac_addr = of_get_mac_address(np); mac_addr = of_get_mac_address(np);
if (!IS_ERR(mac_addr)) if (!IS_ERR(mac_addr))
memcpy(pdata->dev_addr, mac_addr, sizeof(pdata->dev_addr)); ether_addr_copy(pdata->dev_addr, mac_addr);
return pdata; return pdata;
} }
......
...@@ -903,7 +903,7 @@ static int mpc52xx_fec_probe(struct platform_device *op) ...@@ -903,7 +903,7 @@ static int mpc52xx_fec_probe(struct platform_device *op)
*/ */
mac_addr = of_get_mac_address(np); mac_addr = of_get_mac_address(np);
if (!IS_ERR(mac_addr)) { if (!IS_ERR(mac_addr)) {
memcpy(ndev->dev_addr, mac_addr, ETH_ALEN); ether_addr_copy(ndev->dev_addr, mac_addr);
} else { } else {
struct mpc52xx_fec __iomem *fec = priv->fec; struct mpc52xx_fec __iomem *fec = priv->fec;
......
...@@ -729,7 +729,7 @@ static int mac_probe(struct platform_device *_of_dev) ...@@ -729,7 +729,7 @@ static int mac_probe(struct platform_device *_of_dev)
err = -EINVAL; err = -EINVAL;
goto _return_of_get_parent; goto _return_of_get_parent;
} }
memcpy(mac_dev->addr, mac_addr, sizeof(mac_dev->addr)); ether_addr_copy(mac_dev->addr, mac_addr);
/* Get the port handles */ /* Get the port handles */
nph = of_count_phandle_with_args(mac_node, "fsl,fman-ports", NULL); nph = of_count_phandle_with_args(mac_node, "fsl,fman-ports", NULL);
......
...@@ -1015,7 +1015,7 @@ static int fs_enet_probe(struct platform_device *ofdev) ...@@ -1015,7 +1015,7 @@ static int fs_enet_probe(struct platform_device *ofdev)
mac_addr = of_get_mac_address(ofdev->dev.of_node); mac_addr = of_get_mac_address(ofdev->dev.of_node);
if (!IS_ERR(mac_addr)) if (!IS_ERR(mac_addr))
memcpy(ndev->dev_addr, mac_addr, ETH_ALEN); ether_addr_copy(ndev->dev_addr, mac_addr);
ret = fep->ops->allocate_bd(ndev); ret = fep->ops->allocate_bd(ndev);
if (ret) if (ret)
......
...@@ -873,7 +873,7 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev) ...@@ -873,7 +873,7 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)
mac_addr = of_get_mac_address(np); mac_addr = of_get_mac_address(np);
if (!IS_ERR(mac_addr)) if (!IS_ERR(mac_addr))
memcpy(dev->dev_addr, mac_addr, ETH_ALEN); ether_addr_copy(dev->dev_addr, mac_addr);
if (model && !strcasecmp(model, "TSEC")) if (model && !strcasecmp(model, "TSEC"))
priv->device_flags |= FSL_GIANFAR_DEV_HAS_GIGABIT | priv->device_flags |= FSL_GIANFAR_DEV_HAS_GIGABIT |
......
...@@ -3911,7 +3911,7 @@ static int ucc_geth_probe(struct platform_device* ofdev) ...@@ -3911,7 +3911,7 @@ static int ucc_geth_probe(struct platform_device* ofdev)
mac_addr = of_get_mac_address(np); mac_addr = of_get_mac_address(np);
if (!IS_ERR(mac_addr)) if (!IS_ERR(mac_addr))
memcpy(dev->dev_addr, mac_addr, ETH_ALEN); ether_addr_copy(dev->dev_addr, mac_addr);
ugeth->ug_info = ug_info; ugeth->ug_info = ug_info;
ugeth->dev = device; ugeth->dev = device;
......
...@@ -2750,7 +2750,7 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev, ...@@ -2750,7 +2750,7 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,
mac_addr = of_get_mac_address(pnp); mac_addr = of_get_mac_address(pnp);
if (!IS_ERR(mac_addr)) if (!IS_ERR(mac_addr))
memcpy(ppd.mac_addr, mac_addr, ETH_ALEN); ether_addr_copy(ppd.mac_addr, mac_addr);
mv643xx_eth_property(pnp, "tx-queue-size", ppd.tx_queue_size); mv643xx_eth_property(pnp, "tx-queue-size", ppd.tx_queue_size);
mv643xx_eth_property(pnp, "tx-sram-addr", ppd.tx_sram_addr); mv643xx_eth_property(pnp, "tx-sram-addr", ppd.tx_sram_addr);
......
...@@ -4565,7 +4565,7 @@ static int mvneta_probe(struct platform_device *pdev) ...@@ -4565,7 +4565,7 @@ static int mvneta_probe(struct platform_device *pdev)
dt_mac_addr = of_get_mac_address(dn); dt_mac_addr = of_get_mac_address(dn);
if (!IS_ERR(dt_mac_addr)) { if (!IS_ERR(dt_mac_addr)) {
mac_from = "device tree"; mac_from = "device tree";
memcpy(dev->dev_addr, dt_mac_addr, ETH_ALEN); ether_addr_copy(dev->dev_addr, dt_mac_addr);
} else { } else {
mvneta_get_mac_addr(pp, hw_mac_addr); mvneta_get_mac_addr(pp, hw_mac_addr);
if (is_valid_ether_addr(hw_mac_addr)) { if (is_valid_ether_addr(hw_mac_addr)) {
......
...@@ -4805,7 +4805,7 @@ static struct net_device *sky2_init_netdev(struct sky2_hw *hw, unsigned port, ...@@ -4805,7 +4805,7 @@ static struct net_device *sky2_init_netdev(struct sky2_hw *hw, unsigned port,
*/ */
iap = of_get_mac_address(hw->pdev->dev.of_node); iap = of_get_mac_address(hw->pdev->dev.of_node);
if (!IS_ERR(iap)) if (!IS_ERR(iap))
memcpy(dev->dev_addr, iap, ETH_ALEN); ether_addr_copy(dev->dev_addr, iap);
else else
memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port * 8, memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port * 8,
ETH_ALEN); ETH_ALEN);
......
...@@ -426,7 +426,7 @@ static void ks8851_init_mac(struct ks8851_net *ks) ...@@ -426,7 +426,7 @@ static void ks8851_init_mac(struct ks8851_net *ks)
mac_addr = of_get_mac_address(ks->spidev->dev.of_node); mac_addr = of_get_mac_address(ks->spidev->dev.of_node);
if (!IS_ERR(mac_addr)) { if (!IS_ERR(mac_addr)) {
memcpy(dev->dev_addr, mac_addr, ETH_ALEN); ether_addr_copy(dev->dev_addr, mac_addr);
ks8851_write_mac_addr(dev); ks8851_write_mac_addr(dev);
return; return;
} }
......
...@@ -1328,7 +1328,7 @@ static int ks8851_probe(struct platform_device *pdev) ...@@ -1328,7 +1328,7 @@ static int ks8851_probe(struct platform_device *pdev)
if (pdev->dev.of_node) { if (pdev->dev.of_node) {
mac = of_get_mac_address(pdev->dev.of_node); mac = of_get_mac_address(pdev->dev.of_node);
if (!IS_ERR(mac)) if (!IS_ERR(mac))
memcpy(ks->mac_addr, mac, ETH_ALEN); ether_addr_copy(ks->mac_addr, mac);
} else { } else {
struct ks8851_mll_platform_data *pdata; struct ks8851_mll_platform_data *pdata;
......
...@@ -1369,7 +1369,7 @@ static int lpc_eth_drv_probe(struct platform_device *pdev) ...@@ -1369,7 +1369,7 @@ static int lpc_eth_drv_probe(struct platform_device *pdev)
if (!is_valid_ether_addr(ndev->dev_addr)) { if (!is_valid_ether_addr(ndev->dev_addr)) {
const char *macaddr = of_get_mac_address(np); const char *macaddr = of_get_mac_address(np);
if (!IS_ERR(macaddr)) if (!IS_ERR(macaddr))
memcpy(ndev->dev_addr, macaddr, ETH_ALEN); ether_addr_copy(ndev->dev_addr, macaddr);
} }
if (!is_valid_ether_addr(ndev->dev_addr)) if (!is_valid_ether_addr(ndev->dev_addr))
eth_hw_addr_random(ndev); eth_hw_addr_random(ndev);
......
...@@ -3193,7 +3193,7 @@ static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev) ...@@ -3193,7 +3193,7 @@ static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev)
mac_addr = of_get_mac_address(np); mac_addr = of_get_mac_address(np);
if (!IS_ERR(mac_addr)) if (!IS_ERR(mac_addr))
memcpy(pdata->mac_addr, mac_addr, ETH_ALEN); ether_addr_copy(pdata->mac_addr, mac_addr);
pdata->no_ether_link = pdata->no_ether_link =
of_property_read_bool(np, "renesas,no-ether-link"); of_property_read_bool(np, "renesas,no-ether-link");
......
...@@ -2233,7 +2233,7 @@ static int cpsw_probe_dt(struct cpsw_platform_data *data, ...@@ -2233,7 +2233,7 @@ static int cpsw_probe_dt(struct cpsw_platform_data *data,
no_phy_slave: no_phy_slave:
mac_addr = of_get_mac_address(slave_node); mac_addr = of_get_mac_address(slave_node);
if (!IS_ERR(mac_addr)) { if (!IS_ERR(mac_addr)) {
memcpy(slave_data->mac_addr, mac_addr, ETH_ALEN); ether_addr_copy(slave_data->mac_addr, mac_addr);
} else { } else {
ret = ti_cm_get_macid(&pdev->dev, i, ret = ti_cm_get_macid(&pdev->dev, i,
slave_data->mac_addr); slave_data->mac_addr);
......
...@@ -361,7 +361,7 @@ static void temac_do_set_mac_address(struct net_device *ndev) ...@@ -361,7 +361,7 @@ static void temac_do_set_mac_address(struct net_device *ndev)
static int temac_init_mac_address(struct net_device *ndev, const void *address) static int temac_init_mac_address(struct net_device *ndev, const void *address)
{ {
memcpy(ndev->dev_addr, address, ETH_ALEN); ether_addr_copy(ndev->dev_addr, address);
if (!is_valid_ether_addr(ndev->dev_addr)) if (!is_valid_ether_addr(ndev->dev_addr))
eth_hw_addr_random(ndev); eth_hw_addr_random(ndev);
temac_do_set_mac_address(ndev); temac_do_set_mac_address(ndev);
......
...@@ -1167,7 +1167,7 @@ static int xemaclite_of_probe(struct platform_device *ofdev) ...@@ -1167,7 +1167,7 @@ static int xemaclite_of_probe(struct platform_device *ofdev)
if (!IS_ERR(mac_address)) { if (!IS_ERR(mac_address)) {
/* Set the MAC address. */ /* Set the MAC address. */
memcpy(ndev->dev_addr, mac_address, ETH_ALEN); ether_addr_copy(ndev->dev_addr, mac_address);
} else { } else {
dev_warn(dev, "No MAC address found, using random\n"); dev_warn(dev, "No MAC address found, using random\n");
eth_hw_addr_random(ndev); eth_hw_addr_random(ndev);
......
...@@ -95,7 +95,7 @@ mt76_eeprom_override(struct mt76_dev *dev) ...@@ -95,7 +95,7 @@ mt76_eeprom_override(struct mt76_dev *dev)
mac = of_get_mac_address(np); mac = of_get_mac_address(np);
if (!IS_ERR(mac)) if (!IS_ERR(mac))
memcpy(dev->macaddr, mac, ETH_ALEN); ether_addr_copy(dev->macaddr, mac);
#endif #endif
if (!is_valid_ether_addr(dev->macaddr)) { if (!is_valid_ether_addr(dev->macaddr)) {
......
...@@ -52,39 +52,22 @@ static const void *of_get_mac_addr(struct device_node *np, const char *name) ...@@ -52,39 +52,22 @@ static const void *of_get_mac_addr(struct device_node *np, const char *name)
static const void *of_get_mac_addr_nvmem(struct device_node *np) static const void *of_get_mac_addr_nvmem(struct device_node *np)
{ {
int ret; int ret;
u8 mac[ETH_ALEN]; const void *mac;
struct property *pp; u8 nvmem_mac[ETH_ALEN];
struct platform_device *pdev = of_find_device_by_node(np); struct platform_device *pdev = of_find_device_by_node(np);
if (!pdev) if (!pdev)
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
ret = nvmem_get_mac_address(&pdev->dev, &mac); ret = nvmem_get_mac_address(&pdev->dev, &nvmem_mac);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
pp = devm_kzalloc(&pdev->dev, sizeof(*pp), GFP_KERNEL); mac = devm_kmemdup(&pdev->dev, nvmem_mac, ETH_ALEN, GFP_KERNEL);
if (!pp) if (!mac)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
pp->name = "nvmem-mac-address"; return mac;
pp->length = ETH_ALEN;
pp->value = devm_kmemdup(&pdev->dev, mac, ETH_ALEN, GFP_KERNEL);
if (!pp->value) {
ret = -ENOMEM;
goto free;
}
ret = of_add_property(np, pp);
if (ret)
goto free;
return pp->value;
free:
devm_kfree(&pdev->dev, pp->value);
devm_kfree(&pdev->dev, pp);
return ERR_PTR(ret);
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment