Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp970771imm; Wed, 8 Aug 2018 08:38:45 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxfjVFeozAVkt9m95x+LPi95/CC5PfLSC7CZ46Qdp5JAMagf/prQcwGrJc0b7zHYCfZjAXG X-Received: by 2002:a17:902:694a:: with SMTP id k10-v6mr3127775plt.166.1533742725553; Wed, 08 Aug 2018 08:38:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533742725; cv=none; d=google.com; s=arc-20160816; b=OFYH6IKSvM2eSg1ODp6AD+WDQw2KmLjpMpNRX6vdHsn7od9/sXRC+/xhOPHPGH0Q9y qIL295aPcs6FMfVm5zsHJg9I1r5VD8YM3S5AomsTVo0Z3bk7kAe1eZBk72bY9YTt94fN XWXcfTBSl4E9IlIuL/QfEbZWDvH5oaI6soFJtqsiKsW2i1HTg1rx/P+ib2KSK7arH5CE cSwLXT9GdRNYunRmg3rdc6wUg9NdpaPALilg4YCuuln+kTECDWLMXPPA8zX6IOQbrv8o hAtP0o7rVHCdL/Hh8spMt4B6intyyw33gO4YkTBMGNLaAE7McJDSBZ9+zINAGUwgoEJq IISw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=GhxBsIfK86giZ9cjSjQgHpsWxFiMvzhSUErcIymDujg=; b=K1woSnG+qs6sZcO6XyCmFi3VYrpXLzzO8TFEkYLxG82uhv4oIpeL1CLaKZaqrHgBTg 63cf4/w/liomyyCzNeWd9mpE1YpIcStifcah1AMtzgdJB8xrivFAhv0UILexsEGtY9gh kWo/L5VRcMTwV/BsE84unw6fKkgJR5hERbLJDepdnyEH6cfkeg+9A8prSNaDvluwntFo PEpyZyhLJSNuppqPtMP1abHf99+quFK1IIfGP58Bs/rF2fZDe0HUzMeRfogzCuDcXanr vHDxRhZCYeplXfo7jrOCf1ul3HA7M6YhlrE1boWc43DXORGf3lwte9MOFqAax8SxskCR n5PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=ZqPg9nBe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z63-v6si4767212pfi.214.2018.08.08.08.38.30; Wed, 08 Aug 2018 08:38:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=ZqPg9nBe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729643AbeHHRyH (ORCPT + 99 others); Wed, 8 Aug 2018 13:54:07 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:46511 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729221AbeHHRyG (ORCPT ); Wed, 8 Aug 2018 13:54:06 -0400 Received: by mail-wr1-f67.google.com with SMTP id h14-v6so2377603wrw.13 for ; Wed, 08 Aug 2018 08:33:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GhxBsIfK86giZ9cjSjQgHpsWxFiMvzhSUErcIymDujg=; b=ZqPg9nBeYD7Jj4LbD/qxHP8mdIaP9ehKNQ4AiXOn4oOR+a5ZAukUE+JSxk5Awm7see 4zC84eGwAAGMLSh2/XuOWxIK/te5rwrHxpT/bW0eu4kwE+HgrDCmjcnYhBbK1Qg0g0iK olWgZ0mraa0LMdGszgAYyHjeeetJwyAyZbU1zQSSiUKih9toBsrwLiDr1y6F05nH50pt xTGMmDnYdUzQv6qqFh2GzahD1ZQ82M0164l1drphkhkbh33+AxbLUcfoQCOitNqO3oOr Us8whYMDibcOLJ0MkFa3pnVGRkdt1rdTb+bEsP68ccMWss+wLl39D21hrtsygCAddcBi HsLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GhxBsIfK86giZ9cjSjQgHpsWxFiMvzhSUErcIymDujg=; b=T3tbX6aFVTLfOzwrVbRu/3DDXAlkqvVEFSFafl1qhtLrB5uHb1yMYrObTMgM9vlKKj wvQhVEsX4HIsfuxrx7gQzMyaF84GyON3zCMTCThvVuX+7icqaBqZoj7ExDvyI1HWIsWZ M1f4P7Ls8dRJOs/4dRhBaWquUez7Crvys1JgoS+CMpPC4lfTxpQyPB/2YV8sIyrmERvj Z5yvQzpSyuWizVDo6+JK1Utpb4CRS1DKei43Hc0kcs21Okuj7bth1i6fgW//uxTBn5qs Jkd2BZegv1JZ3eduGxGaHd0fs43VayEnCTvmupCnCjeUN9Qj0bIbmCHrYR26P9AUTrqy Lcjw== X-Gm-Message-State: AOUpUlE+L2xSOcZsuqm+P4PY2yHIv9RPfP6qAV4Zoira8RCD+zD3XnZH SxQljbmSuv9mJCMiHuzqATuKQA== X-Received: by 2002:adf:fcc3:: with SMTP id f3-v6mr2213453wrs.216.1533742434493; Wed, 08 Aug 2018 08:33:54 -0700 (PDT) Received: from brgl-bgdev.lan (LFbn-MAR-1-609-89.w90-118.abo.wanadoo.fr. [90.118.185.89]) by smtp.gmail.com with ESMTPSA id s2-v6sm5240915wrw.52.2018.08.08.08.33.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 08:33:53 -0700 (PDT) From: Bartosz Golaszewski To: Jonathan Corbet , Sekhar Nori , Kevin Hilman , Russell King , Arnd Bergmann , Greg Kroah-Hartman , David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Grygorii Strashko , "David S . Miller" , Srinivas Kandagatla , Naren , Mauro Carvalho Chehab , Andrew Morton , Lukas Wunner , Dan Carpenter , Florian Fainelli , Ivan Khoronzhuk , Sven Van Asbroeck , Paolo Abeni , Alban Bedel , Rob Herring , David Lechner , Andrew Lunn Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, linux-mtd@lists.infradead.org, linux-omap@vger.kernel.org, netdev@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 14/28] net: split eth_platform_get_mac_address() into subroutines Date: Wed, 8 Aug 2018 17:31:36 +0200 Message-Id: <20180808153150.23444-15-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180808153150.23444-1-brgl@bgdev.pl> References: <20180808153150.23444-1-brgl@bgdev.pl> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski We want do add more sources from which to read the MAC address. In order to avoid bloating this function too much, start by splitting it into subroutines, each of which takes care of reading the MAC from one source. Signed-off-by: Bartosz Golaszewski --- net/ethernet/eth.c | 48 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index ee28440f57c5..cf54cdf042b7 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c @@ -525,26 +525,52 @@ unsigned char * __weak arch_get_platform_mac_address(void) return NULL; } -int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr) +static int mac_address_from_of(struct device *dev, u8 *mac_addr) { const unsigned char *addr; - struct device_node *dp; + struct device_node *np; - if (dev_is_pci(dev)) - dp = pci_device_to_OF_node(to_pci_dev(dev)); - else - dp = dev->of_node; + np = dev_is_pci(dev) ? pci_device_to_OF_node(to_pci_dev(dev)) + : dev->of_node; - addr = NULL; - if (dp) - addr = of_get_mac_address(dp); - if (!addr) - addr = arch_get_platform_mac_address(); + if (!np) + return -ENODEV; + addr = of_get_mac_address(np); if (!addr) return -ENODEV; + if (!addr || !is_valid_ether_addr(addr)) + return -ENODEV; + + ether_addr_copy(mac_addr, addr); + return 0; +} + +static int mac_address_from_arch(u8 *mac_addr) +{ + const unsigned char *addr; + + addr = arch_get_platform_mac_address(); + if (!addr || !is_valid_ether_addr(addr)) + return -ENODEV; + ether_addr_copy(mac_addr, addr); return 0; } + +int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr) +{ + int rv; + + rv = mac_address_from_of(dev, mac_addr); + if (!rv) + return 0; + + rv = mac_address_from_arch(mac_addr); + if (!rv) + return 0; + + return -ENODEV; +} EXPORT_SYMBOL(eth_platform_get_mac_address); -- 2.18.0