All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Michael Walle <michael@walle.cc>
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" <gregory.clement@bootlin.com>,
	"Sebastian Hesselbarth" <sebastian.hesselbarth@gmail.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Benjamin Herrenschmidt" <benh@kernel.crashing.org>,
	"Paul Mackerras" <paulus@samba.org>,
	"Andreas Larsson" <andreas@gaisler.com>,
	"David S . Miller" <davem@davemloft.net>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Chen-Yu Tsai" <wens@csie.org>,
	"Jernej Skrabec" <jernej.skrabec@siol.net>,
	"Joyce Ooi" <joyce.ooi@intel.com>,
	"Chris Snook" <chris.snook@gmail.com>,
	"Rafał Miłecki" <rafal@milecki.pl>,
	bcm-kernel-feedback-list@broadcom.com,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Nicolas Ferre" <nicolas.ferre@microchip.com>,
	"Claudiu Beznea" <claudiu.beznea@microchip.com>,
	"Sunil Goutham" <sgoutham@marvell.com>,
	"Fugang Duan" <fugang.duan@nxp.com>,
	"Madalin Bucur" <madalin.bucur@nxp.com>,
	"Pantelis Antoniou" <pantelis.antoniou@gmail.com>,
	"Claudiu Manoil" <claudiu.manoil@nxp.com>,
	"Li Yang" <leoyang.li@nxp.com>,
	"Yisen Zhuang" <yisen.zhuang@huawei.com>,
	"Salil Mehta" <salil.mehta@huawei.com>,
	"Hauke Mehrtens" <hauke@hauke-m.de>,
	"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
	"Vadym Kochan" <vkochan@marvell.com>,
	"Taras Chornyi" <tchornyi@marvell.com>,
	"Mirko Lindner" <mlindner@marvell.com>,
	"Stephen Hemminger" <stephen@networkplumber.org>,
	"Felix Fietkau" <nbd@nbd.name>, "John Crispin" <john@phrozen.org>,
	"Sean Wang" <sean.wang@mediatek.com>,
	"Mark Lee" <Mark-MC.Lee@mediatek.com>,
	"Matthias Brugger" <matthias.bgg@gmail.com>,
	"Bryan Whitehead" <bryan.whitehead@microchip.com>,
	"Vladimir Zapolskiy" <vz@mleia.com>,
	"Sergei Shtylyov" <sergei.shtylyov@gmail.com>,
	"Byungho An" <bh74.an@samsung.com>,
	"Kunihiko Hayashi" <hayashi.kunihiko@socionext.com>,
	"Giuseppe Cavallaro" <peppe.cavallaro@st.com>,
	"Alexandre Torgue" <alexandre.torgue@st.com>,
	"Jose Abreu" <joabreu@synopsys.com>,
	"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
	"Shawn Guo" <shawnguo@kernel.org>,
	"Sascha Hauer" <s.hauer@pengutronix.de>,
	"Pengutronix Kernel Team" <kernel@pengutronix.de>,
	"Fabio Estevam" <festevam@gmail.com>,
	"NXP Linux Team" <linux-imx@nxp.com>,
	"Kevin Hilman" <khilman@baylibre.com>,
	"Neil Armstrong" <narmstrong@baylibre.com>,
	"Jerome Brunet" <jbrunet@baylibre.com>,
	"Martin Blumenstingl" <martin.blumenstingl@googlemail.com>,
	"Vinod Koul" <vkoul@kernel.org>,
	"Nobuhiro Iwamatsu" <nobuhiro1.iwamatsu@toshiba.co.jp>,
	"Grygorii Strashko" <grygorii.strashko@ti.com>,
	"Wingman Kwok" <w-kwok2@ti.com>,
	"Murali Karicheri" <m-karicheri2@ti.com>,
	"Michal Simek" <michal.simek@xilinx.com>,
	"Radhey Shyam Pandey" <radhey.shyam.pandey@xilinx.com>,
	"Kalle Valo" <kvalo@codeaurora.org>,
	"Lorenzo Bianconi" <lorenzo.bianconi83@gmail.com>,
	"Ryder Lee" <ryder.lee@mediatek.com>,
	"Stanislaw Gruszka" <stf_xl@wp.pl>,
	"Helmut Schaa" <helmut.schaa@googlemail.com>,
	"Heiner Kallweit" <hkallweit1@gmail.com>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Frank Rowand" <frowand.list@gmail.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Jérôme Pouiller" <jerome.pouiller@silabs.com>,
	"Vivien Didelot" <vivien.didelot@gmail.com>,
	"Vladimir Oltean" <olteanv@gmail.com>
