[PATCH] hid-elo: update the reference count of the usb device structure

Subsystems: hid core layer, the rest

STALE1901d

2 messages, 2 authors, 2021-07-25 · open the first message on its own page

[PATCH] hid-elo: update the reference count of the usb device structure

From: Salah Triki <salah.triki@gmail.com>
Date: 2021-07-24 20:24:42

Use usb_get_dev() and usb_put_dev() in order to update the reference
count of the usb device structure.

Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
 drivers/hid/hid-elo.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/hid/hid-elo.c b/drivers/hid/hid-elo.c
index 0d22713a3874..383dfda8c12f 100644
--- a/drivers/hid/hid-elo.c
+++ b/drivers/hid/hid-elo.c
@@ -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);
 
@@ -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);
-- 
2.25.1

Re: [PATCH] hid-elo: update the reference count of the usb device structure

From: Greg KH <gregkh@linuxfoundation.org>
Date: 2021-07-25 06:33:39

On Sat, Jul 24, 2021 at 09:24:34PM +0100, Salah Triki wrote:
Use usb_get_dev() and usb_put_dev() in order to update the reference
count of the usb device structure.
Why?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help