[PATCH 03/10] spi: switch to using class_find_device_by_fwnode()

Dmitry Torokhov posted 10 patches 1 week, 4 days ago
[PATCH 03/10] spi: switch to using class_find_device_by_fwnode()
Posted by Dmitry Torokhov 1 week, 4 days ago
In preparation to class_find_device_by_of_node() going away switch to
using class_find_device_by_fwnode().

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/spi/spi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index bf1df365f795..071a9ffdb59d 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -21,6 +21,7 @@
 #include <linux/kthread.h>
 #include <linux/mod_devicetable.h>
 #include <linux/mutex.h>
+#include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/of_irq.h>
 #include <linux/percpu.h>
@@ -4948,11 +4949,12 @@ EXPORT_SYMBOL_GPL(spi_write_then_read);
 /* The spi controllers are not using spi_bus, so we find it with another way */
 struct spi_controller *of_find_spi_controller_by_node(struct device_node *node)
 {
+	struct fwnode_handle *fwnode = of_fwnode_handle(node);
 	struct device *dev;
 
-	dev = class_find_device_by_of_node(&spi_controller_class, node);
+	dev = class_find_device_by_fwnode(&spi_controller_class, fwnode);
 	if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE))
-		dev = class_find_device_by_of_node(&spi_target_class, node);
+		dev = class_find_device_by_fwnode(&spi_target_class, fwnode);
 	if (!dev)
 		return NULL;
 

-- 
2.53.0.959.g497ff81fa9-goog
Re: [PATCH 03/10] spi: switch to using class_find_device_by_fwnode()
Posted by Mark Brown 1 week, 4 days ago
On Sun, Mar 22, 2026 at 06:54:21PM -0700, Dmitry Torokhov wrote:
> In preparation to class_find_device_by_of_node() going away switch to
> using class_find_device_by_fwnode().

>  struct spi_controller *of_find_spi_controller_by_node(struct device_node *node)
>  {
> +	struct fwnode_handle *fwnode = of_fwnode_handle(node);
>  	struct device *dev;
>  
> -	dev = class_find_device_by_of_node(&spi_controller_class, node);
> +	dev = class_find_device_by_fwnode(&spi_controller_class, fwnode);
>  	if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE))
> -		dev = class_find_device_by_of_node(&spi_target_class, node);
> +		dev = class_find_device_by_fwnode(&spi_target_class, fwnode);
>  	if (!dev)
>  		return NULL;

Actually, no - this just looks weird.  We're in the middle of an OF
specific function but we're having to jump up to fwnode for no apparent
reason.  If we actually decide to get rid of the OF specific function
then I guess but I'm really not convinced this is an improvement in
isolation.
Re: [PATCH 03/10] spi: switch to using class_find_device_by_fwnode()
Posted by Dmitry Torokhov 1 week, 4 days ago
On Mon, Mar 23, 2026 at 05:16:04PM +0000, Mark Brown wrote:
> On Sun, Mar 22, 2026 at 06:54:21PM -0700, Dmitry Torokhov wrote:
> > In preparation to class_find_device_by_of_node() going away switch to
> > using class_find_device_by_fwnode().
> 
> >  struct spi_controller *of_find_spi_controller_by_node(struct device_node *node)
> >  {
> > +	struct fwnode_handle *fwnode = of_fwnode_handle(node);
> >  	struct device *dev;
> >  
> > -	dev = class_find_device_by_of_node(&spi_controller_class, node);
> > +	dev = class_find_device_by_fwnode(&spi_controller_class, fwnode);
> >  	if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE))
> > -		dev = class_find_device_by_of_node(&spi_target_class, node);
> > +		dev = class_find_device_by_fwnode(&spi_target_class, fwnode);
> >  	if (!dev)
> >  		return NULL;
> 
> Actually, no - this just looks weird.  We're in the middle of an OF
> specific function but we're having to jump up to fwnode for no apparent
> reason.  If we actually decide to get rid of the OF specific function
> then I guess but I'm really not convinced this is an improvement in
> isolation.

Yes, I want to remove OF-specific APIs from the driver core. I also have
drafts for bus_find_device_by_fwnode and others.

I can make a followup series introducing spi_find_controller_by_fwnode()
and removing this OF-specific variant.

Thanks.

-- 
Dmitry
Re: [PATCH 03/10] spi: switch to using class_find_device_by_fwnode()
Posted by Mark Brown 1 week, 4 days ago
On Sun, Mar 22, 2026 at 06:54:21PM -0700, Dmitry Torokhov wrote:
> In preparation to class_find_device_by_of_node() going away switch to
> using class_find_device_by_fwnode().

Acked-by: Mark Brown <broonie@kernel.org>