Subject: Re: [PATCH net-next v4 1/2] of: net: pass the dst buffer to of_get_mac_address()
Date: Tue, 13 Apr 2021 02:55:53 +0200	[thread overview]
Message-ID: <YHTsGXbbr8mkifDo@lunn.ch> (raw)
In-Reply-To: <20210412174718.17382-2-michael@walle.cc>

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!
> 
> <spml>
> @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
> </spml>
> 
> All drivers, except drivers/net/ethernet/aeroflex/greth.c, were
> compile-time tested.
> 
> Suggested-by: Andrew Lunn <andrew@lunn.ch>
> Signed-off-by: Michael Walle <michael@walle.cc>

I cannot say i looked at all the changes, but the ones i did exam
seemed O.K.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

WARNING: multiple messages have this Message-ID (diff)
From: Andrew Lunn <andrew@lunn.ch>
To: Michael Walle <michael@walle.cc>
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" <gregory.clement@bootlin.com>,
	"Sebastian Hesselbarth" <sebastian.hesselbarth@gmail.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Benjamin Herrenschmidt" <benh@kernel.crashing.org>,
	"Paul Mackerras" <paulus@samba.org>,
	"Andreas Larsson" <andreas@gaisler.com>,
	"David S . Miller" <davem@davemloft.net>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Chen-Yu Tsai" <wens@csie.org>,
	"Jernej Skrabec" <jernej.skrabec@siol.net>,
	"Joyce Ooi" <joyce.ooi@intel.com>,
	"Chris Snook" <chris.snook@gmail.com>,
	"Rafał Miłecki" <rafal@milecki.pl>,
	bcm-kernel-feedback-list@broadcom.com,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Nicolas Ferre" <nicolas.ferre@microchip.com>,
	"Claudiu Beznea" <claudiu.beznea@microchip.com>,
	"Sunil Goutham" <sgoutham@marvell.com>,
	"Fugang Duan" <fugang.duan@nxp.com>,
	"Madalin Bucur" <madalin.bucur@nxp.com>,
	"Pantelis Antoniou" <pantelis.antoniou@gmail.com>,
	"Claudiu Manoil" <claudiu.manoil@nxp.com>,
	"Li Yang" <leoyang.li@nxp.com>,
	"Yisen Zhuang" <yisen.zhuang@huawei.com>,
	"Salil Mehta" <salil.mehta@huawei.com>,
	"Hauke Mehrtens" <hauke@hauke-m.de>,
	"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
	"Vadym Kochan" <vkochan@marvell.com>,
	"Taras Chornyi" <tchornyi@marvell.com>,
	"Mirko Lindner" <mlindner@marvell.com>,
	"Stephen Hemminger" <stephen@networkplumber.org>,
	"Felix Fietkau" <nbd@nbd.name>, "John Crispin" <john@phrozen.org>,
	"Sean Wang" <sean.wang@mediatek.com>,
	"Mark Lee" <Mark-MC.Lee@mediatek.com>,
	"Matthias Brugger" <matthias.bgg@gmail.com>,
	"Bryan Whitehead" <bryan.whitehead@microchip.com>,
	"Vladimir Zapolskiy" <vz@mleia.com>,
	"Sergei Shtylyov" <sergei.shtylyov@gmail.com>,
	"Byungho An" <bh74.an@samsung.com>,
	"Kunihiko Hayashi" <hayashi.kunihiko@socionext.com>,
	"Giuseppe Cavallaro" <peppe.cavallaro@st.com>,
	"Alexandre Torgue" <alexandre.torgue@st.com>,
	"Jose Abreu" <joabreu@synopsys.com>,
	"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
	"Shawn Guo" <shawnguo@kernel.org>,
	"Sascha Hauer" <s.hauer@pengutronix.de>,
	"Pengutronix Kernel Team" <kernel@pengutronix.de>,
	"Fabio Estevam" <festevam@gmail.com>,
	"NXP Linux Team" <linux-imx@nxp.com>,
	"Kevin Hilman" <khilman@baylibre.com>,
	"Neil Armstrong" <narmstrong@baylibre.com>,
	"Jerome Brunet" <jbrunet@baylibre.com>,
	"Martin Blumenstingl" <martin.blumenstingl@googlemail.com>,
	"Vinod Koul" <vkoul@kernel.org>,
	"Nobuhiro Iwamatsu" <nobuhiro1.iwamatsu@toshiba.co.jp>,
	"Grygorii Strashko" <grygorii.strashko@ti.com>,
	"Wingman Kwok" <w-kwok2@ti.com>,
	"Murali Karicheri" <m-karicheri2@ti.com>,
	"Michal Simek" <michal.simek@xilinx.com>,
	"Radhey Shyam Pandey" <radhey.shyam.pandey@xilinx.com>,
	"Kalle Valo" <kvalo@codeaurora.org>,
	"Lorenzo Bianconi" <lorenzo.bianconi83@gmail.com>,
	"Ryder Lee" <ryder.lee@mediatek.com>,
	"Stanislaw Gruszka" <stf_xl@wp.pl>,
	"Helmut Schaa" <helmut.schaa@googlemail.com>,
	"Heiner Kallweit" <hkallweit1@gmail.com>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Frank Rowand" <frowand.list@gmail.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Jérôme Pouiller" <jerome.pouiller@silabs.com>,
	"Vivien Didelot" <vivien.didelot@gmail.com>,
	"Vladimir Oltean" <olteanv@gmail.com>
