Re: [RFC PATCH 3/7] v4l2-fh: add v4l2_fh_open_is_first and v4l2_fh_release_is_last

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Hans,

On Fri, Jul 24, 2015 at 12:21:32PM +0200, Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@xxxxxxxxx>
> 
> Add new helper functions that report back if this was the first open
> or last close.
> 
> Signed-off-by: Hans Verkuil <hans.verkuil@xxxxxxxxx>
> ---

...

> @@ -65,11 +65,23 @@ void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev);
>   */
>  bool v4l2_fh_add(struct v4l2_fh *fh);
>  /*
> + * It allocates a v4l2_fh and inits and adds it to the video_device associated
> + * with the file pointer. In addition it returns true if this was the first
> + * open and false otherwise. The error code is returned in *err.
> + */
> +bool v4l2_fh_open_is_first(struct file *filp, int *err);

The new interface functions look a tad clumsy to me.

What would you think of returning the singularity value from v4l2_fh_open()
straight away? Negative integers are errors, so zero and positive values are
free.

A few drivers just check if the value is non-zero and then return that
value, but there are just a handful of those.

> +/*
>   * Can be used as the open() op of v4l2_file_operations.
>   * It allocates a v4l2_fh and inits and adds it to the video_device associated
>   * with the file pointer.
>   */
> -int v4l2_fh_open(struct file *filp);
> +static inline int v4l2_fh_open(struct file *filp)
> +{
> +	int err;
> +
> +	v4l2_fh_open_is_first(filp, &err);
> +	return err;
> +}
>  /*
>   * Remove file handle from the list of file handles. Must be called in
>   * v4l2_file_operations->release() handler if the driver uses v4l2_fh.
> @@ -86,12 +98,23 @@ bool v4l2_fh_del(struct v4l2_fh *fh);
>   */
>  void v4l2_fh_exit(struct v4l2_fh *fh);
>  /*
> + * It deletes and exits the v4l2_fh associated with the file pointer and
> + * frees it. It will do nothing if filp->private_data (the pointer to the
> + * v4l2_fh struct) is NULL. This function returns true if this was the
> + * last open file handle and false otherwise.
> + */
> +bool v4l2_fh_release_is_last(struct file *filp);
> +/*
>   * Can be used as the release() op of v4l2_file_operations.
>   * It deletes and exits the v4l2_fh associated with the file pointer and
>   * frees it. It will do nothing if filp->private_data (the pointer to the
>   * v4l2_fh struct) is NULL. This function always returns 0.
>   */
> -int v4l2_fh_release(struct file *filp);
> +static inline int v4l2_fh_release(struct file *filp)
> +{
> +	v4l2_fh_release_is_last(filp);
> +	return 0;
> +}
>  /*
>   * Returns true if this filehandle is the only filehandle opened for the

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ailus@xxxxxx	XMPP: sailus@xxxxxxxxxxxxxx
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux