usb: roles: Handle driver reference counting
Subsystems (3)
PATCH v3 2/10 usb: roles: Handle driver reference counting
Quoted 35 lines · Hans de Goede
HI,
Quoted 17 lines · Heikki Krogerus
This fixes potential "BUG: unable to handle kernel paging request at ..." from happening.
Fixes fde0aa6c175a ("usb: common: Small class for USB role switches")Cc <[email protected]>Signed-off-by Heikki Krogerus <[email protected]>--- drivers/usb/common/roles.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)drivers/usb/common/roles.c +0
-0@@ -109,8 +109,15 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,*/ struct usb_role_switch *usb_role_switch_get (struct device *dev)drivers/usb/common/roles.c static void *usb_role_switch_match(struct device_connection *con, int ep, · line 118
Quoted 10 lines
drivers/usb/common/roles.c +7
-2{ -return device_connection_find_match (dev,"usb-role-switch" ,NULL , - usb_role_switch_match); +struct usb_role_switch *sw; + + sw =device_connection_find_match (dev,"usb-role-switch" ,NULL , + usb_role_switch_match); + +if (!IS_ERR (sw)) +WARN_ON (!try_module_get (sw->dev.parent->driver->owner));While testing I found a bug, so sorry but this is going to need a v4,
device_connection_find_match()may return NULL here, so this needs to be if (!IS_ERR_OR_NULL(sw)) to avoid an oops.
Quoted 2 lines
Note I'm also seeing some other issues which I need to debug I will do so tomorrow morning so you may want to wait a bit with v4.
Np. Take your time. And thanks for testing these.
Cheers,