Commit fbf42729 authored by Salah Triki's avatar Salah Triki Committed by Jiri Kosina

HID: elo: update the reference count of the usb device structure

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: default avatarSalah Triki <salah.triki@gmail.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent db8d3a21
...@@ -228,13 +228,15 @@ static int elo_probe(struct hid_device *hdev, const struct hid_device_id *id) ...@@ -228,13 +228,15 @@ static int elo_probe(struct hid_device *hdev, const struct hid_device_id *id)
{ {
struct elo_priv *priv; struct elo_priv *priv;
int ret; int ret;
struct usb_device *udev;
priv = kzalloc(sizeof(*priv), GFP_KERNEL); priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
INIT_DELAYED_WORK(&priv->work, elo_work); 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); hid_set_drvdata(hdev, priv);
...@@ -265,6 +267,8 @@ static void elo_remove(struct hid_device *hdev) ...@@ -265,6 +267,8 @@ static void elo_remove(struct hid_device *hdev)
{ {
struct elo_priv *priv = hid_get_drvdata(hdev); struct elo_priv *priv = hid_get_drvdata(hdev);
usb_put_dev(priv->usbdev);
hid_hw_stop(hdev); hid_hw_stop(hdev);
cancel_delayed_work_sync(&priv->work); cancel_delayed_work_sync(&priv->work);
kfree(priv); kfree(priv);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment