Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] saa7146: remove V4L2_FL_LOCK_ALL_FOPS

Add proper locking to the file operations, allowing for the removal
of the V4L2_FL_LOCK_ALL_FOPS flag.

I also removed some dead code in the form of the saa7146_devices list and
saa7146_devices_lock mutex: these were used once but that was a long time
ago.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
6de7d14d 85397ef6

+39 -28
-8
drivers/media/common/saa7146_core.c
··· 23 23 #include <media/saa7146.h> 24 24 #include <linux/module.h> 25 25 26 - LIST_HEAD(saa7146_devices); 27 - DEFINE_MUTEX(saa7146_devices_lock); 28 - 29 26 static int saa7146_num; 30 27 31 28 unsigned int saa7146_debug; ··· 479 482 set it explicitly. */ 480 483 pci_set_drvdata(pci, &dev->v4l2_dev); 481 484 482 - INIT_LIST_HEAD(&dev->item); 483 - list_add_tail(&dev->item,&saa7146_devices); 484 485 saa7146_num++; 485 486 486 487 err = 0; ··· 540 545 541 546 iounmap(dev->mem); 542 547 pci_release_region(pdev, 0); 543 - list_del(&dev->item); 544 548 pci_disable_device(pdev); 545 549 kfree(dev); 546 550 ··· 586 592 EXPORT_SYMBOL_GPL(saa7146_i2c_adapter_prepare); 587 593 588 594 EXPORT_SYMBOL_GPL(saa7146_debug); 589 - EXPORT_SYMBOL_GPL(saa7146_devices); 590 - EXPORT_SYMBOL_GPL(saa7146_devices_lock); 591 595 592 596 MODULE_AUTHOR("Michael Hunold <michael@mihu.de>"); 593 597 MODULE_DESCRIPTION("driver for generic saa7146-based hardware");
+39 -16
drivers/media/common/saa7146_fops.c
··· 201 201 202 202 DEB_EE("file:%p, dev:%s\n", file, video_device_node_name(vdev)); 203 203 204 - if (mutex_lock_interruptible(&saa7146_devices_lock)) 204 + if (mutex_lock_interruptible(vdev->lock)) 205 205 return -ERESTARTSYS; 206 206 207 207 DEB_D("using: %p\n", dev); ··· 253 253 kfree(fh); 254 254 file->private_data = NULL; 255 255 } 256 - mutex_unlock(&saa7146_devices_lock); 256 + mutex_unlock(vdev->lock); 257 257 return result; 258 258 } 259 259 ··· 265 265 266 266 DEB_EE("file:%p\n", file); 267 267 268 - if (mutex_lock_interruptible(&saa7146_devices_lock)) 268 + if (mutex_lock_interruptible(vdev->lock)) 269 269 return -ERESTARTSYS; 270 270 271 271 if (vdev->vfl_type == VFL_TYPE_VBI) { ··· 283 283 file->private_data = NULL; 284 284 kfree(fh); 285 285 286 - mutex_unlock(&saa7146_devices_lock); 286 + mutex_unlock(vdev->lock); 287 287 288 288 return 0; 289 289 } ··· 293 293 struct video_device *vdev = video_devdata(file); 294 294 struct saa7146_fh *fh = file->private_data; 295 295 struct videobuf_queue *q; 296 + int res; 296 297 297 298 switch (vdev->vfl_type) { 298 299 case VFL_TYPE_GRABBER: { ··· 315 314 return 0; 316 315 } 317 316 318 - return videobuf_mmap_mapper(q,vma); 317 + if (mutex_lock_interruptible(vdev->lock)) 318 + return -ERESTARTSYS; 319 + res = videobuf_mmap_mapper(q, vma); 320 + mutex_unlock(vdev->lock); 321 + return res; 319 322 } 320 323 321 - static unsigned int fops_poll(struct file *file, struct poll_table_struct *wait) 324 + static unsigned int __fops_poll(struct file *file, struct poll_table_struct *wait) 322 325 { 323 326 struct video_device *vdev = video_devdata(file); 324 327 struct saa7146_fh *fh = file->private_data; ··· 361 356 return res; 362 357 } 363 358 359 + static unsigned int fops_poll(struct file *file, struct poll_table_struct *wait) 360 + { 361 + struct video_device *vdev = video_devdata(file); 362 + unsigned int res; 363 + 364 + mutex_lock(vdev->lock); 365 + res = __fops_poll(file, wait); 366 + mutex_unlock(vdev->lock); 367 + return res; 368 + } 369 + 364 370 static ssize_t fops_read(struct file *file, char __user *data, size_t count, loff_t *ppos) 365 371 { 366 372 struct video_device *vdev = video_devdata(file); 367 373 struct saa7146_fh *fh = file->private_data; 374 + int ret; 368 375 369 376 switch (vdev->vfl_type) { 370 377 case VFL_TYPE_GRABBER: ··· 390 373 DEB_EE("V4L2_BUF_TYPE_VBI_CAPTURE: file:%p, data:%p, count:%lu\n", 391 374 file, data, (unsigned long)count); 392 375 */ 393 - if (fh->dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE) 394 - return saa7146_vbi_uops.read(file,data,count,ppos); 376 + if (fh->dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE) { 377 + if (mutex_lock_interruptible(vdev->lock)) 378 + return -ERESTARTSYS; 379 + ret = saa7146_vbi_uops.read(file, data, count, ppos); 380 + mutex_unlock(vdev->lock); 381 + return ret; 382 + } 395 383 return -EINVAL; 396 384 default: 397 385 BUG(); ··· 408 386 { 409 387 struct video_device *vdev = video_devdata(file); 410 388 struct saa7146_fh *fh = file->private_data; 389 + int ret; 411 390 412 391 switch (vdev->vfl_type) { 413 392 case VFL_TYPE_GRABBER: 414 393 return -EINVAL; 415 394 case VFL_TYPE_VBI: 416 - if (fh->dev->ext_vv_data->vbi_fops.write) 417 - return fh->dev->ext_vv_data->vbi_fops.write(file, data, count, ppos); 418 - else 419 - return -EINVAL; 395 + if (fh->dev->ext_vv_data->vbi_fops.write) { 396 + if (mutex_lock_interruptible(vdev->lock)) 397 + return -ERESTARTSYS; 398 + ret = fh->dev->ext_vv_data->vbi_fops.write(file, data, count, ppos); 399 + mutex_unlock(vdev->lock); 400 + return ret; 401 + } 402 + return -EINVAL; 420 403 default: 421 404 BUG(); 422 405 return -EINVAL; ··· 611 584 else 612 585 vfd->ioctl_ops = &dev->ext_vv_data->vbi_ops; 613 586 vfd->release = video_device_release; 614 - /* Locking in file operations other than ioctl should be done by 615 - the driver, not the V4L2 core. 616 - This driver needs auditing so that this flag can be removed. */ 617 - set_bit(V4L2_FL_LOCK_ALL_FOPS, &vfd->flags); 618 587 vfd->lock = &dev->v4l2_lock; 619 588 vfd->v4l2_dev = &dev->v4l2_dev; 620 589 vfd->tvnorms = 0;
-4
include/media/saa7146.h
··· 117 117 { 118 118 struct module *module; 119 119 120 - struct list_head item; 121 - 122 120 struct v4l2_device v4l2_dev; 123 121 struct v4l2_ctrl_handler ctrl_handler; 124 122 ··· 164 166 int saa7146_i2c_adapter_prepare(struct saa7146_dev *dev, struct i2c_adapter *i2c_adapter, u32 bitrate); 165 167 166 168 /* from saa7146_core.c */ 167 - extern struct list_head saa7146_devices; 168 - extern struct mutex saa7146_devices_lock; 169 169 int saa7146_register_extension(struct saa7146_extension*); 170 170 int saa7146_unregister_extension(struct saa7146_extension*); 171 171 struct saa7146_format* saa7146_format_by_fourcc(struct saa7146_dev *dev, int fourcc);