V4L/DVB (9690): gspca: Lock the subdrivers via module_get/put.

The previous subdriver protection against rmmod was done via the
file operations table in the device descriptor. On device disconnection
while streaming, the device structure was freed at close time, and the
module_put still used the module name in the freed area.
Now, explicit module get/put are done on open and close.

Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by Jean-Francois Moine and committed by Mauro Carvalho Chehab 5c4fa002 98522a7b

+11 -4
+10 -3
drivers/media/video/gspca/gspca.c
··· 874 ret = -EBUSY; 875 goto out; 876 } 877 gspca_dev->users++; 878 879 /* one more user */ ··· 927 gspca_dev->memory = GSPCA_MEMORY_NO; 928 } 929 file->private_data = NULL; 930 mutex_unlock(&gspca_dev->queue_lock); 931 932 PDEBUG(D_STREAM, "close done"); ··· 1878 /* init video stuff */ 1879 memcpy(&gspca_dev->vdev, &gspca_template, sizeof gspca_template); 1880 gspca_dev->vdev.parent = &dev->dev; 1881 - memcpy(&gspca_dev->fops, &dev_fops, sizeof gspca_dev->fops); 1882 - gspca_dev->vdev.fops = &gspca_dev->fops; 1883 - gspca_dev->fops.owner = module; /* module protection */ 1884 gspca_dev->present = 1; 1885 ret = video_register_device(&gspca_dev->vdev, 1886 VFL_TYPE_GRABBER,
··· 874 ret = -EBUSY; 875 goto out; 876 } 877 + 878 + /* protect the subdriver against rmmod */ 879 + if (!try_module_get(gspca_dev->module)) { 880 + ret = -ENODEV; 881 + goto out; 882 + } 883 + 884 gspca_dev->users++; 885 886 /* one more user */ ··· 920 gspca_dev->memory = GSPCA_MEMORY_NO; 921 } 922 file->private_data = NULL; 923 + module_put(gspca_dev->module); 924 mutex_unlock(&gspca_dev->queue_lock); 925 926 PDEBUG(D_STREAM, "close done"); ··· 1870 /* init video stuff */ 1871 memcpy(&gspca_dev->vdev, &gspca_template, sizeof gspca_template); 1872 gspca_dev->vdev.parent = &dev->dev; 1873 + gspca_dev->vdev.fops = &dev_fops; 1874 + gspca_dev->module = module; 1875 gspca_dev->present = 1; 1876 ret = video_register_device(&gspca_dev->vdev, 1877 VFL_TYPE_GRABBER,
+1 -1
drivers/media/video/gspca/gspca.h
··· 121 122 struct gspca_dev { 123 struct video_device vdev; /* !! must be the first item */ 124 - struct file_operations fops; 125 struct usb_device *dev; 126 struct kref kref; 127 struct file *capt_file; /* file doing video capture */
··· 121 122 struct gspca_dev { 123 struct video_device vdev; /* !! must be the first item */ 124 + struct module *module; /* subdriver handling the device */ 125 struct usb_device *dev; 126 struct kref kref; 127 struct file *capt_file; /* file doing video capture */