lkml.org 
[lkml]   [2021]   [May]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.10 006/530] usb: roles: Call try_module_get() from usb_role_switch_find_by_fwnode()
    Date
    From: Hans de Goede <hdegoede@redhat.com>

    commit 3a2a91a2d51761557843996a66098eb7182b48b4 upstream.

    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 <stable@vger.kernel.org>
    Reviewed-by: Guenter Roeck <linux@roeck-us.net>
    Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
    Signed-off-by: Hans de Goede <hdegoede@redhat.com>
    Link: https://lore.kernel.org/r/20210409124136.65591-1-hdegoede@redhat.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    ---
    drivers/usb/roles/class.c | 2 ++
    1 file changed, 2 insertions(+)

    --- a/drivers/usb/roles/class.c
    +++ b/drivers/usb/roles/class.c
    @@ -189,6 +189,8 @@ usb_role_switch_find_by_fwnode(const str
    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;
    }

    \
     
     \ /
      Last update: 2021-05-12 17:31    [W:11.311 / U:0.000 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site