linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] driver core: Don't probe devices after bus_type.match() probe deferral
@ 2022-08-11 19:07 Isaac J. Manjarres
  2022-08-12  0:56 ` Guenter Roeck
  0 siblings, 1 reply; 3+ messages in thread
From: Isaac J. Manjarres @ 2022-08-11 19:07 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki, Marek Szyprowski,
	Tomeu Vizoso, Russell King, Ulf Hansson
  Cc: Isaac J. Manjarres, Guenter Roeck, kernel-team, linux-kernel

Both __device_attach_driver() and __driver_attach() check the return
code of the bus_type.match() function to see if the device needs to be
added to the deferred probe list. After adding the device to the list,
the logic attempts to bind the device to the driver anyway, as if the
device had matched with the driver, which is not correct.

If __device_attach_driver() detects that the device in question is not
ready to match with a driver on the bus, then it doesn't make sense for
the device to attempt to bind with the current driver or continue
attempting to match with any of the other drivers on the bus. So, update
the logic in __device_attach_driver() to reflect this.

If __driver_attach() detects that a driver tried to match with a device
that is not ready to match yet, then the driver should not attempt to bind
with the device. However, the driver can still attempt to match and bind
with other devices on the bus, as drivers can be bound to multiple
devices. So, update the logic in __driver_attach() to reflect this.

Fixes: 656b8035b0ee ("ARM: 8524/1: driver cohandle -EPROBE_DEFER from bus_type.match()")
Reported-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Isaac J. Manjarres <isaacmanjarres@google.com>
---
 drivers/base/dd.c | 10 ++++++++++
 1 file changed, 10 insertions(+)


Guenter,

Thanks for testing this patch out. Can you please add your "Tested-by"?

--Isaac

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 70f79fc71539..90b31fb141a5 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -881,6 +881,11 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)
 		dev_dbg(dev, "Device match requests probe deferral\n");
 		dev->can_match = true;
 		driver_deferred_probe_add(dev);
+		/*
+		 * Device can't match with a driver right now, so don't attempt
+		 * to match or bind with other drivers on the bus.
+		 */
+		return ret;
 	} else if (ret < 0) {
 		dev_dbg(dev, "Bus failed to match device: %d\n", ret);
 		return ret;
@@ -1120,6 +1125,11 @@ static int __driver_attach(struct device *dev, void *data)
 		dev_dbg(dev, "Device match requests probe deferral\n");
 		dev->can_match = true;
 		driver_deferred_probe_add(dev);
+		/*
+		 * Driver could not match with device, but may match with
+		 * another device on the bus.
+		 */
+		return 0;
 	} else if (ret < 0) {
 		dev_dbg(dev, "Bus failed to match device: %d\n", ret);
 		return ret;
-- 
2.37.1.559.g78731f0fdb-goog


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

* Re: [PATCH v1] driver core: Don't probe devices after bus_type.match() probe deferral
  2022-08-11 19:07 [PATCH v1] driver core: Don't probe devices after bus_type.match() probe deferral Isaac J. Manjarres
@ 2022-08-12  0:56 ` Guenter Roeck
  2022-08-12  1:39   ` Saravana Kannan
  0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2022-08-12  0:56 UTC (permalink / raw)
  To: Isaac J. Manjarres, Greg Kroah-Hartman, Rafael J. Wysocki,
	Marek Szyprowski, Tomeu Vizoso, Russell King, Ulf Hansson
  Cc: kernel-team, linux-kernel

On 8/11/22 12:07, Isaac J. Manjarres wrote:
> Both __device_attach_driver() and __driver_attach() check the return
> code of the bus_type.match() function to see if the device needs to be
> added to the deferred probe list. After adding the device to the list,
> the logic attempts to bind the device to the driver anyway, as if the
> device had matched with the driver, which is not correct.
> 
> If __device_attach_driver() detects that the device in question is not
> ready to match with a driver on the bus, then it doesn't make sense for
> the device to attempt to bind with the current driver or continue
> attempting to match with any of the other drivers on the bus. So, update
> the logic in __device_attach_driver() to reflect this.
> 
> If __driver_attach() detects that a driver tried to match with a device
> that is not ready to match yet, then the driver should not attempt to bind
> with the device. However, the driver can still attempt to match and bind
> with other devices on the bus, as drivers can be bound to multiple
> devices. So, update the logic in __driver_attach() to reflect this.
> 
> Fixes: 656b8035b0ee ("ARM: 8524/1: driver cohandle -EPROBE_DEFER from bus_type.match()")
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> Signed-off-by: Isaac J. Manjarres <isaacmanjarres@google.com>

Tested-by: Guenter Roeck <linux@roeck-us.net>

> ---
>   drivers/base/dd.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 
> 
> Guenter,
> 
> Thanks for testing this patch out. Can you please add your "Tested-by"?
> 
> --Isaac
> 
> diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> index 70f79fc71539..90b31fb141a5 100644
> --- a/drivers/base/dd.c
> +++ b/drivers/base/dd.c
> @@ -881,6 +881,11 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)
>   		dev_dbg(dev, "Device match requests probe deferral\n");
>   		dev->can_match = true;
>   		driver_deferred_probe_add(dev);
> +		/*
> +		 * Device can't match with a driver right now, so don't attempt
> +		 * to match or bind with other drivers on the bus.
> +		 */
> +		return ret;
>   	} else if (ret < 0) {
>   		dev_dbg(dev, "Bus failed to match device: %d\n", ret);
>   		return ret;
> @@ -1120,6 +1125,11 @@ static int __driver_attach(struct device *dev, void *data)
>   		dev_dbg(dev, "Device match requests probe deferral\n");
>   		dev->can_match = true;
>   		driver_deferred_probe_add(dev);
> +		/*
> +		 * Driver could not match with device, but may match with
> +		 * another device on the bus.
> +		 */
> +		return 0;
>   	} else if (ret < 0) {
>   		dev_dbg(dev, "Bus failed to match device: %d\n", ret);
>   		return ret;


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

* Re: [PATCH v1] driver core: Don't probe devices after bus_type.match() probe deferral
  2022-08-12  0:56 ` Guenter Roeck
