From: Hans de Goede Date: Fri, 9 Apr 2021 12:41:36 +0000 (+0200) Subject: usb: roles: Call try_module_get() from usb_role_switch_find_by_fwnode() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=3a2a91a2d51761557843996a66098eb7182b48b4;p=linux.git usb: roles: Call try_module_get() from usb_role_switch_find_by_fwnode() usb_role_switch_find_by_fwnode() returns a reference to the role-switch which must be put by calling usb_role_switch_put(). usb_role_switch_put() calls module_put(sw->dev.parent->driver->owner), add a matching try_module_get() to usb_role_switch_find_by_fwnode(), making it behave the same as the other usb_role_switch functions which return a reference. This avoids a WARN_ON being hit at kernel/module.c:1158 due to the module-refcount going below 0. Fixes: c6919d5e0cd1 ("usb: roles: Add usb_role_switch_find_by_fwnode()") Cc: stable Reviewed-by: Guenter Roeck Reviewed-by: Heikki Krogerus Signed-off-by: Hans de Goede Link: https://lore.kernel.org/r/20210409124136.65591-1-hdegoede@redhat.com Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c index 97f37077b7f97..33b637d0d8d99 100644 --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c @@ -189,6 +189,8 @@ usb_role_switch_find_by_fwnode(const struct fwnode_handle *fwnode) return NULL; dev = class_find_device_by_fwnode(role_class, fwnode); + if (dev) + WARN_ON(!try_module_get(dev->parent->driver->owner)); return dev ? to_role_switch(dev) : NULL; }