From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CC6BC433ED for ; Tue, 13 Apr 2021 01:47:52 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1CB88600D1 for ; Tue, 13 Apr 2021 01:47:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1CB88600D1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lunn.ch Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4FK7ln2SZ1z3c1q for ; Tue, 13 Apr 2021 11:47:49 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lunn.ch (client-ip=185.16.172.187; helo=vps0.lunn.ch; envelope-from=andrew@lunn.ch; receiver=) Received: from vps0.lunn.ch (vps0.lunn.ch [185.16.172.187]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4FK6cR0V4Zz2xYn for ; Tue, 13 Apr 2021 10:56:22 +1000 (AEST) Received: from andrew by vps0.lunn.ch with local (Exim 4.94) (envelope-from ) id 1lW7LN-00GOEl-SK; Tue, 13 Apr 2021 02:55:53 +0200 Date: Tue, 13 Apr 2021 02:55:53 +0200 From: Andrew Lunn To: Michael Walle Subject: Re: [PATCH net-next v4 1/2] of: net: pass the dst buffer to of_get_mac_address() Message-ID: References: <20210412174718.17382-1-michael@walle.cc> <20210412174718.17382-2-michael@walle.cc> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210412174718.17382-2-michael@walle.cc> X-Mailman-Approved-At: Tue, 13 Apr 2021 11:47:28 +1000 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Mackerras , =?utf-8?B?UmFmYcWCIE1pxYJlY2tp?= , Nobuhiro Iwamatsu , linux-stm32@st-md-mailman.stormreply.com, Jerome Brunet , Neil Armstrong , Michal Simek , Jose Abreu , NXP Linux Team , Mark Lee , Hauke Mehrtens , Sascha Hauer , Lorenzo Bianconi , linux-omap@vger.kernel.org, Greg Kroah-Hartman , linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, Pengutronix Kernel Team , Vladimir Oltean , Claudiu Beznea , =?iso-8859-1?B?Suly9G1l?= Pouiller , Kunihiko Hayashi , Chris Snook , Frank Rowand , Gregory Clement , Madalin Bucur , Martin Blumenstingl , Murali Karicheri , Yisen Zhuang , Alexandre Torgue , Wingman Kwok , Sean Wang , Maxime Ripard , Claudiu Manoil , linux-amlogic@lists.infradead.org, Kalle Valo , Mirko Lindner , Fugang Duan , Bryan Whitehead , ath9k-devel@qca.qualcomm.com, UNGLinuxDriver@microchip.com, Taras Chornyi , Maxime Coquelin , Kevin Hilman , Heiner Kallweit , Andreas Larsson , Giuseppe Cavallaro , Fabio Estevam , Stanislaw Gruszka , Florian Fainelli , linux-staging@lists.linux.dev, Chen-Yu Tsai , bcm-kernel-feedback-list@broadcom.com, linux-arm-kernel@lists.infradead.org, Grygorii Strashko , Byungho An , Radhey Shyam Pandey , Vladimir Zapolskiy , John Crispin , Salil Mehta , Sergei Shtylyov , linux-oxnas@groups.io, Shawn Guo , "David S . Miller" , Helmut Schaa , Thomas Petazzoni , linux-renesas-soc@vger.kernel.org, Ryder Lee , Russell King , Vadym Kochan , Jakub Kicinski , Vivien Didelot , Sunil Goutham , Sebastian Hesselbarth , devicetree@vger.kernel.org, Rob Herring , linux-mediatek@lists.infradead.org, Matthias Brugger , Jernej Skrabec , netdev@vger.kernel.org, Nicolas Ferre , Li Yang , Stephen Hemminger , Vinod Koul , Joyce Ooi , linuxppc-dev@lists.ozlabs.org, Felix Fietkau Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Mon, Apr 12, 2021 at 07:47:17PM +0200, Michael Walle wrote: > of_get_mac_address() returns a "const void*" pointer to a MAC address. > Lately, support to fetch the MAC address by an NVMEM provider was added. > But this will only work with platform devices. It will not work with > PCI devices (e.g. of an integrated root complex) and esp. not with DSA > ports. > > There is an of_* variant of the nvmem binding which works without > devices. The returned data of a nvmem_cell_read() has to be freed after > use. On the other hand the return of_get_mac_address() points to some > static data without a lifetime. The trick for now, was to allocate a > device resource managed buffer which is then returned. This will only > work if we have an actual device. > > Change it, so that the caller of of_get_mac_address() has to supply a > buffer where the MAC address is written to. Unfortunately, this will > touch all drivers which use the of_get_mac_address(). > > Usually the code looks like: > > const char *addr; > addr = of_get_mac_address(np); > if (!IS_ERR(addr)) > ether_addr_copy(ndev->dev_addr, addr); > > This can then be simply rewritten as: > > of_get_mac_address(np, ndev->dev_addr); > > Sometimes is_valid_ether_addr() is used to test the MAC address. > of_get_mac_address() already makes sure, it just returns a valid MAC > address. Thus we can just test its return code. But we have to be > careful if there are still other sources for the MAC address before the > of_get_mac_address(). In this case we have to keep the > is_valid_ether_addr() call. > > The following coccinelle patch was used to convert common cases to the > new style. Afterwards, I've manually gone over the drivers and fixed the > return code variable: either used a new one or if one was already > available use that. Mansour Moufid, thanks for that coccinelle patch! > > > @a@ > identifier x; > expression y, z; > @@ > - x = of_get_mac_address(y); > + x = of_get_mac_address(y, z); > <... > - ether_addr_copy(z, x); > ...> > > @@ > identifier a.x; > @@ > - if (<+... x ...+>) {} > > @@ > identifier a.x; > @@ > if (<+... x ...+>) { > ... > } > - else {} > > @@ > identifier a.x; > expression e; > @@ > - if (<+... x ...+>@e) > - {} > - else > + if (!(e)) > {...} > > @@ > expression x, y, z; > @@ > - x = of_get_mac_address(y, z); > + of_get_mac_address(y, z); > ... when != x > > > All drivers, except drivers/net/ethernet/aeroflex/greth.c, were > compile-time tested. > > Suggested-by: Andrew Lunn > Signed-off-by: Michael Walle I cannot say i looked at all the changes, but the ones i did exam seemed O.K. Reviewed-by: Andrew Lunn Andrew