Subject: Re: [PATCH net-next v4 1/2] of: net: pass the dst buffer to of_get_mac_address()
Date: Tue, 13 Apr 2021 02:55:53 +0200	[thread overview]
Message-ID: <YHTsGXbbr8mkifDo@lunn.ch> (raw)
In-Reply-To: <20210412174718.17382-2-michael@walle.cc>

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!
> 
> <spml>
> @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
> </spml>
> 
> All drivers, except drivers/net/ethernet/aeroflex/greth.c, were
> compile-time tested.
> 
> Suggested-by: Andrew Lunn <andrew@lunn.ch>
> Signed-off-by: Michael Walle <michael@walle.cc>

I cannot say i looked at all the changes, but the ones i did exam
seemed O.K.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

WARNING: multiple messages have this Message-ID (diff)
From: Andrew Lunn <andrew@lunn.ch>
To: Michael Walle <michael@walle.cc>
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" <gregory.clement@bootlin.com>,
	"Sebastian Hesselbarth" <sebastian.hesselbarth@gmail.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Benjamin Herrenschmidt" <benh@kernel.crashing.org>,
	"Paul Mackerras" <paulus@samba.org>,
	"Andreas Larsson" <andreas@gaisler.com>,
	"David S . Miller" <davem@davemloft.net>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Chen-Yu Tsai" <wens@csie.org>,
	"Jernej Skrabec" <jernej.skrabec@siol.net>,
	"Joyce Ooi" <joyce.ooi@intel.com>,
	"Chris Snook" <chris.snook@gmail.com>,
	"Rafał Miłecki" <rafal@milecki.pl>,
	bcm-kernel-feedback-list@broadcom.com,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Nicolas Ferre" <nicolas.ferre@microchip.com>,
	"Claudiu Beznea" <claudiu.beznea@microchip.com>,
	"Sunil Goutham" <sgoutham@marvell.com>,
	"Fugang Duan" <fugang.duan@nxp.com>,
	"Madalin Bucur" <madalin.bucur@nxp.com>,
	"Pantelis Antoniou" <pantelis.antoniou@gmail.com>,
	"Claudiu Manoil" <claudiu.manoil@nxp.com>,
	"Li Yang" <leoyang.li@nxp.com>,
	"Yisen Zhuang" <yisen.zhuang@huawei.com>,
	"Salil Mehta" <salil.mehta@huawei.com>,
	"Hauke Mehrtens" <hauke@hauke-m.de>,
	"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
	"Vadym Kochan" <vkochan@marvell.com>,
	"Taras Chornyi" <tchornyi@marvell.com>,
	"Mirko Lindner" <mlindner@marvell.com>,
	"Stephen Hemminger" <stephen@networkplumber.org>,
	"Felix Fietkau" <nbd@nbd.name>, "John Crispin" <john@phrozen.org>,
	"Sean Wang" <sean.wang@mediatek.com>,
	"Mark Lee" <Mark-MC.Lee@mediatek.com>,
	"Matthias Brugger" <matthias.bgg@gmail.com>,
	"Bryan Whitehead" <bryan.whitehead@microchip.com>,
	"Vladimir Zapolskiy" <vz@mleia.com>,
	"Sergei Shtylyov" <sergei.shtylyov@gmail.com>,
	"Byungho An" <bh74.an@samsung.com>,
	"Kunihiko Hayashi" <hayashi.kunihiko@socionext.com>,
	"Giuseppe Cavallaro" <peppe.cavallaro@st.com>,
	"Alexandre Torgue" <alexandre.torgue@st.com>,
	"Jose Abreu" <joabreu@synopsys.com>,
	"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
	"Shawn Guo" <shawnguo@kernel.org>,
	"Sascha Hauer" <s.hauer@pengutronix.de>,
	"Pengutronix Kernel Team" <kernel@pengutronix.de>,
	"Fabio Estevam" <festevam@gmail.com>,
	"NXP Linux Team" <linux-imx@nxp.com>,
	"Kevin Hilman" <khilman@baylibre.com>,
	"Neil Armstrong" <narmstrong@baylibre.com>,
	"Jerome Brunet" <jbrunet@baylibre.com>,
	"Martin Blumenstingl" <martin.blumenstingl@googlemail.com>,
	"Vinod Koul" <vkoul@kernel.org>,
	"Nobuhiro Iwamatsu" <nobuhiro1.iwamatsu@toshiba.co.jp>,
	"Grygorii Strashko" <grygorii.strashko@ti.com>,
	"Wingman Kwok" <w-kwok2@ti.com>,
	"Murali Karicheri" <m-karicheri2@ti.com>,
	"Michal Simek" <michal.simek@xilinx.com>,
	"Radhey Shyam Pandey" <radhey.shyam.pandey@xilinx.com>,
	"Kalle Valo" <kvalo@codeaurora.org>,
	"Lorenzo Bianconi" <lorenzo.bianconi83@gmail.com>,
	"Ryder Lee" <ryder.lee@mediatek.com>,
	"Stanislaw Gruszka" <stf_xl@wp.pl>,
	"Helmut Schaa" <helmut.schaa@googlemail.com>,
	"Heiner Kallweit" <hkallweit1@gmail.com>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Frank Rowand" <frowand.list@gmail.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Jérôme Pouiller" <jerome.pouiller@silabs.com>,
	"Vivien Didelot" <vivien.didelot@gmail.com>,
	"Vladimir Oltean" <olteanv@gmail.com>
