Skip to contentSkip to conversation

usb: storage: realtek_cr: get lock before calling usb_enable_autosuspend()

PATCH In review Salah Triki 2 participants 2 messages Aug 2, 2021 – Aug 3, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: storage: realtek_cr: get lock before calling usb_enable_autosuspend()

Based on the documentation of usb_enable_autosuspend(), the caller must hold udev's device lock.

---
 drivers/usb/storage/realtek_cr.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/usb/storage/realtek_cr.c +4 -0
index 3789698d9d3c..6948d6fdad39 100644
@@ -918,9 +918,13 @@ static int realtek_cr_autosuspend_setup(struct us_data *us)
 	timer_setup(&chip->rts51x_suspend_timer, rts51x_suspend_timer_fn, 0);
 	fw5895_init(us);
 
+	usb_lock_device(us->pusb_dev);
+
 	/* enable autosuspend function of the usb device */
 	usb_enable_autosuspend(us->pusb_dev);
 
+	usb_unlock_device(us->pusb_dev);
+
 	return 0;
 }
 #endif
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 16 lines · Salah Triki

Based on the documentation of usb_enable_autosuspend(), the caller must hold udev's device lock.

---
 drivers/usb/storage/realtek_cr.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/usb/storage/realtek_cr.c +0 -0
index 3789698d9d3c..6948d6fdad39 100644
@@ -918,9 +918,13 @@ static int realtek_cr_autosuspend_setup(struct us_data *us)
 	timer_setup(&chip->rts51x_suspend_timer, rts51x_suspend_timer_fn, 0);
 	fw5895_init(us);
 

drivers/usb/storage/realtek_cr.c static int realtek_cr_autosuspend_setup(struct us_data *us) · line 930

Quoted 10 lines
drivers/usb/storage/realtek_cr.c +4 -0
+	usb_lock_device(us->pusb_dev);
+
 	/* enable autosuspend function of the usb device */
 	usb_enable_autosuspend(us->pusb_dev);
 
+	usb_unlock_device(us->pusb_dev);
+
 	return 0;
 }
 #endif

I assume you didn't test this patch, because RTS51xx card readers aren't very common. If you had tested it, you would have found that it causes the system to hang.

This is because when realtek_cr_autosuspend_setup runs, the driver already holds the device lock. The route is a little circuitous:

realtek_cr_probe is called with the lock held, like all probe routines.

It calls usb_store_probe2, which calls usb_stor_acquire_resources. That routine calls us->unusual_dev->initFunction. For the realtek_cr driver, the initFunction is set to init_realtek_cr (see unusual_realtek.h).

init_realtek_cr calls realtek_cr_autosuspend_setup.

There is no other pathway to the usb_enable_autosuspend call. So your patch is not needed.

Alan Stern