From patchwork Wed Oct 13 08:25:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yajun Deng X-Patchwork-Id: 12555079 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37161C433EF for ; Wed, 13 Oct 2021 08:26:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 11B97610CB for ; Wed, 13 Oct 2021 08:26:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238507AbhJMI2P (ORCPT ); Wed, 13 Oct 2021 04:28:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234440AbhJMI2O (ORCPT ); Wed, 13 Oct 2021 04:28:14 -0400 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91F47C061570; Wed, 13 Oct 2021 01:26:11 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yajun Deng To: davem@davemloft.net, kuba@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yajun Deng 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 Message-Id: <20211013082550.624-1-yajun.deng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: yajun.deng@linux.dev Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 Reported-by: kernel test robot Reported-by: kernel test robot --- 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; } From patchwork Wed Oct 13 08:26:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yajun Deng X-Patchwork-Id: 12555081 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB06FC433F5 for ; Wed, 13 Oct 2021 08:26:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AD1EE61077 for ; Wed, 13 Oct 2021 08:26:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238592AbhJMI3B (ORCPT ); Wed, 13 Oct 2021 04:29:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238555AbhJMI2y (ORCPT ); Wed, 13 Oct 2021 04:28:54 -0400 X-Greylist: delayed 76 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 13 Oct 2021 01:26:51 PDT Received: from out10.migadu.com (out10.migadu.com [IPv6:2001:41d0:2:e8e3::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1670DC061570; Wed, 13 Oct 2021 01:26:50 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1634113603; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=3J/v/zdtjtl+/PpmqBkLrn6nFk7IE1zZUoknWsoDZSE=; b=b19WTM3BhWK42yjq7O3eNhI/ZZi+Irf0pejMmnhw/dc6lQq4DnorsyEmXtkco4oRIe4ekU s6mbvIzEdVj0xj0Ec4rRooVDbLOg/S9lCzrsH5Zu4N7Zg1NV8JvPu8BoiW3UGhD1tBVElr BWSw/Iv2FFLEMZNIVC7kmD2PvtsiGaM= From: Yajun Deng To: davem@davemloft.net, kuba@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yajun Deng Subject: [PATCH net-next 2/2] ethernet: remove nvmem_get_mac_address() Date: Wed, 13 Oct 2021 16:26:22 +0800 Message-Id: <20211013082622.707-1-yajun.deng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: yajun.deng@linux.dev Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org nvmem_get_mac_address() is no longer used, remove it. Signed-off-by: Yajun Deng --- include/linux/etherdevice.h | 1 - net/ethernet/eth.c | 36 ------------------------------------ 2 files changed, 37 deletions(-) diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index 3cf546d2ffd1..9a8f46afe114 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h @@ -31,7 +31,6 @@ struct fwnode_handle; int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr); int platform_get_ethdev_address(struct device *dev, struct net_device *netdev); unsigned char *arch_get_platform_mac_address(void); -int nvmem_get_mac_address(struct device *dev, void *addrbuf); int device_get_mac_address(struct device *dev, char *addr); int device_get_ethdev_address(struct device *dev, struct net_device *netdev); int fwnode_get_mac_address(struct fwnode_handle *fwnode, char *addr); diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index c7d9e08107cb..210ff7235e5f 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c @@ -543,42 +543,6 @@ int platform_get_ethdev_address(struct device *dev, struct net_device *netdev) } EXPORT_SYMBOL(platform_get_ethdev_address); -/** - * nvmem_get_mac_address - Obtain the MAC address from an nvmem cell named - * 'mac-address' associated with given device. - * - * @dev: Device with which the mac-address cell is associated. - * @addrbuf: Buffer to which the MAC address will be copied on success. - * - * Returns 0 on success or a negative error number on failure. - */ -int nvmem_get_mac_address(struct device *dev, void *addrbuf) -{ - struct nvmem_cell *cell; - const void *mac; - size_t len; - - cell = nvmem_cell_get(dev, "mac-address"); - if (IS_ERR(cell)) - return PTR_ERR(cell); - - mac = nvmem_cell_read(cell, &len); - nvmem_cell_put(cell); - - if (IS_ERR(mac)) - return PTR_ERR(mac); - - if (len != ETH_ALEN || !is_valid_ether_addr(mac)) { - kfree(mac); - return -EINVAL; - } - - ether_addr_copy(addrbuf, mac); - kfree(mac); - - return 0; -} - static int fwnode_get_mac_addr(struct fwnode_handle *fwnode, const char *name, char *addr) {