Skip to content

Commit 5c4fa00

Browse files
moinejfMauro Carvalho Chehab
authored andcommitted
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 <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 98522a7 commit 5c4fa00

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

drivers/media/video/gspca/gspca.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,13 @@ static int dev_open(struct inode *inode, struct file *file)
874874
ret = -EBUSY;
875875
goto out;
876876
}
877+
878+
/* protect the subdriver against rmmod */
879+
if (!try_module_get(gspca_dev->module)) {
880+
ret = -ENODEV;
881+
goto out;
882+
}
883+
877884
gspca_dev->users++;
878885

879886
/* one more user */
@@ -920,6 +927,7 @@ static int dev_close(struct inode *inode, struct file *file)
920927
gspca_dev->memory = GSPCA_MEMORY_NO;
921928
}
922929
file->private_data = NULL;
930+
module_put(gspca_dev->module);
923931
mutex_unlock(&gspca_dev->queue_lock);
924932

925933
PDEBUG(D_STREAM, "close done");
@@ -1870,9 +1878,8 @@ int gspca_dev_probe(struct usb_interface *intf,
18701878
/* init video stuff */
18711879
memcpy(&gspca_dev->vdev, &gspca_template, sizeof gspca_template);
18721880
gspca_dev->vdev.parent = &dev->dev;
1873-
memcpy(&gspca_dev->fops, &dev_fops, sizeof gspca_dev->fops);
1874-
gspca_dev->vdev.fops = &gspca_dev->fops;
1875-
gspca_dev->fops.owner = module; /* module protection */
1881+
gspca_dev->vdev.fops = &dev_fops;
1882+
gspca_dev->module = module;
18761883
gspca_dev->present = 1;
18771884
ret = video_register_device(&gspca_dev->vdev,
18781885
VFL_TYPE_GRABBER,

drivers/media/video/gspca/gspca.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ struct gspca_frame {
121121

122122
struct gspca_dev {
123123
struct video_device vdev; /* !! must be the first item */
124-
struct file_operations fops;
124+
struct module *module; /* subdriver handling the device */
125125
struct usb_device *dev;
126126
struct kref kref;
127127
struct file *capt_file; /* file doing video capture */

0 commit comments

Comments
 (0)