All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] radio-mr800: locking fixes
@ 2010-10-17 12:26 Hans Verkuil
  2010-10-17 12:52 ` Hans Verkuil
  2010-10-18 13:25 ` David Ellingsworth
  0 siblings, 2 replies; 15+ messages in thread
From: Hans Verkuil @ 2010-10-17 12:26 UTC (permalink / raw)
  To: linux-media; +Cc: David Ellingsworth

- serialize the suspend and resume functions using the global lock.
- do not call usb_autopm_put_interface after a disconnect.
- fix a race when disconnecting the device.

Reported-by: David Ellingsworth <david@identd.dyndns.org>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
---
 drivers/media/radio/radio-mr800.c |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/media/radio/radio-mr800.c b/drivers/media/radio/radio-mr800.c
index 2f56b26..b540e80 100644
--- a/drivers/media/radio/radio-mr800.c
+++ b/drivers/media/radio/radio-mr800.c
@@ -284,9 +284,13 @@ static void usb_amradio_disconnect(struct usb_interface *intf)
 	struct amradio_device *radio = to_amradio_dev(usb_get_intfdata(intf));
 
 	mutex_lock(&radio->lock);
+	/* increase the device node's refcount */
+	get_device(&radio->videodev.dev);
 	v4l2_device_disconnect(&radio->v4l2_dev);
-	mutex_unlock(&radio->lock);
 	video_unregister_device(&radio->videodev);
+	mutex_unlock(&radio->lock);
+	/* decrease the device node's refcount, allowing it to be released */
+	put_device(&radio->videodev.dev);
 }
 
 /* vidioc_querycap - query device capabilities */
@@ -515,7 +519,8 @@ static int usb_amradio_close(struct file *file)
 {
 	struct amradio_device *radio = file->private_data;
 
-	usb_autopm_put_interface(radio->intf);
+	if (video_is_registered(&radio->videodev))
+		usb_autopm_put_interface(radio->intf);
 	return 0;
 }
 
@@ -524,10 +529,12 @@ static int usb_amradio_suspend(struct usb_interface *intf, pm_message_t message)
 {
 	struct amradio_device *radio = to_amradio_dev(usb_get_intfdata(intf));
 
+	mutex_lock(&radio->lock);
 	if (!radio->muted && radio->initialized) {
 		amradio_set_mute(radio, AMRADIO_STOP);
 		radio->muted = 0;
 	}
+	mutex_unlock(&radio->lock);
 
 	dev_info(&intf->dev, "going into suspend..\n");
 	return 0;
@@ -538,8 +545,9 @@ static int usb_amradio_resume(struct usb_interface *intf)
 {
 	struct amradio_device *radio = to_amradio_dev(usb_get_intfdata(intf));
 
+	mutex_lock(&radio->lock);
 	if (unlikely(!radio->initialized))
-		return 0;
+		goto unlock;
 
 	if (radio->stereo)
 		amradio_set_stereo(radio, WANT_STEREO);
@@ -551,6 +559,9 @@ static int usb_amradio_resume(struct usb_interface *intf)
 	if (!radio->muted)
 		amradio_set_mute(radio, AMRADIO_START);
 
+unlock:
+	mutex_unlock(&radio->lock);
+
 	dev_info(&intf->dev, "coming out of suspend..\n");
 	return 0;
 }
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2010-10-23  1:21 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-17 12:26 [RFC PATCH] radio-mr800: locking fixes Hans Verkuil
2010-10-17 12:52 ` Hans Verkuil
2010-10-18 13:16   ` David Ellingsworth
2010-10-18 13:20     ` Hans Verkuil
2010-10-18 16:06       ` David Ellingsworth
2010-10-18 13:25 ` David Ellingsworth
2010-10-18 13:38   ` Hans Verkuil
2010-10-18 13:56     ` David Ellingsworth
2010-10-18 14:18       ` Hans Verkuil
2010-10-18 14:35         ` David Ellingsworth
2010-10-18 14:55           ` David Ellingsworth
2010-10-18 15:51             ` Hans Verkuil
2010-10-23  0:31               ` Mauro Carvalho Chehab
2010-10-23  1:21                 ` David Ellingsworth
2010-10-18 13:38   ` Hans Verkuil

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.