USB: Fix device driver race
PATCH 1/2 USB: Fix device driver race
When a new device with a specialised device driver is plugged in, the new driver will be modprobe()'d but the driver core will attach the "generic" driver to the device.
After that, nothing will trigger a reprobe when the modprobe()'d device driver has finished initialising, as the device has the "generic" driver attached to it.
Trigger a reprobe ourselves when new specialised drivers get registered.
--- drivers/usb/core/driver.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)
drivers/usb/core/driver.c +29 -2
@@ -905,6 +905,30 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)return 0 ; } +static int __usb_bus_reprobe_drivers (struct device *dev,void *data) +{ +struct usb_device_driver *udriver =to_usb_device_driver (dev->driver); +struct usb_device *udev =to_usb_device (dev); + +if (udriver == &usb_generic_driver && + !udev->use_generic_driver) +return device_reprobe (dev); + +return 0 ; +} + +static int __usb_device_driver_added (struct device_driver *drv,void *data) +{ +struct usb_device_driver *udrv =to_usb_device_driver (drv); + +if (udrv->match) { +bus_for_each_dev (&usb_bus_type,NULL , udrv, + __usb_bus_reprobe_drivers); + } + +return 0 ; +} +/** * usb_register_device_driver - register a USB device (not interface) driver * @new_udriver: USB operations for the device driver
@@ -934,13 +958,16 @@ int usb_register_device_driver(struct usb_device_driver *new_udriver, retval =driver_register (&new_udriver->drvwrap.driver); -if (!retval) +if (!retval) { +bus_for_each_drv (&usb_bus_type,NULL ,NULL , + __usb_device_driver_added);pr_info ("%s: registered new device driver %s\n" , usbcore_name, new_udriver->name); -else + }else {printk (KERN_ERR "%s: error %d registering device " " driver %s\n" , usbcore_name, retval, new_udriver->name); + }return retval; }
Signature · 1 line
2.26.2
PATCH 2/2 USB: Fix source path in header
--- drivers/usb/core/driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/core/driver.c +1 -1
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 /* -* drivers/usb/driver.c - most of the driver model stuff for usb +* drivers/usb/core/driver.c - most of the driver model stuff for usb * * (C) Copyright 2005 Greg Kroah-Hartman <[email protected]> *
Signature · 1 line
2.26.2
Greg Kroah-Hartman
maintainerRe: [PATCH 2/2] USB: Fix source path in header
Quoted 1 line · Bastien Nocera
Signed-off-by Bastien Nocera <[email protected]>
I can't take patches without any changelog text at all, sorry.
drivers/usb/core/driver.c line 3
Quoted 13 lines
--- drivers/usb/core/driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/core/driver.c +1
-1@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 /* -* drivers/usb/driver.c - most of the driver model stuff for usb +* drivers/usb/core/driver.c - most of the driver model stuff for usb
Just drop the whole file name, it's not needed at all.
thanks,
greg k-h
Re: [PATCH 2/2] USB: Fix source path in header
Quoted 4 lines · Greg Kroah-Hartman
Quoted 1 line · Bastien Nocera
Signed-off-by Bastien Nocera <[email protected]>I can't take patches without any changelog text at all, sorry.
The subject line isn't clear enough?
Quoted 4 lines
Quoted 4 lines
--- drivers/usb/core/driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines
Quoted 10 lines
drivers/usb/core/driver.c +1
-1@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 /* -* drivers/usb/driver.c - most of the driver model stuff for usb +* drivers/usb/core/driver.c - most of the driver model stuff for usb
Just drop the whole file name, it's not needed at all.
And the description after or just the filename?
Greg Kroah-Hartman
maintainerRe: [PATCH 2/2] USB: Fix source path in header
Quoted 7 lines · Bastien Nocera
Quoted 4 lines · Greg Kroah-Hartman
Quoted 1 line · Bastien Nocera
Signed-off-by Bastien Nocera <[email protected]>I can't take patches without any changelog text at all, sorry.
The subject line isn't clear enough?
Maybe, maybe not, doesn't mean you shouldn't also write some text about why you did what you did.
Quoted 17 lines
Quoted 4 lines
Quoted 4 lines
--- drivers/usb/core/driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 12 lines
Quoted 10 lines
drivers/usb/core/driver.c +1
-1@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 /* -* drivers/usb/driver.c - most of the driver model stuff for usb +* drivers/usb/core/driver.c - most of the driver model stuff for usb
Just drop the whole file name, it's not needed at all.
Quoted 1 line
And the description after or just the filename?
The description is fine to keep.
thanks,
greg k-h
Re: [PATCH 2/2] USB: Fix source path in header
Quoted 33 lines · Greg Kroah-Hartman
Quoted 7 lines · Bastien Nocera
Quoted 4 lines · Greg Kroah-Hartman
Quoted 1 line · Bastien Nocera
Signed-off-by Bastien Nocera <[email protected]>I can't take patches without any changelog text at all, sorry.
The subject line isn't clear enough?
Maybe, maybe not, doesn't mean you shouldn't also write some text about
why you did what you did.Quoted 20 lines
Quoted 19 lines
Quoted 13 lines
--- drivers/usb/core/driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/core/driver.c +0
-1@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 /* -* drivers/usb/driver.c - most of the driver model stuff for Quoted 4 lines
usb
+ *drivers/usb/core/driver.c- most of the driver model stuff for
usbJust drop the whole file name, it's not needed at all.
Quoted 3 lines
Quoted 1 line
And the description after or just the filename?
The description is fine to keep.
Looks like there's a lot more cleaning up that would need to be done in the tree, so feel free to drop this patch.
Cheers
Greg Kroah-Hartman
maintainerQuoted 4 lines · Bastien Nocera
When a new device with a specialised device driver is plugged in, the new driver will be modprobe()'d but the driver core will attach the "generic" driver to the device.
Quoted 8 lines
After that, nothing will trigger a reprobe when the modprobe()'d device driver has finished initialising, as the device has the "generic" driver attached to it.
Trigger a reprobe ourselves when new specialised drivers get registered.
Signed-off-by Bastien Nocera <[email protected]>---
What commit id does this fix? And if it's in an older kernel, should it be backported to the stable trees?
thanks,
greg k-h
Quoted 14 lines · Greg Kroah-Hartman
Quoted 13 lines · Bastien Nocera
When a new device with a specialised device driver is plugged in, the
new driver will be modprobe()'d but the driver core will attach the "generic" driver to the device.After that, nothing will trigger a reprobe when the modprobe()'d device
driver has finished initialising, as the device has the "generic" driver attached to it.Trigger a reprobe ourselves when new specialised drivers get registered.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Bastien Nocera <[email protected]>---
What commit id does this fix? And if it's in an older kernel, should it
be backported to the stable trees?
AFAIK, the apple-mfi-fastcharge driver wasn't backported to stable trees, and it's the only driver that's impacted by this bug, so there shouldn't be any need to backport it there.
Did you want me to respin it with this info?
Cheers
Quoted 32 lines · Bastien Nocera
When a new device with a specialised device driver is plugged in, the new driver will be modprobe()'d but the driver core will attach the "generic" driver to the device.
After that, nothing will trigger a reprobe when the modprobe()'d device driver has finished initialising, as the device has the "generic" driver attached to it.
Trigger a reprobe ourselves when new specialised drivers get registered.
Signed-off-by Bastien Nocera <[email protected]>--- drivers/usb/core/driver.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)drivers/usb/core/driver.c +9
-0@@ -905,6 +905,30 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)return 0 ; } +static int __usb_bus_reprobe_drivers (struct device *dev,void *data) +{ +struct usb_device_driver *udriver =to_usb_device_driver (dev->driver); +struct usb_device *udev =to_usb_device (dev); + +if (udriver == &usb_generic_driver && + !udev->use_generic_driver) +return device_reprobe (dev); +
drivers/usb/core/driver.c static int usb_uevent(struct device *dev, struct kobj_uevent_env *env) · line 926
Quoted 10 lines
drivers/usb/core/driver.c +10
-0+return 0 ; +} + +static int __usb_device_driver_added (struct device_driver *drv,void *data) +{ +struct usb_device_driver *udrv =to_usb_device_driver (drv); + +if (udrv->match) { +bus_for_each_dev (&usb_bus_type,NULL , udrv, + __usb_bus_reprobe_drivers);
What does udrv get used for here?
Quoted 9 lines
drivers/usb/core/driver.c +5
-0+ } + +return 0 ; +} +/** * usb_register_device_driver - register a USB device (not interface) driver * @new_udriver: USB operations for the device driver
drivers/usb/core/driver.c int usb_register_device_driver(struct usb_device_driver *new_udriver, · line 963
Quoted 7 lines
drivers/usb/core/driver.c +3
-1@@ -934,13 +958,16 @@ int usb_register_device_driver(struct usb_device_driver *new_udriver, retval =driver_register (&new_udriver->drvwrap.driver); -if (!retval) +if (!retval) { +bus_for_each_drv (&usb_bus_type,NULL ,NULL , + __usb_device_driver_added);
This looks funny. You're calling both bus_for_each_drv() and bus_for_each_dev(). Can't you skip this iterator and just call bus_for_each_dev() directly?
Alan Stern
Quoted 67 lines · Alan Stern
Quoted 43 lines · Bastien Nocera
When a new device with a specialised device driver is plugged in, the
new driver will be modprobe()'d but the driver core will attach the "generic" driver to the device.After that, nothing will trigger a reprobe when the modprobe()'d device
driver has finished initialising, as the device has the "generic" driver attached to it.Trigger a reprobe ourselves when new specialised drivers get registered.
Signed-off-by Bastien Nocera <[email protected]>--- drivers/usb/core/driver.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)drivers/usb/core/driver.c +13
-0@@ -905,6 +905,30 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)return 0 ; } +static int __usb_bus_reprobe_drivers (struct device *dev,void *data) +{ +struct usb_device_driver *udriver =to_usb_device_driver (dev- >driver); +struct usb_device *udev =to_usb_device (dev); + +if (udriver == &usb_generic_driver && + !udev->use_generic_driver) +return device_reprobe (dev); + +return 0 ; +} + +static int __usb_device_driver_added(struct device_driver *drv,void *data)
drivers/usb/core/driver.c static int usb_uevent(struct device *dev, struct kobj_uevent_env *env) · line 926
Quoted 6 lines
drivers/usb/core/driver.c +6
-0+{ +struct usb_device_driver *udrv =to_usb_device_driver (drv); + +if (udrv->match) { +bus_for_each_dev (&usb_bus_type,NULL , udrv, + __usb_bus_reprobe_drivers);What does udrv get used for here?
Quoted 14 lines
drivers/usb/core/driver.c +5
-0+ } + +return 0 ; +} +/** * usb_register_device_driver - register a USB device (not interface) driver
* @new_udriver: USB operations for the device driverdrivers/usb/core/driver.c +0
-0@@ -934,13 +958,16 @@ int usb_register_device_driver(structusb_device_driver *new_udriver, retval =driver_register (&new_udriver->drvwrap.driver);
Quoted 8 lines
drivers/usb/core/driver.c int usb_register_device_driver(struct usb_device_driver *new_udriver, · line 963
Quoted 4 lines
drivers/usb/core/driver.c +3
-1-if (!retval) +if (!retval) { +bus_for_each_drv (&usb_bus_type,NULL ,NULL , + __usb_device_driver_added);This looks funny. You're calling both
bus_for_each_drv()andbus_for_each_dev(). Can't you skip this iterator and just callbus_for_each_dev()directly?
You're right, looks like this could be simplified somewhat. I'm building and testing a smaller patch.
Thanks
Quoted 77 lines · Bastien Nocera
Quoted 67 lines · Alan Stern
Quoted 43 lines · Bastien Nocera
When a new device with a specialised device driver is plugged in, the
new driver will be modprobe()'d but the driver core will attach the "generic" driver to the device.After that, nothing will trigger a reprobe when the modprobe()'d device
driver has finished initialising, as the device has the "generic" driver attached to it.Trigger a reprobe ourselves when new specialised drivers get registered.
Signed-off-by Bastien Nocera <[email protected]>--- drivers/usb/core/driver.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)drivers/usb/core/driver.c +13
-0@@ -905,6 +905,30 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)return 0 ; } +static int __usb_bus_reprobe_drivers (struct device *dev,void *data) +{ +struct usb_device_driver *udriver =to_usb_device_driver (dev- >driver); +struct usb_device *udev =to_usb_device (dev); + +if (udriver == &usb_generic_driver && + !udev->use_generic_driver) +return device_reprobe (dev); + +return 0 ; +} + +static int __usb_device_driver_added(struct device_driver *drv,void *data)
drivers/usb/core/driver.c static int usb_uevent(struct device *dev, struct kobj_uevent_env *env) · line 926
Quoted 6 lines
drivers/usb/core/driver.c +6
-0+{ +struct usb_device_driver *udrv =to_usb_device_driver (drv); + +if (udrv->match) { +bus_for_each_dev (&usb_bus_type,NULL , udrv, + __usb_bus_reprobe_drivers);What does udrv get used for here?
Quoted 14 lines
drivers/usb/core/driver.c +5
-0+ } + +return 0 ; +} +/** * usb_register_device_driver - register a USB device (not interface) driver
* @new_udriver: USB operations for the device driverdrivers/usb/core/driver.c +0
-0@@ -934,13 +958,16 @@ int usb_register_device_driver(structusb_device_driver *new_udriver, retval =driver_register (&new_udriver->drvwrap.driver);Quoted 8 lines
drivers/usb/core/driver.c int usb_register_device_driver(struct usb_device_driver *new_udriver, · line 963
Quoted 4 lines
drivers/usb/core/driver.c +3
-1-if (!retval) +if (!retval) { +bus_for_each_drv (&usb_bus_type,NULL ,NULL , + __usb_device_driver_added);This looks funny. You're calling both
bus_for_each_drv()andbus_for_each_dev(). Can't you skip this iterator and just callbus_for_each_dev()directly?
Quoted 3 lines
You're right, looks like this could be simplified somewhat. I'm building and testing a smaller patch.
What do you mean "reprobe" for your device? Do you mean the mfi_fc_probe is not called? If it is, Would you please check why usb_device_match at drivers/usb/core/driver.c does not return true for your device?
Signature · 2 lines
Thanks, Peter Chen
Quoted 86 lines · Peter Chen
Quoted 85 lines · Bastien Nocera
Quoted 83 lines · Alan Stern
Quoted 53 lines · Bastien Nocera
When a new device with a specialised device driver is plugged in,
the
new driver will be modprobe()'d but the driver core will attach the
"generic" driver to the device.After that, nothing will trigger a reprobe when the modprobe()'d
device
driver has finished initialising, as the device has the "generic"
driver attached to it.Trigger a reprobe ourselves when new specialised drivers get registered.
Signed-off-by Bastien Nocera <[email protected]>--- drivers/usb/core/driver.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)drivers/usb/core/driver.c +3
-0@@ -905,6 +905,30 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)return 0 ; } +static int __usb_bus_reprobe_drivers (struct device *dev,void *data) +{ + struct usb_device_driver *udriver =to_usb_device_driver(dev-
Quoted 1 line
driver);
drivers/usb/core/driver.c +10
-0+struct usb_device *udev =to_usb_device (dev); + +if (udriver == &usb_generic_driver && + !udev->use_generic_driver) +return device_reprobe (dev); + +return 0 ; +} + +static int __usb_device_driver_added(struct device_driver*drv,
void *data)drivers/usb/core/driver.c +2
-0+{ + struct usb_device_driver *udrv =
to_usb_device_driver(drv);drivers/usb/core/driver.c static int usb_uevent(struct device *dev, struct kobj_uevent_env *env) · line 926
Quoted 4 lines
drivers/usb/core/driver.c +4
-0+ +if (udrv->match) { +bus_for_each_dev (&usb_bus_type,NULL , udrv, + __usb_bus_reprobe_drivers);What does udrv get used for here?
Quoted 10 lines
drivers/usb/core/driver.c +5
-0+ } + +return 0 ; +} +/** * usb_register_device_driver - register a USB device (not interface) driver
* @new_udriver: USB operations for the device driverdrivers/usb/core/driver.c int usb_register_device_driver(struct · line 964
Quoted 8 lines
drivers/usb/core/driver.c +3
-1@@ -934,13 +958,16 @@ int usb_register_device_driver(structusb_device_driver *new_udriver, retval =driver_register (&new_udriver->drvwrap.driver); -if (!retval) +if (!retval) { +bus_for_each_drv (&usb_bus_type,NULL ,NULL , + __usb_device_driver_added);This looks funny. You're calling both
bus_for_each_drv()andbus_for_each_dev(). Can't you skip this iterator and just callbus_for_each_dev()directly?
Quoted 8 lines
Quoted 3 lines
You're right, looks like this could be simplified somewhat. I'm building and testing a smaller patch.
What do you mean "reprobe" for your device? Do you mean the
mfi_fc_probe
is not called? If it is, Would you please check whyusb_device_matchatdrivers/usb/core/driver.cdoes not return true for your device?
mfi_fc_probe() isn't called because the device already has the generic driver attached by the time the apple-mfi-fastcharge driver is loaded.
Quoted 79 lines
Quoted 79 lines
Quoted 78 lines
Quoted 66 lines
Quoted 45 lines
After that, nothing will trigger a reprobe when the modprobe()'d device driver has finished initialising, as the device has the "generic"
driver attached to it.Trigger a reprobe ourselves when new specialised drivers get registered.
Signed-off-by Bastien Nocera <[email protected]>--- drivers/usb/core/driver.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/drivers/usb/core/driver.cindexf81606c6a35b..a6187dd2186c100644drivers/usb/core/driver.c +3
-0@@ -905,6 +905,30 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)return 0 ; } +static int __usb_bus_reprobe_drivers (struct device *dev,void *data) +{ + struct usb_device_driver *udriver =to_usb_device_driver(dev-
Quoted 1 line
driver);
drivers/usb/core/driver.c +10
-0+struct usb_device *udev =to_usb_device (dev); + +if (udriver == &usb_generic_driver && + !udev->use_generic_driver) +return device_reprobe (dev); + +return 0 ; +} + +static int __usb_device_driver_added(struct device_driver*drv,
void *data)drivers/usb/core/driver.c +2
-0+{ + struct usb_device_driver *udrv =
to_usb_device_driver(drv);drivers/usb/core/driver.c static int usb_uevent(struct device *dev, struct kobj_uevent_env *env) · line 926
Quoted 4 lines
drivers/usb/core/driver.c +4
-0+ +if (udrv->match) { +bus_for_each_dev (&usb_bus_type,NULL , udrv, + __usb_bus_reprobe_drivers);What does udrv get used for here?
Quoted 14 lines
drivers/usb/core/driver.c +5
-0+ } + +return 0 ; +} +/** * usb_register_device_driver - register a USB device (not interface) driver
* @new_udriver: USB operations for the device driver @@
-934,13 +958,16 @@ int usb_register_device_driver(structusb_device_driver*new_udriver,retval =
driver_register(&new_udriver->drvwrap.driver);Quoted 8 lines
drivers/usb/core/driver.c int usb_register_device_driver(struct usb_device_driver *new_udriver, · line 963
Quoted 4 lines
drivers/usb/core/driver.c +3
-1-if (!retval) +if (!retval) { +bus_for_each_drv (&usb_bus_type,NULL ,NULL , + __usb_device_driver_added);This looks funny. You're calling both
bus_for_each_drv()andbus_for_each_dev(). Can't you skip this iterator and just callbus_for_each_dev()directly?You're right, looks like this could be simplified somewhat. I'm building and testing a smaller patch.
Quoted 7 lines
Quoted 4 lines
What do you mean "reprobe" for your device? Do you mean the
mfi_fc_probeis not called? If it is, Would you please check whyusb_device_matchatdrivers/usb/core/driver.cdoes not return true for your device?
mfi_fc_probe()isn't called because the device already has the generic driver attached by the time the apple-mfi-fastcharge driver is loaded.
Would you please explain more, why only this driver has this issue? Seem you create a struct usb_device_driver, but not struct usb_driver, few drivers do like that. You may see drivers/usb/misc/ehset.c and drivers/usb/misc/appledisplay.c as an example.
Peter
Greg Kroah-Hartman
maintainerQuoted 84 lines · Peter Chen
Quoted 84 lines
Quoted 83 lines
Quoted 75 lines
Quoted 66 lines
Quoted 45 lines
After that, nothing will trigger a reprobe when the modprobe()'d device driver has finished initialising, as the device has the "generic"
driver attached to it.Trigger a reprobe ourselves when new specialised drivers get registered.
Signed-off-by Bastien Nocera <[email protected]>--- drivers/usb/core/driver.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/drivers/usb/core/driver.cindexf81606c6a35b..a6187dd2186c100644drivers/usb/core/driver.c +3
-0@@ -905,6 +905,30 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)return 0 ; } +static int __usb_bus_reprobe_drivers (struct device *dev,void *data) +{ + struct usb_device_driver *udriver =to_usb_device_driver(dev-
Quoted 1 line
driver);
drivers/usb/core/driver.c +10
-0+struct usb_device *udev =to_usb_device (dev); + +if (udriver == &usb_generic_driver && + !udev->use_generic_driver) +return device_reprobe (dev); + +return 0 ; +} + +static int __usb_device_driver_added(struct device_driver*drv,
void *data)drivers/usb/core/driver.c +2
-0+{ + struct usb_device_driver *udrv =
to_usb_device_driver(drv);drivers/usb/core/driver.c static int usb_uevent(struct device *dev, struct kobj_uevent_env *env) · line 926
Quoted 4 lines
drivers/usb/core/driver.c +4
-0+ +if (udrv->match) { +bus_for_each_dev (&usb_bus_type,NULL , udrv, + __usb_bus_reprobe_drivers);What does udrv get used for here?
Quoted 14 lines
drivers/usb/core/driver.c +5
-0+ } + +return 0 ; +} +/** * usb_register_device_driver - register a USB device (not interface) driver
* @new_udriver: USB operations for the device driver @@
-934,13 +958,16 @@ int usb_register_device_driver(structusb_device_driver*new_udriver,retval =
driver_register(&new_udriver->drvwrap.driver);Quoted 8 lines
drivers/usb/core/driver.c int usb_register_device_driver(struct usb_device_driver *new_udriver, · line 963
Quoted 4 lines
drivers/usb/core/driver.c +3
-1-if (!retval) +if (!retval) { +bus_for_each_drv (&usb_bus_type,NULL ,NULL , + __usb_device_driver_added);This looks funny. You're calling both
bus_for_each_drv()andbus_for_each_dev(). Can't you skip this iterator and just callbus_for_each_dev()directly?Quoted 3 lines
You're right, looks like this could be simplified somewhat. I'm building and testing a smaller patch.
What do you mean "reprobe" for your device? Do you mean the
mfi_fc_probeis not called? If it is, Would you please check whyusb_device_matchatdrivers/usb/core/driver.cdoes not return true for your device?
Quoted 7 lines
Quoted 2 lines
mfi_fc_probe()isn't called because the device already has the generic driver attached by the time the apple-mfi-fastcharge driver is loaded.Would you please explain more, why only this driver has this issue? Seem you create a struct
usb_device_driver, but not structusb_driver, few drivers do like that. You may seedrivers/usb/misc/ehset.canddrivers/usb/misc/appledisplay.cas an example.
This is a different "type" of driver.
Quoted 97 lines · Peter Chen
Quoted 93 lines
Quoted 87 lines
Quoted 83 lines
Quoted 73 lines
Quoted 52 lines
After that, nothing will trigger a reprobe when the modprobe()'d
device driver has finished initialising, as the device has the
"generic"
driver attached to it.Trigger a reprobe ourselves when new specialised drivers get
registered.Signed-off-by Bastien Nocera <[email protected]>--- drivers/usb/core/driver.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/drivers/usb/core/driver.cindexf81606c6a35b..a6187dd2186c
100644drivers/usb/core/driver.c +1
-0@@ -905,6 +905,30 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)return 0 ; } +static int __usb_bus_reprobe_drivers(struct device *dev,void
*data)drivers/usb/core/driver.c +2
-0+{ + struct usb_device_driver *udriver =to_usb_device_driver(dev-
Quoted 1 line
driver);
drivers/usb/core/driver.c +10
-0+struct usb_device *udev =to_usb_device (dev); + +if (udriver == &usb_generic_driver && + !udev->use_generic_driver) +return device_reprobe (dev); + +return 0 ; +} + +static int __usb_device_driver_added(struct device_driver*drv,
void *data)drivers/usb/core/driver.c +2
-0+{ + struct usb_device_driver *udrv =
to_usb_device_driver(drv);drivers/usb/core/driver.c static int usb_uevent(struct device *dev, struct kobj_uevent_env *env) · line 926
Quoted 4 lines
drivers/usb/core/driver.c +4
-0+ +if (udrv->match) { +bus_for_each_dev (&usb_bus_type,NULL , udrv, + __usb_bus_reprobe_drivers);What does udrv get used for here?
Quoted 14 lines
drivers/usb/core/driver.c +5
-0+ } + +return 0 ; +} +/** * usb_register_device_driver - register a USB device (not interface) driver
* @new_udriver: USB operations for the device driver @@
-934,13 +958,16 @@ int usb_register_device_driver(structusb_device_driver*new_udriver,retval =
driver_register(&new_udriver->drvwrap.driver);Quoted 9 lines
drivers/usb/core/driver.c int usb_register_device_driver(struct usb_device_driver *new_udriver, · line 963
Quoted 4 lines
drivers/usb/core/driver.c +3
-1-if (!retval) +if (!retval) { +bus_for_each_drv (&usb_bus_type,NULL ,NULL , + __usb_device_driver_added);This looks funny. You're calling both
bus_for_each_drv()andbus_for_each_dev(). Can't you skip this iterator and just callbus_for_each_dev()directly?Quoted 3 lines
You're right, looks like this could be simplified somewhat. I'm building and testing a smaller patch.
Quoted 5 lines
What do you mean "reprobe" for your device? Do you mean the
mfi_fc_probeis not called? If it is, Would you please check whyusb_device_matchatdrivers/usb/core/driver.cdoes not return true for
your device?Quoted 3 lines
mfi_fc_probe()isn't called because the device already has the generic driver
attached by the time the apple-mfi-fastcharge driver is loaded.
Quoted 7 lines
Would you please explain more, why only this driver has this issue? Seem you
create a structusb_device_driver, but not structusb_driver, few drivers do like
that. You may seedrivers/usb/misc/ehset.canddrivers/usb/misc/appledisplay.c
as an example.
It's a _device_ driver, not an interface driver. It's the only driver that has the problem because it's the only non-generic device driver :)
Quoted 106 lines · Bastien Nocera
Quoted 97 lines · Peter Chen
Quoted 93 lines
Quoted 87 lines
Quoted 83 lines
Quoted 73 lines
Quoted 52 lines
After that, nothing will trigger a reprobe when the modprobe()'d
device driver has finished initialising, as the device has the
"generic"
driver attached to it.Trigger a reprobe ourselves when new specialised drivers get
registered.Signed-off-by Bastien Nocera <[email protected]>--- drivers/usb/core/driver.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/drivers/usb/core/driver.cindexf81606c6a35b..a6187dd2186c
100644drivers/usb/core/driver.c +1
-0@@ -905,6 +905,30 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)return 0 ; } +static int __usb_bus_reprobe_drivers(struct device *dev,void
*data)drivers/usb/core/driver.c +2
-0+{ + struct usb_device_driver *udriver =to_usb_device_driver(dev-
Quoted 1 line
driver);
drivers/usb/core/driver.c +10
-0+struct usb_device *udev =to_usb_device (dev); + +if (udriver == &usb_generic_driver && + !udev->use_generic_driver) +return device_reprobe (dev); + +return 0 ; +} + +static int __usb_device_driver_added(struct device_driver*drv,
void *data)drivers/usb/core/driver.c +2
-0+{ + struct usb_device_driver *udrv =
to_usb_device_driver(drv);drivers/usb/core/driver.c
Quoted 4 lines
drivers/usb/core/driver.c +4
-0+ +if (udrv->match) { +bus_for_each_dev (&usb_bus_type,NULL , udrv, + __usb_bus_reprobe_drivers);What does udrv get used for here?
Quoted 14 lines
drivers/usb/core/driver.c +5
-0+ } + +return 0 ; +} +/** * usb_register_device_driver - register a USB device (not interface) driver
* @new_udriver: USB operations for the device driver @@
-934,13 +958,16 @@ int usb_register_device_driver(structusb_device_driver*new_udriver,retval =
driver_register(&new_udriver->drvwrap.driver);Quoted 9 lines
drivers/usb/core/driver.c
Quoted 4 lines
drivers/usb/core/driver.c +3
-1-if (!retval) +if (!retval) { +bus_for_each_drv (&usb_bus_type,NULL ,NULL , + __usb_device_driver_added);This looks funny. You're calling both
bus_for_each_drv()andbus_for_each_dev(). Can't you skip this iterator and just callbus_for_each_dev()directly?Quoted 3 lines
You're right, looks like this could be simplified somewhat. I'm building and testing a smaller patch.
Quoted 5 lines
What do you mean "reprobe" for your device? Do you mean the
mfi_fc_probeis not called? If it is, Would you please check whyusb_device_matchatdrivers/usb/core/driver.cdoes not return true for
your device?Quoted 3 lines
mfi_fc_probe()isn't called because the device already has the generic driver
attached by the time the apple-mfi-fastcharge driver is loaded.Quoted 7 lines
Would you please explain more, why only this driver has this issue? Seem you
create a structusb_device_driver, but not structusb_driver, few drivers do like
that. You may seedrivers/usb/misc/ehset.canddrivers/usb/misc/appledisplay.c
as an example.
Quoted 3 lines
It's a _device_ driver, not an interface driver. It's the only driver that has the problem because it's the only non-generic device driver :)
I may clear now, thanks.
So, you mean your device has no interface descriptor, so you can't create a USB interface driver, and have to create non-generic device driver for it. I see there is __check_usb_generic function at generic.c to check if it could use generic driver or not, you may add some condition (eg, no interface descriptor) to avoid using generic driver Is it feasible?
Signature · 2 lines
Thanks, Peter Chen
Quoted 1 line · Peter Chen
<snip>
Quoted 9 lines
I may clear now, thanks.
So, you mean your device has no interface descriptor, so you can't create a USB interface driver, and have to create non-generic device driver for it. I see there is
__check_usb_genericfunction atgeneric.c
to check if it could use generic driver or not, you may add some condition (eg, no interface descriptor) to avoid using generic driver Is it feasible?
I'm not looking for work-arounds, the driver is meant to be for *the device*, not for interfaces. It does have interfaces, but they're not the target of the calls made.
There's a race between USB device (not interface) drivers on the first plug, which I'm trying to fix.