Skip to content

Commit 5c54fca

Browse files
Heikki Krogerusgregkh
authored andcommitted
usb: roles: Take care of driver module reference counting
This fixes potential "BUG: unable to handle kernel paging request at ..." from happening. Fixes: fde0aa6 ("usb: common: Small class for USB role switches") Cc: <stable@vger.kernel.org> Acked-by: Hans de Goede <hdegoede@redhat.com> Tested-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c9a4cb2 commit 5c54fca

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

drivers/usb/common/roles.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,15 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,
109109
*/
110110
struct usb_role_switch *usb_role_switch_get(struct device *dev)
111111
{
112-
return device_connection_find_match(dev, "usb-role-switch", NULL,
113-
usb_role_switch_match);
112+
struct usb_role_switch *sw;
113+
114+
sw = device_connection_find_match(dev, "usb-role-switch", NULL,
115+
usb_role_switch_match);
116+
117+
if (!IS_ERR_OR_NULL(sw))
118+
WARN_ON(!try_module_get(sw->dev.parent->driver->owner));
119+
120+
return sw;
114121
}
115122
EXPORT_SYMBOL_GPL(usb_role_switch_get);
116123

@@ -122,8 +129,10 @@ EXPORT_SYMBOL_GPL(usb_role_switch_get);
122129
*/
123130
void usb_role_switch_put(struct usb_role_switch *sw)
124131
{
125-
if (!IS_ERR_OR_NULL(sw))
132+
if (!IS_ERR_OR_NULL(sw)) {
126133
put_device(&sw->dev);
134+
module_put(sw->dev.parent->driver->owner);
135+
}
127136
}
128137
EXPORT_SYMBOL_GPL(usb_role_switch_put);
129138

0 commit comments

Comments
 (0)