From patchwork Thu Jul 19 15:32:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10534807 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0FDF0600D0 for ; Thu, 19 Jul 2018 15:33:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C06DA299D6 for ; Thu, 19 Jul 2018 15:33:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BEA8929C02; Thu, 19 Jul 2018 15:33:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E3D629CB9 for ; Thu, 19 Jul 2018 15:33:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731980AbeGSQQg (ORCPT ); Thu, 19 Jul 2018 12:16:36 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36491 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731838AbeGSQQf (ORCPT ); Thu, 19 Jul 2018 12:16:35 -0400 Received: by mail-wm0-f66.google.com with SMTP id s14-v6so6894874wmc.1 for ; Thu, 19 Jul 2018 08:32:52 -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=ILOXH9pVEXmkUqoRI158DGfYu5yW/dY65Iz0Pm4CfIk=; b=wpD1zpgjNoJzc7gGJjnsRMVNmmArkWJDssEGA6Xxw6MvRaJpoUQgIfU+2Zf7Tv9ea+ +hs20Hr3lNDgxMC4Pm5WTE3m0f9YBGg0JGJh6pU07ne4k827KjRJJ+XJhlb6s99Uo3Tx o/vIk/ZmWILR4XMzAuHQbK4XvIyWg2/zh7SbwHMhkyCWFnIG83EavP1lKQe5kJ+2K77j vyGa8aLI2mxaOPXJpM/pnWXyY7EG8lNTdcy27le7jKRVrnu4U7tsXAeI/uYJKS9kv3yq tC8lCz4hVLHCRwM34C9ecBjwTlBnuGJ/hQhWFZ7ixHBGFM21AfZvt7Bs0d5y9RPiUFUE So3w== 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=ILOXH9pVEXmkUqoRI158DGfYu5yW/dY65Iz0Pm4CfIk=; b=TwPMQMi30mcB9vayHRGjJ+uGE+GnheOLOkBGleC8nId8J8h4duLXfPs5OaRfFNinSo FIeFGOYfYyLX3w2Rtne65zVHBjcqqHSjShhVVkRlOcBjnWEfmbOL1Yw+Jg4wuEK/+8AE PkmA49viLBhveaNZKKr5HC+Y4pNueuFmb/KH80eKyg65SmB+29GLoMCNa3Pt5KtOwRO+ QPtm+ZB5YuOpCUyJAUITdVbbzXnHTAHSJYoKQM3WFt84hc1qVJrwOLVkW6y7qbMv3I8N DV9ZJ/vDxTJUBSlGMDigr25uun2zE+f/3W3UDr5fADr8mDlEr9y/2bD6Yg9b5rl8rgVW 54+w== X-Gm-Message-State: AOUpUlEhwRhjUIdtzmb8Frszv6KUl0u06apu1mB4BqIBOldCWE4qvDnF +/W+fwDWan6tPxZ+fbvPk5itNw== X-Google-Smtp-Source: AAOMgpfr+hiJTPGwnqvPCPW7pxNq4Y5VWbASiEBQ88EY7/i47Sed8+2rfaZXjnoIwDTOc+d0lS7TgQ== X-Received: by 2002:a1c:28c2:: with SMTP id o185-v6mr4577523wmo.40.1532014371999; Thu, 19 Jul 2018 08:32:51 -0700 (PDT) Received: from brgl-bgdev.baylibre.local (AStLambert-681-1-40-185.w90-86.abo.wanadoo.fr. [90.86.159.185]) by smtp.gmail.com with ESMTPSA id w9-v6sm8914090wrr.77.2018.07.19.08.32.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 08:32:51 -0700 (PDT) From: Bartosz Golaszewski To: Sekhar Nori , Kevin Hilman , Russell King , Grygorii Strashko , "David S . Miller" , Srinivas Kandagatla , Lukas Wunner , Rob Herring , Florian Fainelli , Dan Carpenter , Ivan Khoronzhuk , David Lechner , Greg Kroah-Hartman , Andrew Lunn Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, netdev@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v3 1/3] net: split eth_platform_get_mac_address() into subroutines Date: Thu, 19 Jul 2018 17:32:41 +0200 Message-Id: <20180719153243.20944-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180719153243.20944-1-brgl@bgdev.pl> References: <20180719153243.20944-1-brgl@bgdev.pl> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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);