All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: Sakari Ailus <sakari.ailus@iki.fi>,
	linux-media@vger.kernel.org, niklas.soderlund@ragnatech.se,
	maxime.ripard@free-electrons.com,
	laurent.pinchart@ideasonboard.com, pavel@ucw.cz, sre@kernel.org
Subject: Re: [PATCH v15 04/32] v4l: async: Fix notifier complete callback error handling
Date: Tue, 10 Oct 2017 17:21:01 +0300	[thread overview]
Message-ID: <20171010142101.u2tip7kch4dwuvih@paasikivi.fi.intel.com> (raw)
In-Reply-To: <527a8c33-f982-edd2-7cb5-a7a16992f0d6@xs4all.nl>

Hi Hans,

On Tue, Oct 10, 2017 at 03:18:13PM +0200, Hans Verkuil wrote:
> On 10/10/2017 02:57 PM, Sakari Ailus wrote:
> > Hi Hans,
> > 
> > On Mon, Oct 09, 2017 at 01:45:25PM +0200, Hans Verkuil wrote:
> >> On 04/10/17 23:50, Sakari Ailus wrote:
> >>> The notifier complete callback may return an error. This error code was
> >>> simply returned to the caller but never handled properly.
> >>>
> >>> Move calling the complete callback function to the caller from
> >>> v4l2_async_test_notify and undo the work that was done either in async
> >>> sub-device or async notifier registration.
> >>>
> >>> Reported-by: Russell King <rmk+kernel@armlinux.org.uk>
> >>> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> >>> ---
> >>>  drivers/media/v4l2-core/v4l2-async.c | 78 +++++++++++++++++++++++++++---------
> >>>  1 file changed, 60 insertions(+), 18 deletions(-)
> >>>
> >>> diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
> >>> index ca281438a0ae..4924481451ca 100644
> >>> --- a/drivers/media/v4l2-core/v4l2-async.c
> >>> +++ b/drivers/media/v4l2-core/v4l2-async.c
> >>> @@ -122,9 +122,6 @@ static int v4l2_async_test_notify(struct v4l2_async_notifier *notifier,
> >>>  	/* Move from the global subdevice list to notifier's done */
> >>>  	list_move(&sd->async_list, &notifier->done);
> >>>  
> >>> -	if (list_empty(&notifier->waiting) && notifier->complete)
> >>> -		return notifier->complete(notifier);
> >>> -
> >>>  	return 0;
> >>>  }
> >>>  
> >>> @@ -136,11 +133,27 @@ static void v4l2_async_cleanup(struct v4l2_subdev *sd)
> >>>  	sd->asd = NULL;
> >>>  }
> >>>  
> >>> +static void v4l2_async_notifier_unbind_all_subdevs(
> >>> +	struct v4l2_async_notifier *notifier)
> >>> +{
> >>> +	struct v4l2_subdev *sd, *tmp;
> >>> +
> >>> +	list_for_each_entry_safe(sd, tmp, &notifier->done, async_list) {
> >>> +		if (notifier->unbind)
> >>> +			notifier->unbind(notifier, sd, sd->asd);
> >>> +
> >>> +		v4l2_async_cleanup(sd);
> >>> +
> >>> +		list_move(&sd->async_list, &subdev_list);
> >>> +	}
> >>> +}
> >>> +
> >>>  int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
> >>>  				 struct v4l2_async_notifier *notifier)
> >>>  {
> >>>  	struct v4l2_subdev *sd, *tmp;
> >>>  	struct v4l2_async_subdev *asd;
> >>> +	int ret;
> >>>  	int i;
> >>>  
> >>>  	if (!v4l2_dev || !notifier->num_subdevs ||
> >>> @@ -185,19 +198,30 @@ int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
> >>>  		}
> >>>  	}
> >>>  
> >>> +	if (list_empty(&notifier->waiting) && notifier->complete) {
> >>> +		ret = notifier->complete(notifier);
> >>> +		if (ret)
> >>> +			goto err_complete;
> >>> +	}
> >>> +
> >>>  	/* Keep also completed notifiers on the list */
> >>>  	list_add(&notifier->list, &notifier_list);
> >>>  
> >>>  	mutex_unlock(&list_lock);
> >>>  
> >>>  	return 0;
> >>> +
> >>> +err_complete:
> >>> +	v4l2_async_notifier_unbind_all_subdevs(notifier);
> >>> +
> >>> +	mutex_unlock(&list_lock);
> >>> +
> >>> +	return ret;
> >>>  }
> >>>  EXPORT_SYMBOL(v4l2_async_notifier_register);
> >>>  
> >>>  void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier)
> >>>  {
> >>> -	struct v4l2_subdev *sd, *tmp;
> >>> -
> >>>  	if (!notifier->v4l2_dev)
> >>>  		return;
> >>>  
> >>> @@ -205,14 +229,7 @@ void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier)
> >>>  
> >>>  	list_del(&notifier->list);
> >>>  
> >>> -	list_for_each_entry_safe(sd, tmp, &notifier->done, async_list) {
> >>> -		if (notifier->unbind)
> >>> -			notifier->unbind(notifier, sd, sd->asd);
> >>> -
> >>> -		v4l2_async_cleanup(sd);
> >>> -
> >>> -		list_move(&sd->async_list, &subdev_list);
> >>> -	}
> >>> +	v4l2_async_notifier_unbind_all_subdevs(notifier);
> >>>  
> >>>  	mutex_unlock(&list_lock);
> >>>  
> >>> @@ -223,6 +240,7 @@ EXPORT_SYMBOL(v4l2_async_notifier_unregister);
> >>>  int v4l2_async_register_subdev(struct v4l2_subdev *sd)
> >>>  {
> >>>  	struct v4l2_async_notifier *notifier;
> >>> +	int ret;
> >>>  
> >>>  	/*
> >>>  	 * No reference taken. The reference is held by the device
> >>> @@ -238,19 +256,43 @@ int v4l2_async_register_subdev(struct v4l2_subdev *sd)
> >>>  
> >>>  	list_for_each_entry(notifier, &notifier_list, list) {
> >>>  		struct v4l2_async_subdev *asd = v4l2_async_belongs(notifier, sd);
> >>> -		if (asd) {
> >>> -			int ret = v4l2_async_test_notify(notifier, sd, asd);
> >>> -			mutex_unlock(&list_lock);
> >>> -			return ret;
> >>> -		}
> >>> +		int ret;
> >>> +
> >>> +		if (!asd)
> >>> +			continue;
> >>> +
> >>> +		ret = v4l2_async_test_notify(notifier, sd, asd);
> >>> +		if (ret)
> >>> +			goto err_unlock;
> >>> +
> >>> +		if (!list_empty(&notifier->waiting) || !notifier->complete)
> >>> +			goto out_unlock;
> >>> +
> >>> +		ret = notifier->complete(notifier);
> >>> +		if (ret)
> >>> +			goto err_cleanup;
> >>> +
> >>> +		goto out_unlock;
> >>>  	}
> >>>  
> >>>  	/* None matched, wait for hot-plugging */
> >>>  	list_add(&sd->async_list, &subdev_list);
> >>>  
> >>> +out_unlock:
> >>>  	mutex_unlock(&list_lock);
> >>>  
> >>>  	return 0;
> >>> +
> >>> +err_cleanup:
> >>> +	if (notifier->unbind)
> >>> +		notifier->unbind(notifier, sd, sd->asd);
> >>> +
> >>> +	v4l2_async_cleanup(sd);
> >>
> >> I'm trying to understand this. Who will unbind all subdevs in this case?
> > 
> > The driver that registered them is responsible for that, as usual.
> > 
> >>
> >> And in the general case: if complete returns an error, the bridge driver
> >> should be remove()d. Who will do that? Does that work at all?
> > 
> > The bridge driver can't do that alone, the bridge driver would need to be
> > unbound explicitly by the user.
> > 
> > This approach has the benefit that it's symmetric: on error we only tear
> > down the part that was added, no more. Doing otherwise would likely make
> > the error handling hard to understand and test properly. For instance, if a
> > driver's probe function calling v4l2_async_register_subdev() or
> > v4l2_async_notifier_register() fails, leading the driver binding to fail.
> > If the error is temporary for whatever reason, just retrying the operation
> > will help.
> > 
> 
> So to be clear: if complete() returns an error, then you basically end up with
> a 'zombie' device: it's been successfully probed, but because complete() failed
> it will just sit there until the user unbinds it (typically via rmmod).

Either that, or the complete callback is called again by re-probing the
sub-device driver (which failed as v4l2_async_register_subdev() failed).

> 
> For the record: this will only happen if the subdev is loaded after the main
> driver. If the subdev is loaded before the main driver, then when the main driver
> calls v4l2_async_notifier_register() from the probe() function it will return an
> error and the probe will fail with an error.

Correct.

In the long run it'd be good to get rid of the complete callback entirely
or make its return value void. I think that's still a separate matter
though.

Speaking of complete callbacks --- I don't think we have a use case for
calling them from the sub-device notifiers. I'll disable them in v16 for
that reason: we don't want to embrace their use, especially without a valid
reason.

-- 
Regards,

Sakari Ailus
sakari.ailus@linux.intel.com

  reply	other threads:[~2017-10-10 14:21 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-04 21:50 [PATCH v15 00/32] Unified fwnode endpoint parser, async sub-device notifier support, N9 flash DTS Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 01/32] v4l: async: Remove re-probing support Sakari Ailus
2017-10-08 21:50   ` Sebastian Reichel
2017-10-09 11:22   ` Mauro Carvalho Chehab
2017-10-09 14:06     ` Sakari Ailus
2017-10-09 14:08       ` Hans Verkuil
2017-10-09 14:18         ` Sakari Ailus
2017-10-09 14:20           ` Hans Verkuil
2017-10-09 15:27             ` Mauro Carvalho Chehab
     [not found]           ` <CGME20171009164457epcas1p3c5e134e4bb5d85498fe8d4f00332f2fc@epcas1p3.samsung.com>
2017-10-09 16:44             ` Sylwester Nawrocki
2017-10-09 19:18               ` Laurent Pinchart
2017-10-10 12:18               ` Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 02/32] v4l: async: Don't set sd->dev NULL in v4l2_async_cleanup Sakari Ailus
2017-10-08 21:50   ` Sebastian Reichel
2017-10-09 11:21   ` Hans Verkuil
2017-10-04 21:50 ` [PATCH v15 03/32] v4l: async: fix unbind error in v4l2_async_notifier_unregister() Sakari Ailus
2017-10-08 21:50   ` Sebastian Reichel
2017-10-09 11:23   ` Hans Verkuil
2017-10-04 21:50 ` [PATCH v15 04/32] v4l: async: Fix notifier complete callback error handling Sakari Ailus
2017-10-09 11:45   ` Hans Verkuil
2017-10-10 12:57     ` Sakari Ailus
2017-10-10 13:18       ` Hans Verkuil
2017-10-10 14:21         ` Sakari Ailus [this message]
2017-10-04 21:50 ` [PATCH v15 05/32] v4l: async: Correctly serialise async sub-device unregistration Sakari Ailus
2017-10-08 21:52   ` Sebastian Reichel
2017-10-09 11:45   ` Hans Verkuil
2017-10-04 21:50 ` [PATCH v15 06/32] v4l: async: Use more intuitive names for internal functions Sakari Ailus
2017-10-08 21:53   ` Sebastian Reichel
2017-10-04 21:50 ` [PATCH v15 07/32] v4l: async: Add V4L2 async documentation to the documentation build Sakari Ailus
2017-10-08 21:54   ` Sebastian Reichel
2017-10-09 11:31   ` Mauro Carvalho Chehab
2017-10-04 21:50 ` [PATCH v15 08/32] v4l: fwnode: Support generic parsing of graph endpoints in a device Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 09/32] omap3isp: Use generic parser for parsing fwnode endpoints Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 10/32] rcar-vin: " Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 11/32] omap3isp: Fix check for our own sub-devices Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 12/32] omap3isp: Print the name of the entity where no source pads could be found Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 13/32] v4l: async: Move async subdev notifier operations to a separate structure Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 14/32] v4l: async: Introduce helpers for calling async ops callbacks Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 15/32] v4l: async: Register sub-devices before calling bound callback Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 16/32] v4l: async: Allow async notifier register call succeed with no subdevs Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 17/32] v4l: async: Prepare for async sub-device notifiers Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 18/32] v4l: async: Allow binding notifiers to sub-devices Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 19/32] v4l: async: Ensure only unique fwnodes are registered to notifiers Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 20/32] dt: bindings: Add a binding for flash LED devices associated to a sensor Sakari Ailus
     [not found]   ` <20171004215051.13385-21-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-10-13 13:41     ` Rob Herring
2017-10-13 13:41       ` Rob Herring
2017-10-04 21:50 ` [PATCH v15 21/32] dt: bindings: Add lens-focus binding for image sensors Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 22/32] v4l: fwnode: Move KernelDoc documentation to the header Sakari Ailus
2017-10-05 12:03   ` [PATCH v15.1 " Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 23/32] v4l: fwnode: Add a helper function for parsing generic references Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 24/32] v4l: fwnode: Add a helper function to obtain device / integer references Sakari Ailus
2017-10-18 13:56   ` [PATCH v15.1 " Sakari Ailus
2017-10-18 15:32     ` Sakari Ailus
2017-10-19  6:52       ` Hans Verkuil
2017-10-20 11:35         ` Sakari Ailus
2017-10-24 20:32         ` [PATCH v15.2 " Sakari Ailus
2017-10-24 20:36           ` Sakari Ailus
2017-10-25  7:28           ` Hans Verkuil
2017-10-04 21:50 ` [PATCH v15 25/32] v4l: fwnode: Add convenience function for parsing common external refs Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 26/32] v4l: fwnode: Add a convenience function for registering sensors Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 27/32] dt: bindings: smiapp: Document lens-focus and flash-leds properties Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 28/32] smiapp: Add support for flash and lens devices Sakari Ailus
2017-10-06 11:21   ` Pavel Machek
2017-10-04 21:50 ` [PATCH v15 29/32] et8ek8: " Sakari Ailus
2017-10-06 11:21   ` Pavel Machek
2017-10-04 21:50 ` [PATCH v15 30/32] ov5670: " Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 31/32] ov13858: " Sakari Ailus
2017-10-04 21:50 ` [PATCH v15 32/32] arm: dts: omap3: N9/N950: Add flash references to the camera Sakari Ailus
2017-10-05  6:11 ` [PATCH v15 00/32] Unified fwnode endpoint parser, async sub-device notifier support, N9 flash DTS Sakari Ailus

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=20171010142101.u2tip7kch4dwuvih@paasikivi.fi.intel.com \
    --to=sakari.ailus@linux.intel.com \
    --cc=hverkuil@xs4all.nl \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=maxime.ripard@free-electrons.com \
    --cc=niklas.soderlund@ragnatech.se \
    --cc=pavel@ucw.cz \
    --cc=sakari.ailus@iki.fi \
    --cc=sre@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.