Re: Are *all* 2.4.x v4l drivers now broken?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Hi 

I tested Gerd's patch to fix the deadlock when old-v4l-interface drivers
get hot unplugged --  It doesn't quite do the job because vfl->owner can't get
its module count decreased if vfl=NULL after the cleanup.  The solution is to
store a pointer to vfl->owner before calling vfl->close, then later do a
__MOD_DEC_USE_COUNT with it, rather than with vfl->owner, which may be history.

 I attach a (I think) corrected patch.  (tested).    I basically need this 
patch for RedHat 7.x and 8.0 2.4.18 kernels which already have the new v4l
interface that appeared only officially in 2.4.19, but have it in a broken form,
so its unusable, and the old interface must be still be used.  (This is for
an improved version of the cpia driver that users can substitute for their
Official Kernel one, and which will only use the new interface in 2.4.19 or
later kernels.)

(Hopefully the 2.4.21 kernel can get all the improvements in the cpia driver, so
this type of maintenance can end ...)

This patch is *definitely* needed for all those drivers which are not
updated to use the new V4L interface.  It's tested against various sequences
of hot_unplugging multiple cameras.
Duncan.



diff -uNr linux-2.4.20/drivers/media/video/videodev.c
linux-2.4.20-videodev_fix/drivers/media/video/videodev.c
--- linux-2.4.20/drivers/media/video/videodev.c Sun Sep 29 19:31:52 2002
+++ linux-2.4.20-videodev_fix/drivers/media/video/videodev.c    Wed Jan  8
03:11:25 2003
@@ -186,14 +186,20 @@
 static int video_release(struct inode *inode, struct file *file)
 {
        struct video_device *vfl;
+       struct module *owner;
 
-       down(&videodev_lock);
        vfl = video_devdata(file);
-       if(vfl->close)
+       owner = vfl->owner;
+       if(vfl->close) 
                vfl->close(vfl);
-       vfl->users--;
-       if(vfl->owner)
-               __MOD_DEC_USE_COUNT(vfl->owner);
+
+       down(&videodev_lock);
+       /* ->close() might have called video_device_unregister()
+          in case of a hot unplug, thus we have to get vfl again */
+       if (vfl = video_devdata(file)) 
+               vfl->users--;
+       if (owner) 
+               __MOD_DEC_USE_COUNT(owner);
        up(&videodev_lock);
        return 0;
 }

 




On 10-Dec-2002 Gerd Knorr wrote:
> Duncan Haldane wrote:
>>  Hi,
>>   
>>  continuing my investigation of the effects of the lock added to
>>  video_unregister_device() in 2.4.19, I got reports of yet more
>>  drivers that are broken in a way that is fatal to the system if the
>>  camera is disconnected while open.
<snip>>>  
> 
> The patch below hopefully fixes that without creating new holes.
> Comments?
> 
>   Gerd
> 
> ==============================[ cut here ]==============================
> --- videodev.c.lock   2002-12-10 11:06:04.000000000 +0100
> +++ videodev.c        2002-12-10 11:21:44.000000000 +0100
> @@ -187,13 +187,19 @@
>  {
>       struct video_device *vfl;
>  
> -     down(&videodev_lock);
>       vfl = video_devdata(file);
>       if(vfl->close)
>               vfl->close(vfl);
> -     vfl->users--;
> -     if(vfl->owner)
> -             __MOD_DEC_USE_COUNT(vfl->owner);
> +
> +     down(&videodev_lock);
> +     /* ->close() might have called video_device_unregister()
> +           in case of a hot unplug, thus we have to get vfl again */
> +     vfl = video_devdata(file);
> +     if (NULL != vfl) {
> +             vfl->users--;
> +             if(vfl->owner)
> +                     __MOD_DEC_USE_COUNT(vfl->owner);
> +     }
>       up(&videodev_lock);
>       return 0;
>  }
> 
> 
> 
> --
> video4linux-list mailing list
> Unsubscribe mailto:video4linux-list-request@xxxxxxxxxx?subject=unsubscribe
> https://listman.redhat.com/mailman/listinfo/video4linux-list

----------------------------------
E-Mail: Duncan Haldane <f.duncan.m.haldane@xxxxxxxxxxxxxxxx>
Date: 08-Jan-2003
Time: 03:21:59

This message was sent by XFMail
----------------------------------





[Index of Archives]     [Linux DVB]     [Video Disk Recorder]     [Asterisk]     [Photo]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Free Photo Albums]     [Fedora Users]     [Fedora Women]     [ALSA Users]     [ALSA Devel]     [Linux USB]

Powered by Linux