Linux Media Controller development
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: linux-media@vger.kernel.org, Hans Verkuil <hans@jjverkuil.nl>
Subject: Re: [PATCH v4 2/3] media: v4l2-ctrls: Return the handler's error in v4l2_ctrl_handler_free()
Date: Mon, 23 Jun 2025 15:29:33 +0300	[thread overview]
Message-ID: <20250623122933.GI826@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20250623122717.GG826@pendragon.ideasonboard.com>

On Mon, Jun 23, 2025 at 03:27:19PM +0300, Laurent Pinchart wrote:
> Hi Sakari,
> 
> Thank you for the patch.
> 
> On Mon, Jun 23, 2025 at 03:23:13PM +0300, Sakari Ailus wrote:
> > v4l2_ctrl_handler_free() used to return void but changing this to int,
> > returning the handler's error code, enables the drivers to simply return
> > the handler's error in this common error handling pattern:
> > 
> > 	if (handler->error)
> > 		return v4l2_ctrl_handler_free(handler);
> > 
> > Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> > ---
> >  drivers/media/v4l2-core/v4l2-ctrls-core.c | 11 ++++++++---
> >  include/media/v4l2-ctrls.h                |  4 +++-
> >  2 files changed, 11 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c
> > index d28596c720d8..98b960775e87 100644
> > --- a/drivers/media/v4l2-core/v4l2-ctrls-core.c
> > +++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c
> > @@ -1631,14 +1631,17 @@ int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
> >  EXPORT_SYMBOL(v4l2_ctrl_handler_init_class);
> >  
> >  /* Free all controls and control refs */
> > -void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl)
> > +int v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl)
> >  {
> >  	struct v4l2_ctrl_ref *ref, *next_ref;
> >  	struct v4l2_ctrl *ctrl, *next_ctrl;
> >  	struct v4l2_subscribed_event *sev, *next_sev;
> >  
> > -	if (hdl == NULL || hdl->buckets == NULL)
> > -		return;
> > +	if (!hdl)
> > +		return 0;
> > +
> > +	if (!hdl->buckets)
> > +		return hdl->error;
> 
> !hdl->buckets means the handler has been freed, or is not initialized.
> I'd return 0 in that case.

Actually it can also mean init failed due to an allocation error, in
which case error is set to -ENOMEM. Please ignore this comment.

> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

You can keep this.

> >  
> >  	v4l2_ctrl_handler_free_request(hdl);
> >  
> > @@ -1663,6 +1666,8 @@ void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl)
> >  	hdl->cached = NULL;
> >  	mutex_unlock(hdl->lock);
> >  	mutex_destroy(&hdl->_lock);
> > +
> > +	return hdl->error;
> >  }
> >  EXPORT_SYMBOL(v4l2_ctrl_handler_free);
> >  
> > diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
> > index 3a87096e064f..c32c46286441 100644
> > --- a/include/media/v4l2-ctrls.h
> > +++ b/include/media/v4l2-ctrls.h
> > @@ -579,8 +579,10 @@ int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
> >   * @hdl:	The control handler.
> >   *
> >   * Does nothing if @hdl == NULL.
> > + *
> > + * Return: @hdl's error field or 0 if @hdl is NULL.
> >   */
> > -void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
> > +int v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
> >  
> >  /**
> >   * v4l2_ctrl_lock() - Helper function to lock the handler

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2025-06-23 12:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-23 12:23 [PATCH v3 0/3] Control handler free changes Sakari Ailus
2025-06-23 12:23 ` [PATCH v4 1/3] media: v4l2-ctrls: Don't reset handler's error in v4l2_ctrl_handler_free() Sakari Ailus
2025-06-23 12:25   ` Laurent Pinchart
2025-06-23 12:23 ` [PATCH v4 2/3] media: v4l2-ctrls: Return the " Sakari Ailus
2025-06-23 12:27   ` Laurent Pinchart
2025-06-23 12:29     ` Laurent Pinchart [this message]
2025-06-23 12:58     ` Hans Verkuil
2025-06-23 12:56   ` Hans Verkuil
2025-06-23 12:23 ` [PATCH v4 3/3] media: Documentation: Document new v4l2_ctrl_handler_free() behaviour Sakari Ailus
2025-06-23 12:28   ` Laurent Pinchart
2025-06-23 13:00   ` 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=20250623122933.GI826@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=hans@jjverkuil.nl \
    --cc=linux-media@vger.kernel.org \
    --cc=sakari.ailus@linux.intel.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