All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] [media] v4l2-async: Always unregister the subdev on failure
@ 2016-08-24 13:49 Alban Bedel
  2016-09-05 13:06 ` Hans Verkuil
  0 siblings, 1 reply; 2+ messages in thread
From: Alban Bedel @ 2016-08-24 13:49 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Javier Martinez Canillas, Sakari Ailus,
	linux-kernel, Alban Bedel

In v4l2_async_test_notify() if the registered_async callback or the
complete notifier returns an error the subdev is not unregistered.
This leave paths where v4l2_async_register_subdev() can fail but
leave the subdev still registered.

Add the required calls to v4l2_device_unregister_subdev() to plug
these holes.

Signed-off-by: Alban Bedel <alban.bedel@avionic-design.de>
---
Changelog:
v2: * Added the missing unbind() calls as suggested by Javier.
---
 drivers/media/v4l2-core/v4l2-async.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
index ceb28d47c3f9..abe512d0b4cb 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -113,23 +113,28 @@ static int v4l2_async_test_notify(struct v4l2_async_notifier *notifier,
 	list_move(&sd->async_list, &notifier->done);
 
 	ret = v4l2_device_register_subdev(notifier->v4l2_dev, sd);
-	if (ret < 0) {
-		if (notifier->unbind)
-			notifier->unbind(notifier, sd, asd);
-		return ret;
-	}
+	if (ret < 0)
+		goto err_subdev_register;
 
 	ret = v4l2_subdev_call(sd, core, registered_async);
-	if (ret < 0 && ret != -ENOIOCTLCMD) {
-		if (notifier->unbind)
-			notifier->unbind(notifier, sd, asd);
-		return ret;
+	if (ret < 0 && ret != -ENOIOCTLCMD)
+		goto err_subdev_call;
+
+	if (list_empty(&notifier->waiting) && notifier->complete) {
+		ret = notifier->complete(notifier);
+		if (ret < 0)
+			goto err_subdev_call;
 	}
 
-	if (list_empty(&notifier->waiting) && notifier->complete)
-		return notifier->complete(notifier);
-
 	return 0;
+
+err_subdev_call:
+	v4l2_device_unregister_subdev(sd);
+err_subdev_register:
+	if (notifier->unbind)
+		notifier->unbind(notifier, sd, asd);
+
+	return ret;
 }
 
 static void v4l2_async_cleanup(struct v4l2_subdev *sd)
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] [media] v4l2-async: Always unregister the subdev on failure
  2016-08-24 13:49 [PATCH v2] [media] v4l2-async: Always unregister the subdev on failure Alban Bedel
@ 2016-09-05 13:06 ` Hans Verkuil
  0 siblings, 0 replies; 2+ messages in thread
From: Hans Verkuil @ 2016-09-05 13:06 UTC (permalink / raw)
  To: Alban Bedel, linux-media
  Cc: Mauro Carvalho Chehab, Javier Martinez Canillas, Sakari Ailus,
	linux-kernel

Hi Alban,

On 08/24/2016 03:49 PM, Alban Bedel wrote:
> In v4l2_async_test_notify() if the registered_async callback or the
> complete notifier returns an error the subdev is not unregistered.
> This leave paths where v4l2_async_register_subdev() can fail but
> leave the subdev still registered.
> 
> Add the required calls to v4l2_device_unregister_subdev() to plug
> these holes.

This patch no longer applies after another patch from Javier was merged.

Can you rebase and post a v3?

Thanks!

	Hans

> 
> Signed-off-by: Alban Bedel <alban.bedel@avionic-design.de>
> ---
> Changelog:
> v2: * Added the missing unbind() calls as suggested by Javier.
> ---
>  drivers/media/v4l2-core/v4l2-async.c | 29 +++++++++++++++++------------
>  1 file changed, 17 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
> index ceb28d47c3f9..abe512d0b4cb 100644
> --- a/drivers/media/v4l2-core/v4l2-async.c
> +++ b/drivers/media/v4l2-core/v4l2-async.c
> @@ -113,23 +113,28 @@ static int v4l2_async_test_notify(struct v4l2_async_notifier *notifier,
>  	list_move(&sd->async_list, &notifier->done);
>  
>  	ret = v4l2_device_register_subdev(notifier->v4l2_dev, sd);
> -	if (ret < 0) {
> -		if (notifier->unbind)
> -			notifier->unbind(notifier, sd, asd);
> -		return ret;
> -	}
> +	if (ret < 0)
> +		goto err_subdev_register;
>  
>  	ret = v4l2_subdev_call(sd, core, registered_async);
> -	if (ret < 0 && ret != -ENOIOCTLCMD) {
> -		if (notifier->unbind)
> -			notifier->unbind(notifier, sd, asd);
> -		return ret;
> +	if (ret < 0 && ret != -ENOIOCTLCMD)
> +		goto err_subdev_call;
> +
> +	if (list_empty(&notifier->waiting) && notifier->complete) {
> +		ret = notifier->complete(notifier);
> +		if (ret < 0)
> +			goto err_subdev_call;
>  	}
>  
> -	if (list_empty(&notifier->waiting) && notifier->complete)
> -		return notifier->complete(notifier);
> -
>  	return 0;
> +
> +err_subdev_call:
> +	v4l2_device_unregister_subdev(sd);
> +err_subdev_register:
> +	if (notifier->unbind)
> +		notifier->unbind(notifier, sd, asd);
> +
> +	return ret;
>  }
>  
>  static void v4l2_async_cleanup(struct v4l2_subdev *sd)
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-09-05 13:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-24 13:49 [PATCH v2] [media] v4l2-async: Always unregister the subdev on failure Alban Bedel
2016-09-05 13:06 ` Hans Verkuil

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.