Re: [RFC PATCH 1/2] v4l2-ctrls.c: add v4l2_ctrl_request_create

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

 



Hi Hans,

On 7/28/20 12:48 PM, Hans Verkuil wrote:
> Add a new v4l2_ctrl_request_create() function that can be called in
> req_validate() to create a control request object if needed.
> 
> This is needed if the driver needs to set controls in the request,
> 
> Signed-off-by: Hans Verkuil <hverkuil-cisco@xxxxxxxxx>
> ---
>  drivers/media/mc/mc-request.c        |  3 ++-
>  drivers/media/v4l2-core/v4l2-ctrls.c | 35 ++++++++++++++++++++++++++++
>  include/media/v4l2-ctrls.h           | 16 +++++++++++++
>  3 files changed, 53 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/mc/mc-request.c b/drivers/media/mc/mc-request.c
> index c0782fd96c59..64df83c6f5e5 100644
> --- a/drivers/media/mc/mc-request.c
> +++ b/drivers/media/mc/mc-request.c
> @@ -414,7 +414,8 @@ int media_request_object_bind(struct media_request *req,
>  
>  	spin_lock_irqsave(&req->lock, flags);
>  
> -	if (WARN_ON(req->state != MEDIA_REQUEST_STATE_UPDATING))
> +	if (WARN_ON(req->state != MEDIA_REQUEST_STATE_UPDATING &&
> +		    req->state != MEDIA_REQUEST_STATE_VALIDATING))
>  		goto unlock;
>  
>  	obj->req = req;
> diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
> index 3f3fbcd60cc6..0d4c8551ba2a 100644
> --- a/drivers/media/v4l2-core/v4l2-ctrls.c
> +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
> @@ -4345,6 +4345,41 @@ void v4l2_ctrl_request_complete(struct media_request *req,
>  }
>  EXPORT_SYMBOL(v4l2_ctrl_request_complete);
>  
> +int v4l2_ctrl_request_create(struct media_request *req,
> +			     struct v4l2_ctrl_handler *main_hdl)
> +{
> +	struct media_request_object *obj;
> +	struct v4l2_ctrl_handler *new_hdl;
> +	int ret = 0;
> +
> +	if (!req || !main_hdl)
> +		return 0;
> +
> +	if (WARN_ON(req->state != MEDIA_REQUEST_STATE_VALIDATING))
> +		return -EBUSY;
> +
> +	/* If a request object is found, then do nothing. */
> +	obj = media_request_object_find(req, &req_ops, main_hdl);
> +	if (obj) {
> +		media_request_object_put(obj);
> +		return 0;
> +	}
> +
> +	/* Create a new request so the driver can return controls */
> +	new_hdl = kzalloc(sizeof(*new_hdl), GFP_KERNEL);
> +	if (!new_hdl)
> +		return -ENOMEM;
> +
> +	obj = &new_hdl->req_obj;

Why initialize 'obj' and then not use it? Did you forget something

> +	ret = v4l2_ctrl_handler_init(new_hdl, (main_hdl->nr_of_buckets - 1) * 8);
> +	if (!ret)
> +		ret = v4l2_ctrl_request_bind(req, new_hdl, main_hdl);
> +	if (ret)
> +		kfree(new_hdl);
> +	return ret;
> +}
> +EXPORT_SYMBOL(v4l2_ctrl_request_create);
> +
>  int v4l2_ctrl_request_setup(struct media_request *req,
>  			     struct v4l2_ctrl_handler *main_hdl)
>  {
> diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
> index f40e2cbb21d3..2703baa170fa 100644
> --- a/include/media/v4l2-ctrls.h
> +++ b/include/media/v4l2-ctrls.h
> @@ -1254,6 +1254,22 @@ int v4l2_ctrl_request_setup(struct media_request *req,
>  void v4l2_ctrl_request_complete(struct media_request *req,
>  				struct v4l2_ctrl_handler *parent);
>  
> +/**
> + * v4l2_ctrl_request_create - Create a control handler request object
> + *
> + * @req: The request
> + * @parent: The parent control handler ('priv' in media_request_object_find())
> + *
> + * If the user created a request without controls, but the driver wants to
> + * set controls for the request, then this function can be called in the
> + * request's req_validate function. If there is no control object in the
> + * request, then this will create one. Now the driver can set controls
> + * and when v4l2_ctrl_request_complete() is called they will be automatically
> + * copied into the request.
> + */
> +int v4l2_ctrl_request_create(struct media_request *req,
> +			     struct v4l2_ctrl_handler *parent);
> +
>  /**
>   * v4l2_ctrl_request_hdl_find - Find the control handler in the request
>   *
> 

-- 
regards,
Stan



[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