LCOV - code coverage report
Current view: top level - drivers/media/v4l2-core - v4l2-fh.c (source / functions) Hit Total Coverage
Test: Real Lines: 47 53 88.7 %
Date: 2020-10-17 15:46:16 Functions: 0 7 0.0 %
Legend: Neither, QEMU, Real, Both Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: GPL-2.0-only
       2                 :            : /*
       3                 :            :  * v4l2-fh.c
       4                 :            :  *
       5                 :            :  * V4L2 file handles.
       6                 :            :  *
       7                 :            :  * Copyright (C) 2009--2010 Nokia Corporation.
       8                 :            :  *
       9                 :            :  * Contact: Sakari Ailus <sakari.ailus@iki.fi>
      10                 :            :  */
      11                 :            : 
      12                 :            : #include <linux/bitops.h>
      13                 :            : #include <linux/slab.h>
      14                 :            : #include <linux/export.h>
      15                 :            : #include <media/v4l2-dev.h>
      16                 :            : #include <media/v4l2-fh.h>
      17                 :            : #include <media/v4l2-event.h>
      18                 :            : #include <media/v4l2-ioctl.h>
      19                 :            : #include <media/v4l2-mc.h>
      20                 :            : 
      21                 :          3 : void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev)
      22                 :            : {
      23                 :          3 :         fh->vdev = vdev;
      24                 :            :         /* Inherit from video_device. May be overridden by the driver. */
      25                 :          3 :         fh->ctrl_handler = vdev->ctrl_handler;
      26                 :          3 :         INIT_LIST_HEAD(&fh->list);
      27                 :          3 :         set_bit(V4L2_FL_USES_V4L2_FH, &fh->vdev->flags);
      28                 :            :         /*
      29                 :            :          * determine_valid_ioctls() does not know if struct v4l2_fh
      30                 :            :          * is used by this driver, but here we do. So enable the
      31                 :            :          * prio ioctls here.
      32                 :            :          */
      33                 :          3 :         set_bit(_IOC_NR(VIDIOC_G_PRIORITY), vdev->valid_ioctls);
      34                 :          3 :         set_bit(_IOC_NR(VIDIOC_S_PRIORITY), vdev->valid_ioctls);
      35                 :          3 :         fh->prio = V4L2_PRIORITY_UNSET;
      36                 :          3 :         init_waitqueue_head(&fh->wait);
      37                 :          3 :         INIT_LIST_HEAD(&fh->available);
      38                 :          3 :         INIT_LIST_HEAD(&fh->subscribed);
      39                 :          3 :         fh->sequence = -1;
      40                 :          3 :         mutex_init(&fh->subscribe_lock);
      41                 :          3 : }
      42                 :            : EXPORT_SYMBOL_GPL(v4l2_fh_init);
      43                 :            : 
      44                 :          3 : void v4l2_fh_add(struct v4l2_fh *fh)
      45                 :            : {
      46                 :            :         unsigned long flags;
      47                 :            : 
      48                 :          3 :         v4l2_prio_open(fh->vdev->prio, &fh->prio);
      49                 :          3 :         spin_lock_irqsave(&fh->vdev->fh_lock, flags);
      50                 :          3 :         list_add(&fh->list, &fh->vdev->fh_list);
      51                 :          3 :         spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
      52                 :          3 : }
      53                 :            : EXPORT_SYMBOL_GPL(v4l2_fh_add);
      54                 :            : 
      55                 :          3 : int v4l2_fh_open(struct file *filp)
      56                 :            : {
      57                 :          3 :         struct video_device *vdev = video_devdata(filp);
      58                 :          3 :         struct v4l2_fh *fh = kzalloc(sizeof(*fh), GFP_KERNEL);
      59                 :            : 
      60                 :          3 :         filp->private_data = fh;
      61                 :          3 :         if (fh == NULL)
      62                 :            :                 return -ENOMEM;
      63                 :          3 :         v4l2_fh_init(fh, vdev);
      64                 :          3 :         v4l2_fh_add(fh);
      65                 :          3 :         return 0;
      66                 :            : }
      67                 :            : EXPORT_SYMBOL_GPL(v4l2_fh_open);
      68                 :            : 
      69                 :          3 : void v4l2_fh_del(struct v4l2_fh *fh)
      70                 :            : {
      71                 :            :         unsigned long flags;
      72                 :            : 
      73                 :          3 :         spin_lock_irqsave(&fh->vdev->fh_lock, flags);
      74                 :          3 :         list_del_init(&fh->list);
      75                 :          3 :         spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
      76                 :          3 :         v4l2_prio_close(fh->vdev->prio, fh->prio);
      77                 :          3 : }
      78                 :            : EXPORT_SYMBOL_GPL(v4l2_fh_del);
      79                 :            : 
      80                 :          3 : void v4l2_fh_exit(struct v4l2_fh *fh)
      81                 :            : {
      82                 :          3 :         if (fh->vdev == NULL)
      83                 :          3 :                 return;
      84                 :          3 :         v4l_disable_media_source(fh->vdev);
      85                 :          3 :         v4l2_event_unsubscribe_all(fh);
      86                 :            :         mutex_destroy(&fh->subscribe_lock);
      87                 :          3 :         fh->vdev = NULL;
      88                 :            : }
      89                 :            : EXPORT_SYMBOL_GPL(v4l2_fh_exit);
      90                 :            : 
      91                 :          3 : int v4l2_fh_release(struct file *filp)
      92                 :            : {
      93                 :          3 :         struct v4l2_fh *fh = filp->private_data;
      94                 :            : 
      95                 :          3 :         if (fh) {
      96                 :          3 :                 v4l2_fh_del(fh);
      97                 :          3 :                 v4l2_fh_exit(fh);
      98                 :          3 :                 kfree(fh);
      99                 :            :         }
     100                 :          3 :         return 0;
     101                 :            : }
     102                 :            : EXPORT_SYMBOL_GPL(v4l2_fh_release);
     103                 :            : 
     104                 :          0 : int v4l2_fh_is_singular(struct v4l2_fh *fh)
     105                 :            : {
     106                 :            :         unsigned long flags;
     107                 :            :         int is_singular;
     108                 :            : 
     109                 :          0 :         if (fh == NULL || fh->vdev == NULL)
     110                 :            :                 return 0;
     111                 :          0 :         spin_lock_irqsave(&fh->vdev->fh_lock, flags);
     112                 :          0 :         is_singular = list_is_singular(&fh->list);
     113                 :          0 :         spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
     114                 :          0 :         return is_singular;
     115                 :            : }
     116                 :            : EXPORT_SYMBOL_GPL(v4l2_fh_is_singular);
    

Generated by: LCOV version 1.14