[PATCH 2/2] net: stmmac: Populate netdev of_node

Primoz Fiser posted 2 patches 2 months, 3 weeks ago
[PATCH 2/2] net: stmmac: Populate netdev of_node
Posted by Primoz Fiser 2 months, 3 weeks ago
Populate netdev of_node with device of_node so that the network device
inherits the device tree node information in case of platform device.
On the other hand, when stmmac_dvr_probe() is called from pci device,
of_node will be NULL preserving current behavior.

With this in place, when initiated from platform device, udev will be
able to export OF_* properties (OF_NAME, OF_FULLNAME, OF_COMPATIBLE,
OF_ALIAS, etc) for the network interface. These properties are commonly
used by udev rules and other userspace tools for device identification
and configuration.

Signed-off-by: Primoz Fiser <primoz.fiser@norik.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index f350a6662880..dfd503a87f22 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -7487,6 +7487,7 @@ int stmmac_dvr_probe(struct device *device,
 		return -ENOMEM;
 
 	SET_NETDEV_DEV(ndev, device);
+	ndev->dev.of_node = device->of_node;
 
 	priv = netdev_priv(ndev);
 	priv->device = device;
-- 
2.34.1
Re: [PATCH 2/2] net: stmmac: Populate netdev of_node
Posted by Peng Fan 2 months, 2 weeks ago
On Thu, Jul 17, 2025 at 11:00:37AM +0200, Primoz Fiser wrote:
>Populate netdev of_node with device of_node so that the network device
>inherits the device tree node information in case of platform device.
>On the other hand, when stmmac_dvr_probe() is called from pci device,
>of_node will be NULL preserving current behavior.
>
>With this in place, when initiated from platform device, udev will be
>able to export OF_* properties (OF_NAME, OF_FULLNAME, OF_COMPATIBLE,
>OF_ALIAS, etc) for the network interface. These properties are commonly
>used by udev rules and other userspace tools for device identification
>and configuration.
>
>Signed-off-by: Primoz Fiser <primoz.fiser@norik.com>
>---
> drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 1 +
> 1 file changed, 1 insertion(+)
>
>diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
>index f350a6662880..dfd503a87f22 100644
>--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
>+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
>@@ -7487,6 +7487,7 @@ int stmmac_dvr_probe(struct device *device,
> 		return -ENOMEM;
> 
> 	SET_NETDEV_DEV(ndev, device);
>+	ndev->dev.of_node = device->of_node;

You may need to device_set_node.

TBH: I am not sure why device_set_node does not increments the refcnt,
while device_set_of_node_from_dev has. But this driver supports
non-OF platform, so using device_set_of_node_from_dev may not be good,
and I would suggest use device_set_node.

Regards
Peng

> 
> 	priv = netdev_priv(ndev);
> 	priv->device = device;
>-- 
>2.34.1
>