From: Yajun Deng <yajun.deng@linux.dev>
To: davem@davemloft.net, kuba@kernel.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Yajun Deng <yajun.deng@linux.dev>
Subject: [PATCH net-next 1/2] of: net: move nvmem_get_mac_address() into of_get_mac_addr_nvmem()
Date: Wed, 13 Oct 2021 16:25:50 +0800 [thread overview]
Message-ID: <20211013082550.624-1-yajun.deng@linux.dev> (raw)
nvmem_get_mac_address() is only called by of_get_mac_addr_nvmem(), and
they use almost the same code. so move nvmem_get_mac_address() into
of_get_mac_addr_nvmem().
In addition, prefer ether_addr_copy() over memcpy() if the ethernet
addresses are __aligned(2).
Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
net/core/of_net.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/net/core/of_net.c b/net/core/of_net.c
index f1a9bf7578e7..cd170ffda5f9 100644
--- a/net/core/of_net.c
+++ b/net/core/of_net.c
@@ -51,7 +51,7 @@ static int of_get_mac_addr(struct device_node *np, const char *name, u8 *addr)
struct property *pp = of_find_property(np, name, NULL);
if (pp && pp->length == ETH_ALEN && is_valid_ether_addr(pp->value)) {
- memcpy(addr, pp->value, ETH_ALEN);
+ ether_addr_copy(addr, pp->value);
return 0;
}
return -ENODEV;
@@ -68,13 +68,11 @@ static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
/* Try lookup by device first, there might be a nvmem_cell_lookup
* associated with a given device.
*/
- if (pdev) {
- ret = nvmem_get_mac_address(&pdev->dev, addr);
- put_device(&pdev->dev);
- return ret;
- }
+ if (pdev)
+ cell = nvmem_cell_get(&pdev->dev, "mac-address");
+ else
+ cell = of_nvmem_cell_get(np, "mac-address");
- cell = of_nvmem_cell_get(np, "mac-address");
if (IS_ERR(cell))
return PTR_ERR(cell);
@@ -89,9 +87,12 @@ static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
return -EINVAL;
}
- memcpy(addr, mac, ETH_ALEN);
+ ether_addr_copy(addr, mac);
kfree(mac);
+ if (pdev)
+ put_device(&pdev->dev);
+
return 0;
}
--
2.32.0
next reply other threads:[~2021-10-13 8:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-13 8:25 Yajun Deng [this message]
2021-10-13 19:16 ` [PATCH net-next 1/2] of: net: move nvmem_get_mac_address() into of_get_mac_addr_nvmem() kernel test robot
2021-10-15 10:00 ` kernel test robot
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=20211013082550.624-1-yajun.deng@linux.dev \
--to=yajun.deng@linux.dev \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/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).