Subject: Re: [PATCH net-next v4 1/2] of: net: pass the dst buffer to of_get_mac_address()
Date: Tue, 13 Apr 2021 02:55:53 +0200	[thread overview]
Message-ID: <YHTsGXbbr8mkifDo@lunn.ch> (raw)
In-Reply-To: <20210412174718.17382-2-michael@walle.cc>

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!
> 
> <spml>
> @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
> </spml>
> 
> All drivers, except drivers/net/ethernet/aeroflex/greth.c, were
> compile-time tested.
> 
> Suggested-by: Andrew Lunn <andrew@lunn.ch>
> Signed-off-by: Michael Walle <michael@walle.cc>

I cannot say i looked at all the changes, but the ones i did exam
seemed O.K.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

WARNING: multiple messages have this Message-ID (diff)
From: Andrew Lunn <andrew@lunn.ch>
To: Michael Walle <michael@walle.cc>
Cc: "Paul Mackerras" <paulus@samba.org>,
	"Rafał Miłecki" <rafal@milecki.pl>,
	"Nobuhiro Iwamatsu" <nobuhiro1.iwamatsu@toshiba.co.jp>,
	linux-stm32@st-md-mailman.stormreply.com,
	"Jerome Brunet" <jbrunet@baylibre.com>,
	"Neil Armstrong" <narmstrong@baylibre.com>,
	"Michal Simek" <michal.simek@xilinx.com>,
	"Jose Abreu" <joabreu@synopsys.com>,
	"NXP Linux Team" <linux-imx@nxp.com>,
	"Mark Lee" <Mark-MC.Lee@mediatek.com>,
	"Hauke Mehrtens" <hauke@hauke-m.de>,
	"Sascha Hauer" <s.hauer@pengutronix.de>,
	"Lorenzo Bianconi" <lorenzo.bianconi83@gmail.com>,
	linux-omap@vger.kernel.org,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Pengutronix Kernel Team" <kernel@pengutronix.de>,
	"Vladimir Oltean" <olteanv@gmail.com>,
	"Claudiu Beznea" <claudiu.beznea@microchip.com>,
	"Jérôme Pouiller" <jerome.pouiller@silabs.com>,
	"Kunihiko Hayashi" <hayashi.kunihiko@socionext.com>,
	"Chris Snook" <chris.snook@gmail.com>,
	"Frank Rowand" <frowand.list@gmail.com>,
	"Gregory Clement" <gregory.clement@bootlin.com>,
	"Madalin Bucur" <madalin.bucur@nxp.com>,
	"Martin Blumenstingl" <martin.blumenstingl@googlemail.com>,
	"Murali Karicheri" <m-karicheri2@ti.com>,
	"Yisen Zhuang" <yisen.zhuang@huawei.com>,
	"Alexandre Torgue" <alexandre.torgue@st.com>,
	"Wingman Kwok" <w-kwok2@ti.com>,
	"Sean Wang" <sean.wang@mediatek.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Claudiu Manoil" <claudiu.manoil@nxp.com>,
	linux-amlogic@lists.infradead.org,
	"Kalle Valo" <kvalo@codeaurora.org>,
	"Mirko Lindner" <mlindner@marvell.com>,
	"Fugang Duan" <fugang.duan@nxp.com>,
	"Bryan Whitehead" <bryan.whitehead@microchip.com>,
	ath9k-devel@qca.qualcomm.com, UNGLinuxDriver@microchip.com,
	"Taras Chornyi" <tchornyi@marvell.com>,
	"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
	"Kevin Hilman" <khilman@baylibre.com>,
	"Heiner Kallweit" <hkallweit1@gmail.com>,
	"Andreas Larsson" <andreas@gaisler.com>,
	"Giuseppe Cavallaro" <peppe.cavallaro@st.com>,
	"Fabio Estevam" <festevam@gmail.com>,
	"Stanislaw Gruszka" <stf_xl@wp.pl>,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	linux-staging@lists.linux.dev, "Chen-Yu Tsai" <wens@csie.org>,
	bcm-kernel-feedback-list@broadcom.com,
	linux-arm-kernel@lists.infradead.org,
	"Grygorii Strashko" <grygorii.strashko@ti.com>,
	"Byungho An" <bh74.an@samsung.com>,
	"Radhey Shyam Pandey" <radhey.shyam.pandey@xilinx.com>,
	"Vladimir Zapolskiy" <vz@mleia.com>,
	"John Crispin" <john@phrozen.org>,
	"Salil Mehta" <salil.mehta@huawei.com>,
	"Sergei Shtylyov" <sergei.shtylyov@gmail.com>,
	linux-oxnas@groups.io, "Shawn Guo" <shawnguo@kernel.org>,
	"David S . Miller" <davem@davemloft.net>,
	"Helmut Schaa" <helmut.schaa@googlemail.com>,
	"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
	linux-renesas-soc@vger.kernel.org,
	"Ryder Lee" <ryder.lee@mediatek.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"Vadym Kochan" <vkochan@marvell.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Vivien Didelot" <vivien.didelot@gmail.com>,
	"Sunil Goutham" <sgoutham@marvell.com>,
	"Sebastian Hesselbarth" <sebastian.hesselbarth@gmail.com>,
	devicetree@vger.kernel.org, "Rob Herring" <robh+dt@kernel.org>,
	linux-mediatek@lists.infradead.org,
	"Matthias Brugger" <matthias.bgg@gmail.com>,
	"Jernej Skrabec" <jernej.skrabec@siol.net>,
	netdev@vger.kernel.org,
	"Nicolas Ferre" <nicolas.ferre@microchip.com>,
	"Li Yang" <leoyang.li@nxp.com>,
	"Stephen Hemminger" <stephen@networkplumber.org>,
	"Vinod Koul" <vkoul@kernel.org>,
	"Joyce Ooi" <joyce.ooi@intel.com>,
	linuxppc-dev@lists.ozlabs.org, "Felix Fietkau" <nbd@nbd.name>
