diff mbox

[2/6] em28xx: refactor the code in em28xx_usb_disconnect()

Message ID 1356649368-5426-3-git-send-email-fschaefer.oss@googlemail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Frank Schäfer Dec. 27, 2012, 11:02 p.m. UTC
The main purpose of this patch is to move the call of em28xx_release_resources()
after the call of em28xx_close_extension().
This is necessary, because some resources might be needed/used by the extensions
fini() functions when they get closed.
Also mark the device as disconnected earlier in this function and unify the
em28xx_uninit_usb_xfer() calls for analog and digital mode.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
---
 drivers/media/usb/em28xx/em28xx-cards.c |   26 +++++++++++---------------
 1 Datei geändert, 11 Zeilen hinzugefügt(+), 15 Zeilen entfernt(-)

Comments

Antti Palosaari Jan. 2, 2013, 7:40 p.m. UTC | #1
On 12/28/2012 01:02 AM, Frank Schäfer wrote:
> The main purpose of this patch is to move the call of em28xx_release_resources()
> after the call of em28xx_close_extension().
> This is necessary, because some resources might be needed/used by the extensions
> fini() functions when they get closed.
> Also mark the device as disconnected earlier in this function and unify the
> em28xx_uninit_usb_xfer() calls for analog and digital mode.

This looks like it could fix that one bug I reported earlier. Care to 
look these:

em28xx releases I2C adapter earlier than demod/tuner/sec
http://www.spinics.net/lists/linux-media/msg54693.html

em28xx #0: submit of audio urb failed
http://www.spinics.net/lists/linux-media/msg54694.html


regards
Antti
Frank Schäfer Jan. 2, 2013, 9:18 p.m. UTC | #2
Am 02.01.2013 20:40, schrieb Antti Palosaari:
> On 12/28/2012 01:02 AM, Frank Schäfer wrote:
>> The main purpose of this patch is to move the call of
>> em28xx_release_resources()
>> after the call of em28xx_close_extension().
>> This is necessary, because some resources might be needed/used by the
>> extensions
>> fini() functions when they get closed.
>> Also mark the device as disconnected earlier in this function and
>> unify the
>> em28xx_uninit_usb_xfer() calls for analog and digital mode.
>
> This looks like it could fix that one bug I reported earlier. Care to
> look these:
>
> em28xx releases I2C adapter earlier than demod/tuner/sec
> http://www.spinics.net/lists/linux-media/msg54693.html

Yes, this one gets fixed with the patch.

>
> em28xx #0: submit of audio urb failed
> http://www.spinics.net/lists/linux-media/msg54694.html

Seems to describe more than one bug.
What do mean with "when I plug em28xx device with analog support" ? Did
you mean "unplug" ?
Does this device use an external audio IC connected via i2c (e.g. EM202) ?
If yes, I think the patch should fix this issue, too.
Do you still have access to this device ? Can you test the patch ?

Regards,
Frank

>
>
> regards
> Antti
>

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c
index 8496a06..40c3e45 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -3478,6 +3478,8 @@  static void em28xx_usb_disconnect(struct usb_interface *interface)
 	if (!dev)
 		return;
 
+	dev->disconnected = 1;
+
 	if (dev->is_audio_only) {
 		mutex_lock(&dev->lock);
 		em28xx_close_extension(dev);
@@ -3489,32 +3491,26 @@  static void em28xx_usb_disconnect(struct usb_interface *interface)
 
 	flush_request_modules(dev);
 
-	/* wait until all current v4l2 io is finished then deallocate
-	   resources */
 	mutex_lock(&dev->lock);
 
 	v4l2_device_disconnect(&dev->v4l2_dev);
 
 	if (dev->users) {
-		em28xx_warn
-		    ("device %s is open! Deregistration and memory "
-		     "deallocation are deferred on close.\n",
-		     video_device_node_name(dev->vdev));
+		em28xx_warn("device %s is open! Deregistration and memory deallocation are deferred on close.\n",
+			    video_device_node_name(dev->vdev));
 
-		em28xx_uninit_usb_xfer(dev, dev->mode);
-		dev->disconnected = 1;
-	} else {
-		dev->disconnected = 1;
-		em28xx_release_resources(dev);
+		em28xx_uninit_usb_xfer(dev, EM28XX_ANALOG_MODE);
+		em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
 	}
 
-	/* free DVB isoc buffers */
-	em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
+	em28xx_close_extension(dev);
+	/* NOTE: must be called BEFORE the resources are released */
+
+	if (!dev->users)
+		em28xx_release_resources(dev);
 
 	mutex_unlock(&dev->lock);
 
-	em28xx_close_extension(dev);
-
 	if (!dev->users) {
 		kfree(dev->alt_max_pkt_size_isoc);
 		kfree(dev);