Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3227133pxb; Wed, 13 Oct 2021 01:28:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBFC9suZINoB+QAM8pDx1mfpq7OHSFichbDoJIt+E9GYpAEl5/xOtsh4m8RIImDMLiXUBs X-Received: by 2002:a17:906:5f8e:: with SMTP id a14mr24499284eju.155.1634113733047; Wed, 13 Oct 2021 01:28:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634113733; cv=none; d=google.com; s=arc-20160816; b=rGktpwBzFY3Ikr8v42N778MOAle+T0JNxs808maGSI58SkTW8z7X/wdJVV9w99lTUP 5Btz4RbBeZLxvf5dCFVxJw9pCXGm70Wmw4+h0bu26yOtesnzkFgeYkOkw8tWkdQRYgy6 vxP6hlRI5Rck7VX70wdwLWJxK3I9zEaTh0CxWb3sG91AozDWikmOTn+Xthxa9umGjreC SA6x6xV98i6EH4w1xXHS3djPjmQdd0DhmLB+HGH3v7PMvG7Xd+qQ+/Rxm311hAEI8Jnh XmJapi4n8316OMcoIKhEE0Q6Qze1VielHoGI3l7HlAF2bWVwdKuLM9MrLAl2x9pe5nC9 N5CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=6nDV+hoW4b09UAKGN/dlXrEJXObhSFKfkSOrDd7Hja4=; b=Vnqw/fAk/vX4bvjo0Pdg4sdSBhzEqIr0Da2McZn5SywZE8A5RD3rvJtH2f3YoSEHE2 aHe3IxATLCIOBQ0Q5PfVdi/7FibqmEBhSCTM2iQKGq890xzadSZBOJRVNf5Kig1yxeBM XLT7QRC9G7A7nUnAm7xetZUFIU1LTSKzBvRhXVS4LejNZfN9CFc8YiCH+H902gsLLIrX gNC7FtDPpsL6NigXavxj92FIzFCjKpmZg+sFfJe87nt5W5dvrxpm2Bj4QEUHtzEGTkp2 LxkKE0oz9FKhuzes7DDhWR/1EIuFVC7AT26k9+HkJCUkLKlCjsD0kPYSL13o4iZD/NyM cjog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v11si18441083eje.169.2021.10.13.01.28.27; Wed, 13 Oct 2021 01:28:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238509AbhJMI2P (ORCPT + 99 others); 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 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: yajun.deng@linux.dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.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 --- 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