Skip to content

Commit

Permalink
HID: elo: update the reference count of the usb device structure
Browse files Browse the repository at this point in the history
Use usb_get_dev() to increment the reference count of the usb device
structure in order to avoid releasing the structure while it is still in
use. And use usb_put_dev() to decrement the reference count and thus,
when it will be equal to 0 the structure will be released.

Signed-off-by: Salah Triki <salah.triki@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
salah-triki authored and Jiri Kosina committed Aug 20, 2021
1 parent db8d3a2 commit fbf4272
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion drivers/hid/hid-elo.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,15 @@ static int elo_probe(struct hid_device *hdev, const struct hid_device_id *id)
{
struct elo_priv *priv;
int ret;
struct usb_device *udev;

priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;

INIT_DELAYED_WORK(&priv->work, elo_work);
priv->usbdev = interface_to_usbdev(to_usb_interface(hdev->dev.parent));
udev = interface_to_usbdev(to_usb_interface(hdev->dev.parent));
priv->usbdev = usb_get_dev(udev);

hid_set_drvdata(hdev, priv);

Expand Down Expand Up @@ -265,6 +267,8 @@ static void elo_remove(struct hid_device *hdev)
{
struct elo_priv *priv = hid_get_drvdata(hdev);

usb_put_dev(priv->usbdev);

hid_hw_stop(hdev);
cancel_delayed_work_sync(&priv->work);
kfree(priv);
Expand Down

0 comments on commit fbf4272

Please sign in to comment.