@ 2022-08-12  1:39   ` Saravana Kannan
  0 siblings, 0 replies; 3+ messages in thread
From: Saravana Kannan @ 2022-08-12  1:39 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Isaac J. Manjarres, Greg Kroah-Hartman, Rafael J. Wysocki,
	Marek Szyprowski, Tomeu Vizoso, Russell King, Ulf Hansson,
	kernel-team, linux-kernel

On Thu, Aug 11, 2022 at 5:56 PM Guenter Roeck <linux@roeck-us.net> wrote:
>
> On 8/11/22 12:07, Isaac J. Manjarres wrote:
> > Both __device_attach_driver() and __driver_attach() check the return
> > code of the bus_type.match() function to see if the device needs to be
> > added to the deferred probe list. After adding the device to the list,
> > the logic attempts to bind the device to the driver anyway, as if the
> > device had matched with the driver, which is not correct.
> >
> > If __device_attach_driver() detects that the device in question is not
> > ready to match with a driver on the bus, then it doesn't make sense for
> > the device to attempt to bind with the current driver or continue
> > attempting to match with any of the other drivers on the bus. So, update
> > the logic in __device_attach_driver() to reflect this.
> >
> > If __driver_attach() detects that a driver tried to match with a device
> > that is not ready to match yet, then the driver should not attempt to bind
> > with the device. However, the driver can still attempt to match and bind
> > with other devices on the bus, as drivers can be bound to multiple
> > devices. So, update the logic in __driver_attach() to reflect this.
> >
> > Fixes: 656b8035b0ee ("ARM: 8524/1: driver cohandle -EPROBE_DEFER from bus_type.match()")
> > Reported-by: Guenter Roeck <linux@roeck-us.net>
> > Signed-off-by: Isaac J. Manjarres <isaacmanjarres@google.com>
>
> Tested-by: Guenter Roeck <linux@roeck-us.net>

Reviewed-by: Saravana Kannan <saravanak@google.com>

-Saravana

>
> > ---
> >   drivers/base/dd.c | 10 ++++++++++
> >   1 file changed, 10 insertions(+)
> >
> >
> > Guenter,
> >
> > Thanks for testing this patch out. Can you please add your "Tested-by"?
> >
> > --Isaac
> >
> > diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> > index 70f79fc71539..90b31fb141a5 100644
> > --- a/drivers/base/dd.c
> > +++ b/drivers/base/dd.c
> > @@ -881,6 +881,11 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)
> >               dev_dbg(dev, "Device match requests probe deferral\n");
> >               dev->can_match = true;
> >               driver_deferred_probe_add(dev);
> > +             /*
> > +              * Device can't match with a driver right now, so don't attempt
> > +              * to match or bind with other drivers on the bus.
> > +              */
> > +             return ret;
> >       } else if (ret < 0) {
> >               dev_dbg(dev, "Bus failed to match device: %d\n", ret);
> >               return ret;
> > @@ -1120,6 +1125,11 @@ static int __driver_attach(struct device *dev, void *data)
> >               dev_dbg(dev, "Device match requests probe deferral\n");
> >               dev->can_match = true;
> >               driver_deferred_probe_add(dev);
> > +             /*
> > +              * Driver could not match with device, but may match with
> > +              * another device on the bus.
> > +              */
> > +             return 0;
> >       } else if (ret < 0) {
> >               dev_dbg(dev, "Bus failed to match device: %d\n", ret);
> >               return ret;
>
> --
> To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com.
>

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

end of thread, other threads:[~2022-08-12  1:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-11 19:07 [PATCH v1] driver core: Don't probe devices after bus_type.match() probe deferral Isaac J. Manjarres
2022-08-12  0:56 ` Guenter Roeck
2022-08-12  1:39   ` Saravana Kannan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).