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