All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] treewide: Fix instantiation of devices in DT overlays
@ 2023-03-24  9:30 ` Geert Uytterhoeven
  0 siblings, 0 replies; 16+ messages in thread
From: Geert Uytterhoeven @ 2023-03-24  9:30 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Saravana Kannan
  Cc: Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, Wolfram Sang, Rob Herring, Frank Rowand,
	Mark Brown, linux-arm-kernel, linux-i2c, devicetree, linux-spi,
	linux-renesas-soc, linux-kernel, Geert Uytterhoeven

When loading a DT overlay that creates a device, the device is not
instantiated, unless the DT overlay is unloaded and reloaded again.

Saravana explains:
  Basically for all overlays (I hope the function is only used for
  overlays) we assume all nodes are NOT devices until they actually
  get added as a device.

Based on a patch by Saravana Kannan, which covered only platform and spi
devices.

Fixes: 4a032827daa89350 ("of: property: Simplify of_link_to_phandle()")
Link: https://lore.kernel.org/r/CAGETcx_+rhHvaC_HJXGrr5_WAd2+k5f=rWYnkCZ6z5bGX-wj4w@mail.gmail.com
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Mark Brown <broonie@kernel.org>
---
v2:
  - Add Acked-by,
  - Drop RFC.
---
 drivers/bus/imx-weim.c    | 1 +
 drivers/i2c/i2c-core-of.c | 1 +
 drivers/of/dynamic.c      | 1 +
 drivers/of/platform.c     | 1 +
 drivers/spi/spi.c         | 1 +
 5 files changed, 5 insertions(+)

diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
index 36d42484142aede2..898e23a4231400fa 100644
--- a/drivers/bus/imx-weim.c
+++ b/drivers/bus/imx-weim.c
@@ -329,6 +329,7 @@ static int of_weim_notify(struct notifier_block *nb, unsigned long action,
 				 "Failed to setup timing for '%pOF'\n", rd->dn);
 
 		if (!of_node_check_flag(rd->dn, OF_POPULATED)) {
+			rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
 			if (!of_platform_device_create(rd->dn, NULL, &pdev->dev)) {
 				dev_err(&pdev->dev,
 					"Failed to create child device '%pOF'\n",
diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
index aa93467784c29c89..303f9003562eed3d 100644
--- a/drivers/i2c/i2c-core-of.c
+++ b/drivers/i2c/i2c-core-of.c
@@ -178,6 +178,7 @@ static int of_i2c_notify(struct notifier_block *nb, unsigned long action,
 			return NOTIFY_OK;
 		}
 
+		rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
 		client = of_i2c_register_device(adap, rd->dn);
 		if (IS_ERR(client)) {
 			dev_err(&adap->dev, "failed to create client for '%pOF'\n",
diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
index 07d93753b12f5f4d..e311d406b1705306 100644
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -226,6 +226,7 @@ static void __of_attach_node(struct device_node *np)
 	np->sibling = np->parent->child;
 	np->parent->child = np;
 	of_node_clear_flag(np, OF_DETACHED);
+	np->fwnode.flags |= FWNODE_FLAG_NOT_DEVICE;
 }
 
 /**
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index b2bd2e783445dd78..17c92cbfb62ee3ef 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -737,6 +737,7 @@ static int of_platform_notify(struct notifier_block *nb,
 		if (of_node_check_flag(rd->dn, OF_POPULATED))
 			return NOTIFY_OK;
 
+		rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
 		/* pdev_parent may be NULL when no bus platform device */
 		pdev_parent = of_find_device_by_node(rd->dn->parent);
 		pdev = of_platform_device_create(rd->dn, NULL,
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 8e8af148b1dc371e..66ac67580d2a473b 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -4527,6 +4527,7 @@ static int of_spi_notify(struct notifier_block *nb, unsigned long action,
 			return NOTIFY_OK;
 		}
 
+		rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
 		spi = of_register_spi_device(ctlr, rd->dn);
 		put_device(&ctlr->dev);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2] treewide: Fix instantiation of devices in DT overlays
@ 2023-03-24  9:30 ` Geert Uytterhoeven
  0 siblings, 0 replies; 16+ messages in thread
From: Geert Uytterhoeven @ 2023-03-24  9:30 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Saravana Kannan
  Cc: Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, Wolfram Sang, Rob Herring, Frank Rowand,
	Mark Brown, linux-arm-kernel, linux-i2c, devicetree, linux-spi,
	linux-renesas-soc, linux-kernel, Geert Uytterhoeven

When loading a DT overlay that creates a device, the device is not
instantiated, unless the DT overlay is unloaded and reloaded again.

Saravana explains:
  Basically for all overlays (I hope the function is only used for
  overlays) we assume all nodes are NOT devices until they actually
  get added as a device.

Based on a patch by Saravana Kannan, which covered only platform and spi
devices.

Fixes: 4a032827daa89350 ("of: property: Simplify of_link_to_phandle()")
Link: https://lore.kernel.org/r/CAGETcx_+rhHvaC_HJXGrr5_WAd2+k5f=rWYnkCZ6z5bGX-wj4w@mail.gmail.com
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Mark Brown <broonie@kernel.org>
---
v2:
  - Add Acked-by,
  - Drop RFC.
---
 drivers/bus/imx-weim.c    | 1 +
 drivers/i2c/i2c-core-of.c | 1 +
 drivers/of/dynamic.c      | 1 +
 drivers/of/platform.c     | 1 +
 drivers/spi/spi.c         | 1 +
 5 files changed, 5 insertions(+)

diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
index 36d42484142aede2..898e23a4231400fa 100644
--- a/drivers/bus/imx-weim.c
+++ b/drivers/bus/imx-weim.c
@@ -329,6 +329,7 @@ static int of_weim_notify(struct notifier_block *nb, unsigned long action,
 				 "Failed to setup timing for '%pOF'\n", rd->dn);
 
 		if (!of_node_check_flag(rd->dn, OF_POPULATED)) {
+			rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
 			if (!of_platform_device_create(rd->dn, NULL, &pdev->dev)) {
 				dev_err(&pdev->dev,
 					"Failed to create child device '%pOF'\n",
diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
index aa93467784c29c89..303f9003562eed3d 100644
--- a/drivers/i2c/i2c-core-of.c
+++ b/drivers/i2c/i2c-core-of.c
@@ -178,6 +178,7 @@ static int of_i2c_notify(struct notifier_block *nb, unsigned long action,
 			return NOTIFY_OK;
 		}
 
+		rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
 		client = of_i2c_register_device(adap, rd->dn);
 		if (IS_ERR(client)) {
 			dev_err(&adap->dev, "failed to create client for '%pOF'\n",
diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
index 07d93753b12f5f4d..e311d406b1705306 100644
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -226,6 +226,7 @@ static void __of_attach_node(struct device_node *np)
 	np->sibling = np->parent->child;
 	np->parent->child = np;
 	of_node_clear_flag(np, OF_DETACHED);
+	np->fwnode.flags |= FWNODE_FLAG_NOT_DEVICE;
 }
 
 /**
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index b2bd2e783445dd78..17c92cbfb62ee3ef 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -737,6 +737,7 @@ static int of_platform_notify(struct notifier_block *nb,
 		if (of_node_check_flag(rd->dn, OF_POPULATED))
 			return NOTIFY_OK;
 
+		rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
 		/* pdev_parent may be NULL when no bus platform device */
 		pdev_parent = of_find_device_by_node(rd->dn->parent);
 		pdev = of_platform_device_create(rd->dn, NULL,
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 8e8af148b1dc371e..66ac67580d2a473b 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -4527,6 +4527,7 @@ static int of_spi_notify(struct notifier_block *nb, unsigned long action,
 			return NOTIFY_OK;
 		}
 
+		rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
 		spi = of_register_spi_device(ctlr, rd->dn);
 		put_device(&ctlr->dev);
 
-- 
2.34.1


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

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] treewide: Fix instantiation of devices in DT overlays
  2023-03-24  9:30 ` Geert Uytterhoeven
@ 2023-03-27  2:52   ` Frank Rowand
  -1 siblings, 0 replies; 16+ messages in thread
From: Frank Rowand @ 2023-03-27  2:52 UTC (permalink / raw)
  To: Geert Uytterhoeven, Greg Kroah-Hartman, Saravana Kannan
  Cc: Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, Wolfram Sang, Rob Herring, Mark Brown,
	linux-arm-kernel, linux-i2c, devicetree, linux-spi,
	linux-renesas-soc, linux-kernel

On 3/24/23 04:30, Geert Uytterhoeven wrote:
> When loading a DT overlay that creates a device, the device is not
> instantiated, unless the DT overlay is unloaded and reloaded again.
> 
> Saravana explains:
>   Basically for all overlays (I hope the function is only used for
>   overlays) we assume all nodes are NOT devices until they actually
>   get added as a device.
> 
> Based on a patch by Saravana Kannan, which covered only platform and spi
> devices.

I have given this a quick look but want to look more deeply at overall
context.  (That Geert found imx-weim, i2c, and spi is a good sign.)

At the top of my list for Monday 3/27.

-Frank

> 
> Fixes: 4a032827daa89350 ("of: property: Simplify of_link_to_phandle()")
> Link: https://lore.kernel.org/r/CAGETcx_+rhHvaC_HJXGrr5_WAd2+k5f=rWYnkCZ6z5bGX-wj4w@mail.gmail.com
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Acked-by: Mark Brown <broonie@kernel.org>
> ---
> v2:
>   - Add Acked-by,
>   - Drop RFC.
> ---
>  drivers/bus/imx-weim.c    | 1 +
>  drivers/i2c/i2c-core-of.c | 1 +
>  drivers/of/dynamic.c      | 1 +
>  drivers/of/platform.c     | 1 +
>  drivers/spi/spi.c         | 1 +
>  5 files changed, 5 insertions(+)
> 
> diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
> index 36d42484142aede2..898e23a4231400fa 100644
> --- a/drivers/bus/imx-weim.c
> +++ b/drivers/bus/imx-weim.c
> @@ -329,6 +329,7 @@ static int of_weim_notify(struct notifier_block *nb, unsigned long action,
>  				 "Failed to setup timing for '%pOF'\n", rd->dn);
>  
>  		if (!of_node_check_flag(rd->dn, OF_POPULATED)) {
> +			rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>  			if (!of_platform_device_create(rd->dn, NULL, &pdev->dev)) {
>  				dev_err(&pdev->dev,
>  					"Failed to create child device '%pOF'\n",
> diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
> index aa93467784c29c89..303f9003562eed3d 100644
> --- a/drivers/i2c/i2c-core-of.c
> +++ b/drivers/i2c/i2c-core-of.c
> @@ -178,6 +178,7 @@ static int of_i2c_notify(struct notifier_block *nb, unsigned long action,
>  			return NOTIFY_OK;
>  		}
>  
> +		rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>  		client = of_i2c_register_device(adap, rd->dn);
>  		if (IS_ERR(client)) {
>  			dev_err(&adap->dev, "failed to create client for '%pOF'\n",
> diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
> index 07d93753b12f5f4d..e311d406b1705306 100644
> --- a/drivers/of/dynamic.c
> +++ b/drivers/of/dynamic.c
> @@ -226,6 +226,7 @@ static void __of_attach_node(struct device_node *np)
>  	np->sibling = np->parent->child;
>  	np->parent->child = np;
>  	of_node_clear_flag(np, OF_DETACHED);
> +	np->fwnode.flags |= FWNODE_FLAG_NOT_DEVICE;
>  }
>  
>  /**
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> index b2bd2e783445dd78..17c92cbfb62ee3ef 100644
> --- a/drivers/of/platform.c
> +++ b/drivers/of/platform.c
> @@ -737,6 +737,7 @@ static int of_platform_notify(struct notifier_block *nb,
>  		if (of_node_check_flag(rd->dn, OF_POPULATED))
>  			return NOTIFY_OK;
>  
> +		rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>  		/* pdev_parent may be NULL when no bus platform device */
>  		pdev_parent = of_find_device_by_node(rd->dn->parent);
>  		pdev = of_platform_device_create(rd->dn, NULL,
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 8e8af148b1dc371e..66ac67580d2a473b 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -4527,6 +4527,7 @@ static int of_spi_notify(struct notifier_block *nb, unsigned long action,
>  			return NOTIFY_OK;
>  		}
>  
> +		rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>  		spi = of_register_spi_device(ctlr, rd->dn);
>  		put_device(&ctlr->dev);
>  


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] treewide: Fix instantiation of devices in DT overlays
@ 2023-03-27  2:52   ` Frank Rowand
  0 siblings, 0 replies; 16+ messages in thread
From: Frank Rowand @ 2023-03-27  2:52 UTC (permalink / raw)
  To: Geert Uytterhoeven, Greg Kroah-Hartman, Saravana Kannan
  Cc: Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, Wolfram Sang, Rob Herring, Mark Brown,
	linux-arm-kernel, linux-i2c, devicetree, linux-spi,
	linux-renesas-soc, linux-kernel

On 3/24/23 04:30, Geert Uytterhoeven wrote:
> When loading a DT overlay that creates a device, the device is not
> instantiated, unless the DT overlay is unloaded and reloaded again.
> 
> Saravana explains:
>   Basically for all overlays (I hope the function is only used for
>   overlays) we assume all nodes are NOT devices until they actually
>   get added as a device.
> 
> Based on a patch by Saravana Kannan, which covered only platform and spi
> devices.

I have given this a quick look but want to look more deeply at overall
context.  (That Geert found imx-weim, i2c, and spi is a good sign.)

At the top of my list for Monday 3/27.

-Frank

> 
> Fixes: 4a032827daa89350 ("of: property: Simplify of_link_to_phandle()")
> Link: https://lore.kernel.org/r/CAGETcx_+rhHvaC_HJXGrr5_WAd2+k5f=rWYnkCZ6z5bGX-wj4w@mail.gmail.com
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Acked-by: Mark Brown <broonie@kernel.org>
> ---
> v2:
>   - Add Acked-by,
>   - Drop RFC.
> ---
>  drivers/bus/imx-weim.c    | 1 +
>  drivers/i2c/i2c-core-of.c | 1 +
>  drivers/of/dynamic.c      | 1 +
>  drivers/of/platform.c     | 1 +
>  drivers/spi/spi.c         | 1 +
>  5 files changed, 5 insertions(+)
> 
> diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
> index 36d42484142aede2..898e23a4231400fa 100644
> --- a/drivers/bus/imx-weim.c
> +++ b/drivers/bus/imx-weim.c
> @@ -329,6 +329,7 @@ static int of_weim_notify(struct notifier_block *nb, unsigned long action,
>  				 "Failed to setup timing for '%pOF'\n", rd->dn);
>  
>  		if (!of_node_check_flag(rd->dn, OF_POPULATED)) {
> +			rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>  			if (!of_platform_device_create(rd->dn, NULL, &pdev->dev)) {
>  				dev_err(&pdev->dev,
>  					"Failed to create child device '%pOF'\n",
> diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
> index aa93467784c29c89..303f9003562eed3d 100644
> --- a/drivers/i2c/i2c-core-of.c
> +++ b/drivers/i2c/i2c-core-of.c
> @@ -178,6 +178,7 @@ static int of_i2c_notify(struct notifier_block *nb, unsigned long action,
>  			return NOTIFY_OK;
>  		}
>  
> +		rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>  		client = of_i2c_register_device(adap, rd->dn);
>  		if (IS_ERR(client)) {
>  			dev_err(&adap->dev, "failed to create client for '%pOF'\n",
> diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
> index 07d93753b12f5f4d..e311d406b1705306 100644
> --- a/drivers/of/dynamic.c
> +++ b/drivers/of/dynamic.c
> @@ -226,6 +226,7 @@ static void __of_attach_node(struct device_node *np)
>  	np->sibling = np->parent->child;
>  	np->parent->child = np;
>  	of_node_clear_flag(np, OF_DETACHED);
> +	np->fwnode.flags |= FWNODE_FLAG_NOT_DEVICE;
>  }
>  
>  /**
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> index b2bd2e783445dd78..17c92cbfb62ee3ef 100644
> --- a/drivers/of/platform.c
> +++ b/drivers/of/platform.c
> @@ -737,6 +737,7 @@ static int of_platform_notify(struct notifier_block *nb,
>  		if (of_node_check_flag(rd->dn, OF_POPULATED))
>  			return NOTIFY_OK;
>  
> +		rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>  		/* pdev_parent may be NULL when no bus platform device */
>  		pdev_parent = of_find_device_by_node(rd->dn->parent);
>  		pdev = of_platform_device_create(rd->dn, NULL,
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 8e8af148b1dc371e..66ac67580d2a473b 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -4527,6 +4527,7 @@ static int of_spi_notify(struct notifier_block *nb, unsigned long action,
>  			return NOTIFY_OK;
>  		}
>  
> +		rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>  		spi = of_register_spi_device(ctlr, rd->dn);
>  		put_device(&ctlr->dev);
>  


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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] treewide: Fix instantiation of devices in DT overlays
  2023-03-24  9:30 ` Geert Uytterhoeven
@ 2023-03-27  3:02   ` Shawn Guo
  -1 siblings, 0 replies; 16+ messages in thread
From: Shawn Guo @ 2023-03-27  3:02 UTC (permalink / raw)
  To: Geert Uytterhoeven, Ivan Bornyakov
  Cc: Greg Kroah-Hartman, Saravana Kannan, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team,
	Wolfram Sang, Rob Herring, Frank Rowand, Mark Brown,
	linux-arm-kernel, linux-i2c, devicetree, linux-spi,
	linux-renesas-soc, linux-kernel

+ Ivan

On Fri, Mar 24, 2023 at 10:30:39AM +0100, Geert Uytterhoeven wrote:
> When loading a DT overlay that creates a device, the device is not
> instantiated, unless the DT overlay is unloaded and reloaded again.
> 
> Saravana explains:
>   Basically for all overlays (I hope the function is only used for
>   overlays) we assume all nodes are NOT devices until they actually
>   get added as a device.
> 
> Based on a patch by Saravana Kannan, which covered only platform and spi
> devices.
> 
> Fixes: 4a032827daa89350 ("of: property: Simplify of_link_to_phandle()")
> Link: https://lore.kernel.org/r/CAGETcx_+rhHvaC_HJXGrr5_WAd2+k5f=rWYnkCZ6z5bGX-wj4w@mail.gmail.com
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Acked-by: Mark Brown <broonie@kernel.org>
> ---
> v2:
>   - Add Acked-by,
>   - Drop RFC.
> ---
>  drivers/bus/imx-weim.c    | 1 +
>  drivers/i2c/i2c-core-of.c | 1 +
>  drivers/of/dynamic.c      | 1 +
>  drivers/of/platform.c     | 1 +
>  drivers/spi/spi.c         | 1 +
>  5 files changed, 5 insertions(+)
> 
> diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
> index 36d42484142aede2..898e23a4231400fa 100644
> --- a/drivers/bus/imx-weim.c
> +++ b/drivers/bus/imx-weim.c
> @@ -329,6 +329,7 @@ static int of_weim_notify(struct notifier_block *nb, unsigned long action,
>  				 "Failed to setup timing for '%pOF'\n", rd->dn);
>  
>  		if (!of_node_check_flag(rd->dn, OF_POPULATED)) {
> +			rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>  			if (!of_platform_device_create(rd->dn, NULL, &pdev->dev)) {
>  				dev_err(&pdev->dev,
>  					"Failed to create child device '%pOF'\n",

Ivan, so you were aware of that the device is not instantiated before
this change?

Shawn

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] treewide: Fix instantiation of devices in DT overlays
@ 2023-03-27  3:02   ` Shawn Guo
  0 siblings, 0 replies; 16+ messages in thread
From: Shawn Guo @ 2023-03-27  3:02 UTC (permalink / raw)
  To: Geert Uytterhoeven, Ivan Bornyakov
  Cc: Greg Kroah-Hartman, Saravana Kannan, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team,
	Wolfram Sang, Rob Herring, Frank Rowand, Mark Brown,
	linux-arm-kernel, linux-i2c, devicetree, linux-spi,
	linux-renesas-soc, linux-kernel

+ Ivan

On Fri, Mar 24, 2023 at 10:30:39AM +0100, Geert Uytterhoeven wrote:
> When loading a DT overlay that creates a device, the device is not
> instantiated, unless the DT overlay is unloaded and reloaded again.
> 
> Saravana explains:
>   Basically for all overlays (I hope the function is only used for
>   overlays) we assume all nodes are NOT devices until they actually
>   get added as a device.
> 
> Based on a patch by Saravana Kannan, which covered only platform and spi
> devices.
> 
> Fixes: 4a032827daa89350 ("of: property: Simplify of_link_to_phandle()")
> Link: https://lore.kernel.org/r/CAGETcx_+rhHvaC_HJXGrr5_WAd2+k5f=rWYnkCZ6z5bGX-wj4w@mail.gmail.com
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Acked-by: Mark Brown <broonie@kernel.org>
> ---
> v2:
>   - Add Acked-by,
>   - Drop RFC.
> ---
>  drivers/bus/imx-weim.c    | 1 +
>  drivers/i2c/i2c-core-of.c | 1 +
>  drivers/of/dynamic.c      | 1 +
>  drivers/of/platform.c     | 1 +
>  drivers/spi/spi.c         | 1 +
>  5 files changed, 5 insertions(+)
> 
> diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
> index 36d42484142aede2..898e23a4231400fa 100644
> --- a/drivers/bus/imx-weim.c
> +++ b/drivers/bus/imx-weim.c
> @@ -329,6 +329,7 @@ static int of_weim_notify(struct notifier_block *nb, unsigned long action,
>  				 "Failed to setup timing for '%pOF'\n", rd->dn);
>  
>  		if (!of_node_check_flag(rd->dn, OF_POPULATED)) {
> +			rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>  			if (!of_platform_device_create(rd->dn, NULL, &pdev->dev)) {
>  				dev_err(&pdev->dev,
>  					"Failed to create child device '%pOF'\n",

Ivan, so you were aware of that the device is not instantiated before
this change?

Shawn

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] treewide: Fix instantiation of devices in DT overlays
  2023-03-27  3:02   ` Shawn Guo
@ 2023-03-27  8:54     ` Ivan Bornyakov
  -1 siblings, 0 replies; 16+ messages in thread
From: Ivan Bornyakov @ 2023-03-27  8:54 UTC (permalink / raw)
  To: Shawn Guo
  Cc: Geert Uytterhoeven, Greg Kroah-Hartman, Saravana Kannan,
	Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, Wolfram Sang, Rob Herring, Frank Rowand,
	Mark Brown, linux-arm-kernel, linux-i2c, devicetree, linux-spi,
	linux-renesas-soc, linux-kernel

Hi, Shawn!

On Mon, Mar 27, 2023 at 11:02:13AM +0800, Shawn Guo wrote:
> + Ivan
> 
> On Fri, Mar 24, 2023 at 10:30:39AM +0100, Geert Uytterhoeven wrote:
> > When loading a DT overlay that creates a device, the device is not
> > instantiated, unless the DT overlay is unloaded and reloaded again.
> > 
> > Saravana explains:
> >   Basically for all overlays (I hope the function is only used for
> >   overlays) we assume all nodes are NOT devices until they actually
> >   get added as a device.
> > 
> > Based on a patch by Saravana Kannan, which covered only platform and spi
> > devices.
> > 
> > Fixes: 4a032827daa89350 ("of: property: Simplify of_link_to_phandle()")
> > Link: https://lore.kernel.org/r/CAGETcx_+rhHvaC_HJXGrr5_WAd2+k5f=rWYnkCZ6z5bGX-wj4w@mail.gmail.com
> > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> > Acked-by: Mark Brown <broonie@kernel.org>
> > ---
> > v2:
> >   - Add Acked-by,
> >   - Drop RFC.
> > ---
> >  drivers/bus/imx-weim.c    | 1 +
> >  drivers/i2c/i2c-core-of.c | 1 +
> >  drivers/of/dynamic.c      | 1 +
> >  drivers/of/platform.c     | 1 +
> >  drivers/spi/spi.c         | 1 +
> >  5 files changed, 5 insertions(+)
> > 
> > diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
> > index 36d42484142aede2..898e23a4231400fa 100644
> > --- a/drivers/bus/imx-weim.c
> > +++ b/drivers/bus/imx-weim.c
> > @@ -329,6 +329,7 @@ static int of_weim_notify(struct notifier_block *nb, unsigned long action,
> >  				 "Failed to setup timing for '%pOF'\n", rd->dn);
> >  
> >  		if (!of_node_check_flag(rd->dn, OF_POPULATED)) {
> > +			rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
> >  			if (!of_platform_device_create(rd->dn, NULL, &pdev->dev)) {
> >  				dev_err(&pdev->dev,
> >  					"Failed to create child device '%pOF'\n",
> 
> Ivan, so you were aware of that the device is not instantiated before
> this change?
> 

I was not aware of that, thanks for warning me.
Will test in the near future.


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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] treewide: Fix instantiation of devices in DT overlays
@ 2023-03-27  8:54     ` Ivan Bornyakov
  0 siblings, 0 replies; 16+ messages in thread
From: Ivan Bornyakov @ 2023-03-27  8:54 UTC (permalink / raw)
  To: Shawn Guo
  Cc: Geert Uytterhoeven, Greg Kroah-Hartman, Saravana Kannan,
	Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, Wolfram Sang, Rob Herring, Frank Rowand,
	Mark Brown, linux-arm-kernel, linux-i2c, devicetree, linux-spi,
	linux-renesas-soc, linux-kernel

Hi, Shawn!

On Mon, Mar 27, 2023 at 11:02:13AM +0800, Shawn Guo wrote:
> + Ivan
> 
> On Fri, Mar 24, 2023 at 10:30:39AM +0100, Geert Uytterhoeven wrote:
> > When loading a DT overlay that creates a device, the device is not
> > instantiated, unless the DT overlay is unloaded and reloaded again.
> > 
> > Saravana explains:
> >   Basically for all overlays (I hope the function is only used for
> >   overlays) we assume all nodes are NOT devices until they actually
> >   get added as a device.
> > 
> > Based on a patch by Saravana Kannan, which covered only platform and spi
> > devices.
> > 
> > Fixes: 4a032827daa89350 ("of: property: Simplify of_link_to_phandle()")
> > Link: https://lore.kernel.org/r/CAGETcx_+rhHvaC_HJXGrr5_WAd2+k5f=rWYnkCZ6z5bGX-wj4w@mail.gmail.com
> > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> > Acked-by: Mark Brown <broonie@kernel.org>
> > ---
> > v2:
> >   - Add Acked-by,
> >   - Drop RFC.
> > ---
> >  drivers/bus/imx-weim.c    | 1 +
> >  drivers/i2c/i2c-core-of.c | 1 +
> >  drivers/of/dynamic.c      | 1 +
> >  drivers/of/platform.c     | 1 +
> >  drivers/spi/spi.c         | 1 +
> >  5 files changed, 5 insertions(+)
> > 
> > diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
> > index 36d42484142aede2..898e23a4231400fa 100644
> > --- a/drivers/bus/imx-weim.c
> > +++ b/drivers/bus/imx-weim.c
> > @@ -329,6 +329,7 @@ static int of_weim_notify(struct notifier_block *nb, unsigned long action,
> >  				 "Failed to setup timing for '%pOF'\n", rd->dn);
> >  
> >  		if (!of_node_check_flag(rd->dn, OF_POPULATED)) {
> > +			rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
> >  			if (!of_platform_device_create(rd->dn, NULL, &pdev->dev)) {
> >  				dev_err(&pdev->dev,
> >  					"Failed to create child device '%pOF'\n",
> 
> Ivan, so you were aware of that the device is not instantiated before
> this change?
> 

I was not aware of that, thanks for warning me.
Will test in the near future.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] treewide: Fix instantiation of devices in DT overlays
  2023-03-24  9:30 ` Geert Uytterhoeven
@ 2023-03-29 16:06   ` Frank Rowand
  -1 siblings, 0 replies; 16+ messages in thread
From: Frank Rowand @ 2023-03-29 16:06 UTC (permalink / raw)
  To: Geert Uytterhoeven, Greg Kroah-Hartman, Saravana Kannan
  Cc: Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, Wolfram Sang, Rob Herring, Mark Brown,
	linux-arm-kernel, linux-i2c, devicetree, linux-spi,
	linux-renesas-soc, linux-kernel

On 3/24/23 04:30, Geert Uytterhoeven wrote:
> When loading a DT overlay that creates a device, the device is not
> instantiated, unless the DT overlay is unloaded and reloaded again.

Can you elaborate on why this is?  What the relevant code paths are?

> 
> Saravana explains:
>   Basically for all overlays (I hope the function is only used for
>   overlays) we assume all nodes are NOT devices until they actually
>   get added as a device.
> 
> Based on a patch by Saravana Kannan, which covered only platform and spi
> devices.


> 
> Fixes: 4a032827daa89350 ("of: property: Simplify of_link_to_phandle()")

From a quick scan of the fixed commit, I don't see how that commit caused the problem.
Can you give a quick clue?  (The clue does not need to be added to the commit message,
but please at least put it below the "---" if there are additional versions of this
patch.)

> Link: https://lore.kernel.org/r/CAGETcx_+rhHvaC_HJXGrr5_WAd2+k5f=rWYnkCZ6z5bGX-wj4w@mail.gmail.com
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Acked-by: Mark Brown <broonie@kernel.org>
> ---
> v2:
>   - Add Acked-by,
>   - Drop RFC.
> ---
>  drivers/bus/imx-weim.c    | 1 +
>  drivers/i2c/i2c-core-of.c | 1 +
>  drivers/of/dynamic.c      | 1 +
>  drivers/of/platform.c     | 1 +
>  drivers/spi/spi.c         | 1 +
>  5 files changed, 5 insertions(+)
> 
> diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
> index 36d42484142aede2..898e23a4231400fa 100644
> --- a/drivers/bus/imx-weim.c
> +++ b/drivers/bus/imx-weim.c
> @@ -329,6 +329,7 @@ static int of_weim_notify(struct notifier_block *nb, unsigned long action,
>  				 "Failed to setup timing for '%pOF'\n", rd->dn);
>  
>  		if (!of_node_check_flag(rd->dn, OF_POPULATED)) {
> +			rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>  			if (!of_platform_device_create(rd->dn, NULL, &pdev->dev)) {
>  				dev_err(&pdev->dev,
>  					"Failed to create child device '%pOF'\n",
> diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
> index aa93467784c29c89..303f9003562eed3d 100644
> --- a/drivers/i2c/i2c-core-of.c
> +++ b/drivers/i2c/i2c-core-of.c
> @@ -178,6 +178,7 @@ static int of_i2c_notify(struct notifier_block *nb, unsigned long action,
>  			return NOTIFY_OK;
>  		}
>  
> +		rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>  		client = of_i2c_register_device(adap, rd->dn);
>  		if (IS_ERR(client)) {
>  			dev_err(&adap->dev, "failed to create client for '%pOF'\n",
> diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
> index 07d93753b12f5f4d..e311d406b1705306 100644
> --- a/drivers/of/dynamic.c
> +++ b/drivers/of/dynamic.c
> @@ -226,6 +226,7 @@ static void __of_attach_node(struct device_node *np)
>  	np->sibling = np->parent->child;
>  	np->parent->child = np;
>  	of_node_clear_flag(np, OF_DETACHED);
> +	np->fwnode.flags |= FWNODE_FLAG_NOT_DEVICE;
>  }
>  
>  /**
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> index b2bd2e783445dd78..17c92cbfb62ee3ef 100644
> --- a/drivers/of/platform.c
> +++ b/drivers/of/platform.c
> @@ -737,6 +737,7 @@ static int of_platform_notify(struct notifier_block *nb,
>  		if (of_node_check_flag(rd->dn, OF_POPULATED))
>  			return NOTIFY_OK;
>  
> +		rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>  		/* pdev_parent may be NULL when no bus platform device */
>  		pdev_parent = of_find_device_by_node(rd->dn->parent);
>  		pdev = of_platform_device_create(rd->dn, NULL,
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 8e8af148b1dc371e..66ac67580d2a473b 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -4527,6 +4527,7 @@ static int of_spi_notify(struct notifier_block *nb, unsigned long action,
>  			return NOTIFY_OK;
>  		}
>  
> +		rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>  		spi = of_register_spi_device(ctlr, rd->dn);
>  		put_device(&ctlr->dev);
>  


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] treewide: Fix instantiation of devices in DT overlays
@ 2023-03-29 16:06   ` Frank Rowand
  0 siblings, 0 replies; 16+ messages in thread
From: Frank Rowand @ 2023-03-29 16:06 UTC (permalink / raw)
  To: Geert Uytterhoeven, Greg Kroah-Hartman, Saravana Kannan
  Cc: Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, Wolfram Sang, Rob Herring, Mark Brown,
	linux-arm-kernel, linux-i2c, devicetree, linux-spi,
	linux-renesas-soc, linux-kernel

On 3/24/23 04:30, Geert Uytterhoeven wrote:
> When loading a DT overlay that creates a device, the device is not
> instantiated, unless the DT overlay is unloaded and reloaded again.

Can you elaborate on why this is?  What the relevant code paths are?

> 
> Saravana explains:
>   Basically for all overlays (I hope the function is only used for
>   overlays) we assume all nodes are NOT devices until they actually
>   get added as a device.
> 
> Based on a patch by Saravana Kannan, which covered only platform and spi
> devices.


> 
> Fixes: 4a032827daa89350 ("of: property: Simplify of_link_to_phandle()")

From a quick scan of the fixed commit, I don't see how that commit caused the problem.
Can you give a quick clue?  (The clue does not need to be added to the commit message,
but please at least put it below the "---" if there are additional versions of this
patch.)

> Link: https://lore.kernel.org/r/CAGETcx_+rhHvaC_HJXGrr5_WAd2+k5f=rWYnkCZ6z5bGX-wj4w@mail.gmail.com
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Acked-by: Mark Brown <broonie@kernel.org>
> ---
> v2:
>   - Add Acked-by,
>   - Drop RFC.
> ---
>  drivers/bus/imx-weim.c    | 1 +
>  drivers/i2c/i2c-core-of.c | 1 +
>  drivers/of/dynamic.c      | 1 +
>  drivers/of/platform.c     | 1 +
>  drivers/spi/spi.c         | 1 +
>  5 files changed, 5 insertions(+)
> 
> diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
> index 36d42484142aede2..898e23a4231400fa 100644
> --- a/drivers/bus/imx-weim.c
> +++ b/drivers/bus/imx-weim.c
> @@ -329,6 +329,7 @@ static int of_weim_notify(struct notifier_block *nb, unsigned long action,
>  				 "Failed to setup timing for '%pOF'\n", rd->dn);
>  
>  		if (!of_node_check_flag(rd->dn, OF_POPULATED)) {
> +			rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>  			if (!of_platform_device_create(rd->dn, NULL, &pdev->dev)) {
>  				dev_err(&pdev->dev,
>  					"Failed to create child device '%pOF'\n",
> diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
> index aa93467784c29c89..303f9003562eed3d 100644
> --- a/drivers/i2c/i2c-core-of.c
> +++ b/drivers/i2c/i2c-core-of.c
> @@ -178,6 +178,7 @@ static int of_i2c_notify(struct notifier_block *nb, unsigned long action,
>  			return NOTIFY_OK;
>  		}
>  
> +		rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>  		client = of_i2c_register_device(adap, rd->dn);
>  		if (IS_ERR(client)) {
>  			dev_err(&adap->dev, "failed to create client for '%pOF'\n",
> diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
> index 07d93753b12f5f4d..e311d406b1705306 100644
> --- a/drivers/of/dynamic.c
> +++ b/drivers/of/dynamic.c
> @@ -226,6 +226,7 @@ static void __of_attach_node(struct device_node *np)
>  	np->sibling = np->parent->child;
>  	np->parent->child = np;
>  	of_node_clear_flag(np, OF_DETACHED);
> +	np->fwnode.flags |= FWNODE_FLAG_NOT_DEVICE;
>  }
>  
>  /**
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> index b2bd2e783445dd78..17c92cbfb62ee3ef 100644
> --- a/drivers/of/platform.c
> +++ b/drivers/of/platform.c
> @@ -737,6 +737,7 @@ static int of_platform_notify(struct notifier_block *nb,
>  		if (of_node_check_flag(rd->dn, OF_POPULATED))
>  			return NOTIFY_OK;
>  
> +		rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>  		/* pdev_parent may be NULL when no bus platform device */
>  		pdev_parent = of_find_device_by_node(rd->dn->parent);
>  		pdev = of_platform_device_create(rd->dn, NULL,
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 8e8af148b1dc371e..66ac67580d2a473b 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -4527,6 +4527,7 @@ static int of_spi_notify(struct notifier_block *nb, unsigned long action,
>  			return NOTIFY_OK;
>  		}
>  
> +		rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>  		spi = of_register_spi_device(ctlr, rd->dn);
>  		put_device(&ctlr->dev);
>  


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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] treewide: Fix instantiation of devices in DT overlays
  2023-03-29 16:06   ` Frank Rowand
@ 2023-03-29 16:49     ` Geert Uytterhoeven
  -1 siblings, 0 replies; 16+ messages in thread
From: Geert Uytterhoeven @ 2023-03-29 16:49 UTC (permalink / raw)
  To: Frank Rowand
  Cc: Greg Kroah-Hartman, Saravana Kannan, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team,
	Wolfram Sang, Rob Herring, Mark Brown, linux-arm-kernel,
	linux-i2c, devicetree, linux-spi, linux-renesas-soc,
	linux-kernel

Hi Frank,

On Wed, Mar 29, 2023 at 6:06 PM Frank Rowand <frowand.list@gmail.com> wrote:
> On 3/24/23 04:30, Geert Uytterhoeven wrote:
> > When loading a DT overlay that creates a device, the device is not
> > instantiated, unless the DT overlay is unloaded and reloaded again.
>
> Can you elaborate on why this is?  What the relevant code paths are?

Honestly, I don't know.

From my local quotes collection:

   "There are two ways of constructing a software design.
    One way is to make it so simple that there are obviously no deficiencies.
    And the other way is to make it so complicated that there are no obvious
    deficiencies."
                                           -- C.A.R Hoare

The double hierarchies of DT and fw_devlink are just too complicated...

> > Saravana explains:
> >   Basically for all overlays (I hope the function is only used for
> >   overlays) we assume all nodes are NOT devices until they actually
> >   get added as a device.
> >
> > Based on a patch by Saravana Kannan, which covered only platform and spi
> > devices.
>
> > Fixes: 4a032827daa89350 ("of: property: Simplify of_link_to_phandle()")
>
> From a quick scan of the fixed commit, I don't see how that commit caused the problem.
> Can you give a quick clue?  (The clue does not need to be added to the commit message,
> but please at least put it below the "---" if there are additional versions of this
> patch.)

I bisected the issue to that commit. Reverting the commit fixed the
issue for me.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] treewide: Fix instantiation of devices in DT overlays
@ 2023-03-29 16:49     ` Geert Uytterhoeven
  0 siblings, 0 replies; 16+ messages in thread
From: Geert Uytterhoeven @ 2023-03-29 16:49 UTC (permalink / raw)
  To: Frank Rowand
  Cc: Greg Kroah-Hartman, Saravana Kannan, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team,
	Wolfram Sang, Rob Herring, Mark Brown, linux-arm-kernel,
	linux-i2c, devicetree, linux-spi, linux-renesas-soc,
	linux-kernel

Hi Frank,

On Wed, Mar 29, 2023 at 6:06 PM Frank Rowand <frowand.list@gmail.com> wrote:
> On 3/24/23 04:30, Geert Uytterhoeven wrote:
> > When loading a DT overlay that creates a device, the device is not
> > instantiated, unless the DT overlay is unloaded and reloaded again.
>
> Can you elaborate on why this is?  What the relevant code paths are?

Honestly, I don't know.

From my local quotes collection:

   "There are two ways of constructing a software design.
    One way is to make it so simple that there are obviously no deficiencies.
    And the other way is to make it so complicated that there are no obvious
    deficiencies."
                                           -- C.A.R Hoare

The double hierarchies of DT and fw_devlink are just too complicated...

> > Saravana explains:
> >   Basically for all overlays (I hope the function is only used for
> >   overlays) we assume all nodes are NOT devices until they actually
> >   get added as a device.
> >
> > Based on a patch by Saravana Kannan, which covered only platform and spi
> > devices.
>
> > Fixes: 4a032827daa89350 ("of: property: Simplify of_link_to_phandle()")
>
> From a quick scan of the fixed commit, I don't see how that commit caused the problem.
> Can you give a quick clue?  (The clue does not need to be added to the commit message,
> but please at least put it below the "---" if there are additional versions of this
> patch.)

I bisected the issue to that commit. Reverting the commit fixed the
issue for me.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] treewide: Fix instantiation of devices in DT overlays
  2023-03-24  9:30 ` Geert Uytterhoeven
@ 2023-03-29 19:01   ` Wolfram Sang
  -1 siblings, 0 replies; 16+ messages in thread
From: Wolfram Sang @ 2023-03-29 19:01 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Greg Kroah-Hartman, Saravana Kannan, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team,
	Rob Herring, Frank Rowand, Mark Brown, linux-arm-kernel,
	linux-i2c, devicetree, linux-spi, linux-renesas-soc,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 841 bytes --]

On Fri, Mar 24, 2023 at 10:30:39AM +0100, Geert Uytterhoeven wrote:
> When loading a DT overlay that creates a device, the device is not
> instantiated, unless the DT overlay is unloaded and reloaded again.
> 
> Saravana explains:
>   Basically for all overlays (I hope the function is only used for
>   overlays) we assume all nodes are NOT devices until they actually
>   get added as a device.
> 
> Based on a patch by Saravana Kannan, which covered only platform and spi
> devices.
> 
> Fixes: 4a032827daa89350 ("of: property: Simplify of_link_to_phandle()")
> Link: https://lore.kernel.org/r/CAGETcx_+rhHvaC_HJXGrr5_WAd2+k5f=rWYnkCZ6z5bGX-wj4w@mail.gmail.com
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Acked-by: Mark Brown <broonie@kernel.org>

Acked-by: Wolfram Sang <wsa@kernel.org> # for I2C


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] treewide: Fix instantiation of devices in DT overlays
@ 2023-03-29 19:01   ` Wolfram Sang
  0 siblings, 0 replies; 16+ messages in thread
From: Wolfram Sang @ 2023-03-29 19:01 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Greg Kroah-Hartman, Saravana Kannan, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team,
	Rob Herring, Frank Rowand, Mark Brown, linux-arm-kernel,
	linux-i2c, devicetree, linux-spi, linux-renesas-soc,
	linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 841 bytes --]

On Fri, Mar 24, 2023 at 10:30:39AM +0100, Geert Uytterhoeven wrote:
> When loading a DT overlay that creates a device, the device is not
> instantiated, unless the DT overlay is unloaded and reloaded again.
> 
> Saravana explains:
>   Basically for all overlays (I hope the function is only used for
>   overlays) we assume all nodes are NOT devices until they actually
>   get added as a device.
> 
> Based on a patch by Saravana Kannan, which covered only platform and spi
> devices.
> 
> Fixes: 4a032827daa89350 ("of: property: Simplify of_link_to_phandle()")
> Link: https://lore.kernel.org/r/CAGETcx_+rhHvaC_HJXGrr5_WAd2+k5f=rWYnkCZ6z5bGX-wj4w@mail.gmail.com
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Acked-by: Mark Brown <broonie@kernel.org>

Acked-by: Wolfram Sang <wsa@kernel.org> # for I2C


[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] treewide: Fix instantiation of devices in DT overlays
  2023-03-24  9:30 ` Geert Uytterhoeven
@ 2023-03-29 19:47   ` Saravana Kannan
  -1 siblings, 0 replies; 16+ messages in thread
From: Saravana Kannan @ 2023-03-29 19:47 UTC (permalink / raw)
  To: geert+renesas
  Cc: Greg Kroah-Hartman, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team,
	Wolfram Sang, Rob Herring, Frank Rowand, Mark Brown,
	linux-arm-kernel, linux-i2c, devicetree, linux-spi,
	linux-renesas-soc, linux-kernel

On Fri, Mar 24, 2023 at 2:30 AM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
>

I saw all the other replies. Let me give more details on the commit
text and inline comments so it's clearer and not a "he said he said"

> When loading a DT overlay that creates a device, the device is not
> instantiated,

IIRC I think the devices are instantiated, but not probed.

> unless the DT overlay is unloaded and reloaded again.
>
> Saravana explains:
>   Basically for all overlays (I hope the function is only used for
>   overlays) we assume all nodes are NOT devices until they actually
>   get added as a device.

This comment was about what the patch is doing. I think a better
commit text would be something like below. Feel free to reword as you
see fit.

After the recent refactor to improve fw_devlink[1], it no longer depends on
"compatible" property to identify which device tree nodes will
become struct device. fw_devlink now picks up dangling consumers (consumers
pointing to descendent device tree nodes of a device that aren't converted
to child devices) when a device is successfully bound to a driver. See
__fw_devlink_pickup_dangling_consumers().

However, during DT overlay, a device's device tree node can have sub-nodes
added/removed without unbinding/rebinding the driver. This difference in
behavior between the normal device instantiation and probing flow vs the DT
overlay flow has a bunch of implications that are pointed out elsewhere[2].
One of them is that the fw_devlink logic to pick up dangling consumers is
never exercised.

This patch solves the fw_devlink issue by marking all DT nodes added by DT
overlay with FWNODE_FLAG_NOT_DEVICE (fwnode that won't become device) and
then clearing the flag when a struct device is actually created for the DT
node. This way, fw_devlink knows not to have consumers waiting on these
newly added DT nodes and to propagate the dependency to an ancestor DT node
that has corresponding struct device.

[1] - https://lore.kernel.org/lkml/20230207014207.1678715-1-saravanak@google.com/
[2] - https://lore.kernel.org/lkml/CAGETcx_bkuFaLCiPrAWCPQz+w79ccDp6=9e881qmK=vx3hBMyg@mail.gmail.com/#t


> Based on a patch by Saravana Kannan, which covered only platform and spi
> devices.

You can keep this in the commit text.

> Fixes: 4a032827daa89350 ("of: property: Simplify of_link_to_phandle()")
> Link: https://lore.kernel.org/r/CAGETcx_+rhHvaC_HJXGrr5_WAd2+k5f=rWYnkCZ6z5bGX-wj4w@mail.gmail.com
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Acked-by: Mark Brown <broonie@kernel.org>
> ---
> v2:
>   - Add Acked-by,
>   - Drop RFC.
> ---
>  drivers/bus/imx-weim.c    | 1 +
>  drivers/i2c/i2c-core-of.c | 1 +
>  drivers/of/dynamic.c      | 1 +
>  drivers/of/platform.c     | 1 +
>  drivers/spi/spi.c         | 1 +
>  5 files changed, 5 insertions(+)
>
> diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
> index 36d42484142aede2..898e23a4231400fa 100644
> --- a/drivers/bus/imx-weim.c
> +++ b/drivers/bus/imx-weim.c
> @@ -329,6 +329,7 @@ static int of_weim_notify(struct notifier_block *nb, unsigned long action,
>                                  "Failed to setup timing for '%pOF'\n", rd->dn);
>
>                 if (!of_node_check_flag(rd->dn, OF_POPULATED)) {

It's important this flag clearing is done before the device is added.
So, can you please add a comment before all these clear flag lines
that's something like:

/* Clear the flag before adding the device so that fw_devlink doesn't
skip adding consumers to this device. */

Thanks,
Saravana

> +                       rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>                         if (!of_platform_device_create(rd->dn, NULL, &pdev->dev)) {
>                                 dev_err(&pdev->dev,
>                                         "Failed to create child device '%pOF'\n",
> diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
> index aa93467784c29c89..303f9003562eed3d 100644
> --- a/drivers/i2c/i2c-core-of.c
> +++ b/drivers/i2c/i2c-core-of.c
> @@ -178,6 +178,7 @@ static int of_i2c_notify(struct notifier_block *nb, unsigned long action,
>                         return NOTIFY_OK;
>                 }
>
> +               rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>                 client = of_i2c_register_device(adap, rd->dn);
>                 if (IS_ERR(client)) {
>                         dev_err(&adap->dev, "failed to create client for '%pOF'\n",
> diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
> index 07d93753b12f5f4d..e311d406b1705306 100644
> --- a/drivers/of/dynamic.c
> +++ b/drivers/of/dynamic.c
> @@ -226,6 +226,7 @@ static void __of_attach_node(struct device_node *np)
>         np->sibling = np->parent->child;
>         np->parent->child = np;
>         of_node_clear_flag(np, OF_DETACHED);
> +       np->fwnode.flags |= FWNODE_FLAG_NOT_DEVICE;
>  }
>
>  /**
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> index b2bd2e783445dd78..17c92cbfb62ee3ef 100644
> --- a/drivers/of/platform.c
> +++ b/drivers/of/platform.c
> @@ -737,6 +737,7 @@ static int of_platform_notify(struct notifier_block *nb,
>                 if (of_node_check_flag(rd->dn, OF_POPULATED))
>                         return NOTIFY_OK;
>
> +               rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>                 /* pdev_parent may be NULL when no bus platform device */
>                 pdev_parent = of_find_device_by_node(rd->dn->parent);
>                 pdev = of_platform_device_create(rd->dn, NULL,
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 8e8af148b1dc371e..66ac67580d2a473b 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -4527,6 +4527,7 @@ static int of_spi_notify(struct notifier_block *nb, unsigned long action,
>                         return NOTIFY_OK;
>                 }
>
> +               rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>                 spi = of_register_spi_device(ctlr, rd->dn);
>                 put_device(&ctlr->dev);
>
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] treewide: Fix instantiation of devices in DT overlays
@ 2023-03-29 19:47   ` Saravana Kannan
  0 siblings, 0 replies; 16+ messages in thread
From: Saravana Kannan @ 2023-03-29 19:47 UTC (permalink / raw)
  To: geert+renesas
  Cc: Greg Kroah-Hartman, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team,
	Wolfram Sang, Rob Herring, Frank Rowand, Mark Brown,
	linux-arm-kernel, linux-i2c, devicetree, linux-spi,
	linux-renesas-soc, linux-kernel

On Fri, Mar 24, 2023 at 2:30 AM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
>

I saw all the other replies. Let me give more details on the commit
text and inline comments so it's clearer and not a "he said he said"

> When loading a DT overlay that creates a device, the device is not
> instantiated,

IIRC I think the devices are instantiated, but not probed.

> unless the DT overlay is unloaded and reloaded again.
>
> Saravana explains:
>   Basically for all overlays (I hope the function is only used for
>   overlays) we assume all nodes are NOT devices until they actually
>   get added as a device.

This comment was about what the patch is doing. I think a better
commit text would be something like below. Feel free to reword as you
see fit.

After the recent refactor to improve fw_devlink[1], it no longer depends on
"compatible" property to identify which device tree nodes will
become struct device. fw_devlink now picks up dangling consumers (consumers
pointing to descendent device tree nodes of a device that aren't converted
to child devices) when a device is successfully bound to a driver. See
__fw_devlink_pickup_dangling_consumers().

However, during DT overlay, a device's device tree node can have sub-nodes
added/removed without unbinding/rebinding the driver. This difference in
behavior between the normal device instantiation and probing flow vs the DT
overlay flow has a bunch of implications that are pointed out elsewhere[2].
One of them is that the fw_devlink logic to pick up dangling consumers is
never exercised.

This patch solves the fw_devlink issue by marking all DT nodes added by DT
overlay with FWNODE_FLAG_NOT_DEVICE (fwnode that won't become device) and
then clearing the flag when a struct device is actually created for the DT
node. This way, fw_devlink knows not to have consumers waiting on these
newly added DT nodes and to propagate the dependency to an ancestor DT node
that has corresponding struct device.

[1] - https://lore.kernel.org/lkml/20230207014207.1678715-1-saravanak@google.com/
[2] - https://lore.kernel.org/lkml/CAGETcx_bkuFaLCiPrAWCPQz+w79ccDp6=9e881qmK=vx3hBMyg@mail.gmail.com/#t


> Based on a patch by Saravana Kannan, which covered only platform and spi
> devices.

You can keep this in the commit text.

> Fixes: 4a032827daa89350 ("of: property: Simplify of_link_to_phandle()")
> Link: https://lore.kernel.org/r/CAGETcx_+rhHvaC_HJXGrr5_WAd2+k5f=rWYnkCZ6z5bGX-wj4w@mail.gmail.com
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Acked-by: Mark Brown <broonie@kernel.org>
> ---
> v2:
>   - Add Acked-by,
>   - Drop RFC.
> ---
>  drivers/bus/imx-weim.c    | 1 +
>  drivers/i2c/i2c-core-of.c | 1 +
>  drivers/of/dynamic.c      | 1 +
>  drivers/of/platform.c     | 1 +
>  drivers/spi/spi.c         | 1 +
>  5 files changed, 5 insertions(+)
>
> diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
> index 36d42484142aede2..898e23a4231400fa 100644
> --- a/drivers/bus/imx-weim.c
> +++ b/drivers/bus/imx-weim.c
> @@ -329,6 +329,7 @@ static int of_weim_notify(struct notifier_block *nb, unsigned long action,
>                                  "Failed to setup timing for '%pOF'\n", rd->dn);
>
>                 if (!of_node_check_flag(rd->dn, OF_POPULATED)) {

It's important this flag clearing is done before the device is added.
So, can you please add a comment before all these clear flag lines
that's something like:

/* Clear the flag before adding the device so that fw_devlink doesn't
skip adding consumers to this device. */

Thanks,
Saravana

> +                       rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>                         if (!of_platform_device_create(rd->dn, NULL, &pdev->dev)) {
>                                 dev_err(&pdev->dev,
>                                         "Failed to create child device '%pOF'\n",
> diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
> index aa93467784c29c89..303f9003562eed3d 100644
> --- a/drivers/i2c/i2c-core-of.c
> +++ b/drivers/i2c/i2c-core-of.c
> @@ -178,6 +178,7 @@ static int of_i2c_notify(struct notifier_block *nb, unsigned long action,
>                         return NOTIFY_OK;
>                 }
>
> +               rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>                 client = of_i2c_register_device(adap, rd->dn);
>                 if (IS_ERR(client)) {
>                         dev_err(&adap->dev, "failed to create client for '%pOF'\n",
> diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
> index 07d93753b12f5f4d..e311d406b1705306 100644
> --- a/drivers/of/dynamic.c
> +++ b/drivers/of/dynamic.c
> @@ -226,6 +226,7 @@ static void __of_attach_node(struct device_node *np)
>         np->sibling = np->parent->child;
>         np->parent->child = np;
>         of_node_clear_flag(np, OF_DETACHED);
> +       np->fwnode.flags |= FWNODE_FLAG_NOT_DEVICE;
>  }
>
>  /**
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> index b2bd2e783445dd78..17c92cbfb62ee3ef 100644
> --- a/drivers/of/platform.c
> +++ b/drivers/of/platform.c
> @@ -737,6 +737,7 @@ static int of_platform_notify(struct notifier_block *nb,
>                 if (of_node_check_flag(rd->dn, OF_POPULATED))
>                         return NOTIFY_OK;
>
> +               rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>                 /* pdev_parent may be NULL when no bus platform device */
>                 pdev_parent = of_find_device_by_node(rd->dn->parent);
>                 pdev = of_platform_device_create(rd->dn, NULL,
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 8e8af148b1dc371e..66ac67580d2a473b 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -4527,6 +4527,7 @@ static int of_spi_notify(struct notifier_block *nb, unsigned long action,
>                         return NOTIFY_OK;
>                 }
>
> +               rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
>                 spi = of_register_spi_device(ctlr, rd->dn);
>                 put_device(&ctlr->dev);
>
> --
> 2.34.1
>

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-03-29 19:50 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-24  9:30 [PATCH v2] treewide: Fix instantiation of devices in DT overlays Geert Uytterhoeven
2023-03-24  9:30 ` Geert Uytterhoeven
2023-03-27  2:52 ` Frank Rowand
2023-03-27  2:52   ` Frank Rowand
2023-03-27  3:02 ` Shawn Guo
2023-03-27  3:02   ` Shawn Guo
2023-03-27  8:54   ` Ivan Bornyakov
2023-03-27  8:54     ` Ivan Bornyakov
2023-03-29 16:06 ` Frank Rowand
2023-03-29 16:06   ` Frank Rowand
2023-03-29 16:49   ` Geert Uytterhoeven
2023-03-29 16:49     ` Geert Uytterhoeven
2023-03-29 19:01 ` Wolfram Sang
2023-03-29 19:01   ` Wolfram Sang
2023-03-29 19:47 ` Saravana Kannan
2023-03-29 19:47   ` Saravana Kannan

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.