Skip to content

Commit

Permalink
V4L/DVB (9690): gspca: Lock the subdrivers via module_get/put.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jean-Francois Moine authored and Mauro Carvalho Chehab committed Nov 24, 2008
1 parent 98522a7 commit 5c4fa00
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions drivers/media/video/gspca/gspca.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,13 @@ static int dev_open(struct inode *inode, struct file *file)
ret = -EBUSY;
goto out;
}

/* protect the subdriver against rmmod */
if (!try_module_get(gspca_dev->module)) {
ret = -ENODEV;
goto out;
}

gspca_dev->users++;

/* one more user */
Expand Down Expand Up @@ -920,6 +927,7 @@ static int dev_close(struct inode *inode, struct file *file)
gspca_dev->memory = GSPCA_MEMORY_NO;
}
file->private_data = NULL;
module_put(gspca_dev->module);
mutex_unlock(&gspca_dev->queue_lock);

PDEBUG(D_STREAM, "close done");
Expand Down Expand Up @@ -1870,9 +1878,8 @@ int gspca_dev_probe(struct usb_interface *intf,
/* init video stuff */
memcpy(&gspca_dev->vdev, &gspca_template, sizeof gspca_template);
gspca_dev->vdev.parent = &dev->dev;
memcpy(&gspca_dev->fops, &dev_fops, sizeof gspca_dev->fops);
gspca_dev->vdev.fops = &gspca_dev->fops;
gspca_dev->fops.owner = module; /* module protection */
gspca_dev->vdev.fops = &dev_fops;
gspca_dev->module = module;
gspca_dev->present = 1;
ret = video_register_device(&gspca_dev->vdev,
VFL_TYPE_GRABBER,
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/video/gspca/gspca.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ struct gspca_frame {

struct gspca_dev {
struct video_device vdev; /* !! must be the first item */
struct file_operations fops;
struct module *module; /* subdriver handling the device */
struct usb_device *dev;
struct kref kref;
struct file *capt_file; /* file doing video capture */
Expand Down

0 comments on commit 5c4fa00

Please sign in to comment.