Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2403121pxb; Tue, 13 Apr 2021 00:37:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbMvy4yIm8lBbSM/oqr1wWAIDWpJ625jfyvRF8OEeVe7BPQRj3RuRyIDsPqWluPtpAhwBF X-Received: by 2002:aa7:db95:: with SMTP id u21mr33306004edt.152.1618299476627; Tue, 13 Apr 2021 00:37:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618299476; cv=none; d=google.com; s=arc-20160816; b=hd1P1+ZMtfy22hR5tHt7HXxZshE8xx6+k8gZ2cOo94312SLHHdD32hiwhsyNEj4arB icSMXmXuVIUKaM8MTh7qS4qk4Ayz9A+0Lvql8j+BLstuxwFOePZseSkQPBodfz+lX5Wg unr551EU5yVWGs6hxQDYLln72JGTp5U0JMabZjNMlIb6VEz/wJAw1uUc6OMfjJNktWMc lL1ag50YKL/ZoazQ9SC733f0TZsLieGtqRu7UG85qI+CcbYmEwwbRcfwg5NRT6VVrBeE Ssc7EU2MjOlDOKO8aR28r8/9iw1GjF1lIcH/iOopZuTEDeHAFNElM0l7hSsrM0gnItfY bi1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=JlgNNW6opfbYsb2HY0jilFyMHcv1A4vZ2Vd6HwbRFUs=; b=qHN5AjBKNJiaxXiRipzl4oJBxFRbgwLRrYw1cc6hWvb5fIy5Qj2yMfjUc+gO1Cz2gA wnQcGdnaXP03eNuE1sTfX4R3Ojnrgq6aNfvQCnEBJ87sb3YJW0l05TbFTd+a7vcpMOxX m4u7vTRt58+CmRS9GwfhMNnakg35kGFSBGtMIQwb1/4S2Y6FI+PcL63RUDVTIxQ6vN3H HdGsqFpzEORlKvuCVgCUfjg4L6mi5sBXLhlL/WYR5bQ7r1PJLMgfDqAcCC5yEVG0fcNR X3lmr12ugiA4lTH+nfGAx3cP1nwuSMrT9kEeU7ieQkcPwIN2Vsvmbv8d82XEGJsUFSxo kmlQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b19si9389817edy.543.2021.04.13.00.37.33; Tue, 13 Apr 2021 00:37:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239395AbhDMA4v (ORCPT + 99 others); Mon, 12 Apr 2021 20:56:51 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:47030 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238450AbhDMA4u (ORCPT ); Mon, 12 Apr 2021 20:56:50 -0400 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 Cc: ath9k-devel@qca.qualcomm.com, UNGLinuxDriver@microchip.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, netdev@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-amlogic@lists.infradead.org, linux-oxnas@groups.io, linux-omap@vger.kernel.org, linux-wireless@vger.kernel.org, devicetree@vger.kernel.org, linux-staging@lists.linux.dev, Gregory Clement , Sebastian Hesselbarth , Russell King , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Andreas Larsson , "David S . Miller" , Jakub Kicinski , Maxime Ripard , Chen-Yu Tsai , Jernej Skrabec , Joyce Ooi , Chris Snook , =?utf-8?B?UmFmYcWCIE1pxYJlY2tp?= , bcm-kernel-feedback-list@broadcom.com, Florian Fainelli , Nicolas Ferre , Claudiu Beznea , Sunil Goutham , Fugang Duan , Madalin Bucur , Pantelis Antoniou , Claudiu Manoil , Li Yang , Yisen Zhuang , Salil Mehta , Hauke Mehrtens , Thomas Petazzoni , Vadym Kochan , Taras Chornyi , Mirko Lindner , Stephen Hemminger , Felix Fietkau , John Crispin , Sean Wang , Mark Lee , Matthias Brugger , Bryan Whitehead , Vladimir Zapolskiy , Sergei Shtylyov , Byungho An , Kunihiko Hayashi , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , Maxime Coquelin , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Kevin Hilman , Neil Armstrong , Jerome Brunet , Martin Blumenstingl , Vinod Koul , Nobuhiro Iwamatsu , Grygorii Strashko , Wingman Kwok , Murali Karicheri , Michal Simek , Radhey Shyam Pandey , Kalle Valo , Lorenzo Bianconi , Ryder Lee , Stanislaw Gruszka , Helmut Schaa , Heiner Kallweit , Rob Herring , Frank Rowand , Greg Kroah-Hartman , =?iso-8859-1?B?Suly9G1l?= Pouiller , Vivien Didelot , Vladimir Oltean 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> Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org 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