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

[media] v4l2-fh: add v4l2_fh_is_singular

Several drivers need to do something when the first filehandle is opened
or the last filehandle is closed. Most implement some use count mechanism,
but if they use v4l2_fh, then you can also just check if this is the only
filehandle for the device node. A simple helper function can do this.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
dfddb244 73cb4206

+27
+14
drivers/media/video/v4l2-fh.c
··· 109 109 return 0; 110 110 } 111 111 EXPORT_SYMBOL_GPL(v4l2_fh_release); 112 + 113 + int v4l2_fh_is_singular(struct v4l2_fh *fh) 114 + { 115 + unsigned long flags; 116 + int is_singular; 117 + 118 + if (fh == NULL || fh->vdev == NULL) 119 + return 0; 120 + spin_lock_irqsave(&fh->vdev->fh_lock, flags); 121 + is_singular = list_is_singular(&fh->list); 122 + spin_unlock_irqrestore(&fh->vdev->fh_lock, flags); 123 + return is_singular; 124 + } 125 + EXPORT_SYMBOL_GPL(v4l2_fh_is_singular);
+13
include/media/v4l2-fh.h
··· 77 77 * v4l2_fh struct) is NULL. This function always returns 0. 78 78 */ 79 79 int v4l2_fh_release(struct file *filp); 80 + /* 81 + * Returns 1 if this filehandle is the only filehandle opened for the 82 + * associated video_device. If fh is NULL, then it returns 0. 83 + */ 84 + int v4l2_fh_is_singular(struct v4l2_fh *fh); 85 + /* 86 + * Helper function with struct file as argument. If filp->private_data is 87 + * NULL, then it will return 0. 88 + */ 89 + static inline int v4l2_fh_is_singular_file(struct file *filp) 90 + { 91 + return v4l2_fh_is_singular(filp->private_data); 92 + } 80 93 81 94 #endif /* V4L2_EVENT_H */