--- linux-2.4.20/drivers/media/video/videodev.c.orig Sun Jan 26 21:06:59 2003 +++ linux-2.4.20/drivers/media/video/videodev.c Sun Jan 26 21:14:35 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); + 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; }