Subject: Re: [PATCH net-next v4 1/2] of: net: pass the dst buffer to of_get_mac_address()
Date: Tue, 13 Apr 2021 02:55:53 +0200	[thread overview]
Message-ID: <YHTsGXbbr8mkifDo@lunn.ch> (raw)
In-Reply-To: <20210412174718.17382-2-michael@walle.cc>

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!
> 
> <spml>
> @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
> </spml>
> 
> All drivers, except drivers/net/ethernet/aeroflex/greth.c, were
> compile-time tested.
> 
> Suggested-by: Andrew Lunn <andrew@lunn.ch>
> Signed-off-by: Michael Walle <michael@walle.cc>

I cannot say i looked at all the changes, but the ones i did exam
seemed O.K.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

  reply	other threads:[~2021-04-13  0:56 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-12 17:47 [PATCH net-next v4 0/2] of: net: support non-platform devices in of_get_mac_address() Michael Walle
2021-04-12 17:47 ` Michael Walle
2021-04-12 17:47 ` Michael Walle
2021-04-12 17:47 ` Michael Walle
2021-04-12 17:47 ` [PATCH net-next v4 1/2] of: net: pass the dst buffer to of_get_mac_address() Michael Walle
2021-04-12 17:47   ` Michael Walle
2021-04-12 17:47   ` Michael Walle
2021-04-12 17:47   ` Michael Walle
2021-04-13  0:55   ` Andrew Lunn [this message]
2021-04-13  0:55     ` Andrew Lunn
2021-04-13  0:55     ` Andrew Lunn
2021-04-13  0:55     ` Andrew Lunn
2021-04-12 17:47 ` [PATCH net-next v4 2/2] of: net: fix of_get_mac_addr_nvmem() for non-platform devices Michael Walle
2021-04-12 17:47   ` Michael Walle
2021-04-12 17:47   ` Michael Walle
2021-04-12 17:47   ` Michael Walle
2021-04-13  0:57   ` Andrew Lunn
2021-04-13  0:57     ` Andrew Lunn
2021-04-13  0:57     ` Andrew Lunn
2021-04-13  0:57     ` Andrew Lunn
2021-04-16  3:24   ` Benjamin Herrenschmidt
2021-04-16  3:24     ` Benjamin Herrenschmidt
2021-04-16  3:24     ` Benjamin Herrenschmidt
2021-04-16  3:24     ` Benjamin Herrenschmidt
2021-04-16  7:29     ` Michael Walle
2021-04-16  7:29       ` Michael Walle
2021-04-16  7:29       ` Michael Walle
2021-04-16  7:29       ` Michael Walle
2021-04-16 15:19       ` Rob Herring
2021-04-16 15:19         ` Rob Herring
2021-04-16 15:19         ` Rob Herring
2021-04-16 15:19         ` Rob Herring
2021-04-26 10:54         ` Michael Walle
2021-04-26 10:54           ` Michael Walle
2021-04-26 10:54           ` Michael Walle
2021-04-26 10:54           ` Michael Walle
2021-04-26 23:44           ` Benjamin Herrenschmidt
2021-04-26 23:44             ` Benjamin Herrenschmidt
2021-04-26 23:44             ` Benjamin Herrenschmidt
2021-04-26 23:44             ` Benjamin Herrenschmidt
2021-04-28  8:09             ` Michael Walle
2021-04-28  8:09               ` Michael Walle
2021-04-28  8:09               ` Michael Walle
2021-04-28  8:09               ` Michael Walle
2021-04-13 21:40 ` [PATCH net-next v4 0/2] of: net: support non-platform devices in of_get_mac_address() patchwork-bot+netdevbpf
2021-04-13 21:40   ` patchwork-bot+netdevbpf
2021-04-13 21:40   ` patchwork-bot+netdevbpf
2021-04-13 21:40   ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YHTsGXbbr8mkifDo@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=Mark-MC.Lee@mediatek.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=alexandre.torgue@st.com \
    --cc=andreas@gaisler.com \
    --cc=ath9k-devel@qca.qualcomm.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=benh@kernel.crashing.org \
    --cc=bh74.an@samsung.com \
    --cc=bryan.whitehead@microchip.com \
    --cc=chris.snook@gmail.com \
    --cc=claudiu.beznea@microchip.com \
    --cc=claudiu.manoil@nxp.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=festevam@gmail.com \
    --cc=frowand.list@gmail.com \
    --cc=fugang.duan@nxp.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gregory.clement@bootlin.com \
    --cc=grygorii.strashko@ti.com \
    --cc=hauke@hauke-m.de \
    --cc=hayashi.kunihiko@socionext.com \
    --cc=helmut.schaa@googlemail.com \
    --cc=hkallweit1@gmail.com \
    --cc=jbrunet@baylibre.com \
    --cc=jernej.skrabec@siol.net \
    --cc=jerome.pouiller@silabs.com \
    --cc=joabreu@synopsys.com \
    --cc=john@phrozen.org \
    --cc=joyce.ooi@intel.com \
    --cc=kernel@pengutronix.de \
    --cc=khilman@baylibre.com \
    --cc=kuba@kernel.org \
    --cc=kvalo@codeaurora.org \
    --cc=leoyang.li@nxp.com \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-oxnas@groups.io \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=lorenzo.bianconi83@gmail.com \
    --cc=m-karicheri2@ti.com \
    --cc=madalin.bucur@nxp.com \
    --cc=martin.blumenstingl@googlemail.com \
    --cc=matthias.bgg@gmail.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=michael@walle.cc \
    --cc=michal.simek@xilinx.com \
    --cc=mlindner@marvell.com \
    --cc=mpe@ellerman.id.au \
    --cc=mripard@kernel.org \
    --cc=narmstrong@baylibre.com \
    --cc=nbd@nbd.name \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=nobuhiro1.iwamatsu@toshiba.co.jp \
    --cc=olteanv@gmail.com \
    --cc=pantelis.antoniou@gmail.com \
    --cc=paulus@samba.org \
    --cc=peppe.cavallaro@st.com \
    --cc=radhey.shyam.pandey@xilinx.com \
    --cc=rafal@milecki.pl \
    --cc=robh+dt@kernel.org \
    --cc=ryder.lee@mediatek.com \
    --cc=s.hauer@pengutronix.de \
    --cc=salil.mehta@huawei.com \
    --cc=sean.wang@mediatek.com \
    --cc=sebastian.hesselbarth@gmail.com \
    --cc=sergei.shtylyov@gmail.com \
    --cc=sgoutham@marvell.com \
    --cc=shawnguo@kernel.org \
    --cc=stephen@networkplumber.org \
    --cc=stf_xl@wp.pl \
    --cc=tchornyi@marvell.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=vivien.didelot@gmail.com \
    --cc=vkochan@marvell.com \
    --cc=vkoul@kernel.org \
    --cc=vz@mleia.com \
    --cc=w-kwok2@ti.com \
    --cc=wens@csie.org \
    --cc=yisen.zhuang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.