From patchwork Fri Aug 10 08:05:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10562495 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D1137139A for ; Fri, 10 Aug 2018 09:11:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C116E2B8AD for ; Fri, 10 Aug 2018 09:11:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD7EF2B8B5; Fri, 10 Aug 2018 09:11:02 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0E0032B8D6 for ; Fri, 10 Aug 2018 09:11:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=wTMeBoMv+JmcmC3Cr9M7IyUIQHWfoX5vo4tBNs8d15Y=; b=ktqB3vrX0k6yODlxbvYqibR+w9 iALhkft6I1SUwgDXjfMSvCTgyouMbTWlxETyC0UZ553MHd5yTEupxWtUWSzAruIqrKb7DkL4d0mk6 C7u/5BiMMczra5YmNcGkxwaheLNIEdI3kiqMXmPA5qZjNEpptfKExP3g768yndKYCtzQxo552IPlE 38ASMgY2QzmLjvpah65vYmb2AV04h+NQsC2OiBbFYjkcBusSQzC+RkQLuj3GPeI2tA8JytOQ4uqZO LaQJnklufl24M1oL6Fj63NAAiYM0k7ABa7eHAyRDBOv8S3puerb5rRZzCfMDlcAGjY4/5BRcyaPVJ 0vTCzunA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fo3Rl-0002xN-3Q; Fri, 10 Aug 2018 09:11:01 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fo3BL-0007pj-5I for linux-arm-kernel@bombadil.infradead.org; Fri, 10 Aug 2018 08:54:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=EjOQubnQTroWVxsDBUM1JXSo0fAS57WaAUjmLBb4Sws=; b=mMC3opYIE5xzGnygFPutfGoeR pGmjR86yYtl2EmqZkLjPNtRfMrLi4J7dMiZIDmKZhsXkpyF4hQ+T2Jw0kQRKKqshD+qman+4R0aWE +TQQvlClFThybSUdQ0ZBW+rY3/ukS3g4dbHUsf7BFfY1/LawgMuxXAMqDJc780YU2doY/bXsu/OXy G40/YM55m3hAqDkmH2cmonVolGM8/eeYDdQBjAIVrLVYtL28Nbc0Q2+xmZLzUK/En6tRuHko5/Mng wJdGOlVAnIW9y/naAbwaPIy9NAJGSgrta7HXftb2htzf46sREQtFwESogwSaOG6z0qLt5tOVrJac6 ZCoJD+9jA==; Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fo2R4-0007Wt-Qc for linux-arm-kernel@lists.infradead.org; Fri, 10 Aug 2018 08:06:17 +0000 Received: by mail-wr1-x444.google.com with SMTP id h10-v6so7462276wre.6 for ; Fri, 10 Aug 2018 01:06:02 -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=EjOQubnQTroWVxsDBUM1JXSo0fAS57WaAUjmLBb4Sws=; b=slxAavyRYIQAKAyGAcvJcsdh4bzGKFYXvueiQKixAAkrgMWIfSf1b7VJfMW8yml9CP OlkK3rH0fn7Cp+JOjH+OwKI3DlTgq14HaQgshBSfsWcCVIxRtuP1Tb8j4e1sh3PgBane I5druFmkEsk+6QWmtgkkzuNEX3y6ct8hPvQl+trAkKGjltR0bN4am01ohGLiYfWiIVHf mP1hXPsUie4ZzSKNpP0Ba5pHkzO08Gz7ktUz2eV5J29se9aqmHvVO7Z3qIYUxrUcfOlz BmrOC1ajt2D1hEHzj3h5Omy4PBimrql7pMsm5V3KdV2T1VuHIvws9axLTyMd2zvu0LW2 Lhkw== 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=EjOQubnQTroWVxsDBUM1JXSo0fAS57WaAUjmLBb4Sws=; b=PctikRxpPHA2wL/l1fvzyqT7jVfJjzh4r8QpIS9vwIvYW4oC37QnGznwDZIopSxqkF tk5FMBfxUcQWKTcgw7VsW2mi+3+WehGEMxGpl5jzmHS5llAOqWk9MOmHfVxt7OxLnZV/ 4BlMon+lx1FbCQjfUxF5CXdBnUcfqy1/YexA29hRWvQIs8lb+0GTz60Nz7noTHdQ3wDh HW1Z4AJZBZJKR+De9iRz8ujNrC+7QUdUUtmdhj4sbaqpyZ7Am3wSYmSjFl4Id/HD1BhK Gx4anPQ+mg9kEfDjDqaqGB2dT8evOFSoHwmo8PZWVSO+qN4bQHE/bFZm+4c7Wlr5pp+G c0Rg== X-Gm-Message-State: AOUpUlF4+uALrRB5iiAX80oPiXELWKr0m4X34AyKJIJH56u0DnPwaFri bkzOB+OO55O/ayoDyo43pkh84g== X-Google-Smtp-Source: AA+uWPy4GNYeh2WzvM+2T0Bc7L9+oHxywgRRtH1zE1aqpVG7uIW5FR9RKpaa87lEDy5+MnJSrszRTQ== X-Received: by 2002:adf:8385:: with SMTP id 5-v6mr3547900wre.13.1533888361189; Fri, 10 Aug 2018 01:06:01 -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 h7-v6sm9546405wrs.8.2018.08.10.01.05.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Aug 2018 01:06:00 -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 Subject: [PATCH v2 15/29] net: split eth_platform_get_mac_address() into subroutines Date: Fri, 10 Aug 2018 10:05:12 +0200 Message-Id: <20180810080526.27207-16-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180810080526.27207-1-brgl@bgdev.pl> References: <20180810080526.27207-1-brgl@bgdev.pl> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180810_040615_053259_82865316 X-CRM114-Status: GOOD ( 18.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-doc@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , linux-mtd@lists.infradead.org, linux-i2c@vger.kernel.org, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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 | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index 7f08105402c8..d01dd55de037 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c @@ -525,22 +525,50 @@ 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; - dp = dev->of_node; - addr = NULL; - if (dp) - addr = of_get_mac_address(dp); - if (!addr) - addr = arch_get_platform_mac_address(); + np = dev->of_node; + 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);