linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stanimir Varbanov <stanimir.varbanov@linaro.org>
To: Hans Verkuil <hverkuil-cisco@xs4all.nl>, linux-media@vger.kernel.org
Cc: Yunfei Dong <yunfei.dong@mediatek.com>
Subject: Re: [RFC PATCH 1/2] v4l2-ctrls.c: add v4l2_ctrl_request_create
Date: Tue, 18 Aug 2020 14:30:17 +0300	[thread overview]
Message-ID: <0e0d5188-7d88-e8e2-d4d0-32e117449b35@linaro.org> (raw)
In-Reply-To: <20200728094851.121933-2-hverkuil-cisco@xs4all.nl>

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@xs4all.nl>
> ---
>  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

  reply	other threads:[~2020-08-18 11:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-28  9:48 [RFC PATCH 0/2] Add v4l2_ctrl_request_create() Hans Verkuil
2020-07-28  9:48 ` [RFC PATCH 1/2] v4l2-ctrls.c: add v4l2_ctrl_request_create Hans Verkuil
2020-08-18 11:30   ` Stanimir Varbanov [this message]
2020-08-18 11:39     ` Hans Verkuil
2020-07-28  9:48 ` [RFC PATCH 2/2] vivid: call v4l2_ctrl_request_create() Hans Verkuil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0e0d5188-7d88-e8e2-d4d0-32e117449b35@linaro.org \
    --to=stanimir.varbanov@linaro.org \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    --cc=yunfei.dong@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).