linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] V4L2 async fixes
@ 2024-03-11 12:17 Sakari Ailus
  2024-03-11 12:17 ` [PATCH 1/2] media: v4l: async: Don't set notifier's V4L2 device if registering fails Sakari Ailus
  2024-03-11 12:17 ` [PATCH 2/2] media: v4l: async: Properly check for a notifier initialised or registered Sakari Ailus
  0 siblings, 2 replies; 6+ messages in thread
From: Sakari Ailus @ 2024-03-11 12:17 UTC (permalink / raw)
  To: linux-media; +Cc: jacopo.mondi, Alexander Stein

Hi folks,

This set fixes a few issues in V4L2 async regarding error paths and uneven
calls to teardown functions. I ended up taking a fresh look at the code
after Alexander posted his patch (message id
20240307142452.3685103-1-alexander.stein@ew.tq-group.com).

Sakari Ailus (2):
  media: v4l: async: Don't set notifier's V4L2 device if registering
    fails
  media: v4l: async: Properly check for a notifier initialised or
    registered

 drivers/media/v4l2-core/v4l2-async.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

-- 
2.39.2


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

* [PATCH 1/2] media: v4l: async: Don't set notifier's V4L2 device if registering fails
  2024-03-11 12:17 [PATCH 0/2] V4L2 async fixes Sakari Ailus
@ 2024-03-11 12:17 ` Sakari Ailus
  2024-03-11 12:17 ` [PATCH 2/2] media: v4l: async: Properly check for a notifier initialised or registered Sakari Ailus
  1 sibling, 0 replies; 6+ messages in thread
From: Sakari Ailus @ 2024-03-11 12:17 UTC (permalink / raw)
  To: linux-media; +Cc: jacopo.mondi, Alexander Stein

The V4L2 device used to be set when the notifier was registered but this
has been moved to the notifier initialisation. Don't touch the V4L2 device
if registration fails.

Fixes: b8ec754ae4c5 ("media: v4l: async: Set v4l2_device and subdev in async notifier init")
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-async.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
index 6a7dcf43d712..2ff35d5d60f2 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -620,16 +620,10 @@ static int __v4l2_async_nf_register(struct v4l2_async_notifier *notifier)
 
 int v4l2_async_nf_register(struct v4l2_async_notifier *notifier)
 {
-	int ret;
-
 	if (WARN_ON(!notifier->v4l2_dev == !notifier->sd))
 		return -EINVAL;
 
-	ret = __v4l2_async_nf_register(notifier);
-	if (ret)
-		notifier->v4l2_dev = NULL;
-
-	return ret;
+	return __v4l2_async_nf_register(notifier);
 }
 EXPORT_SYMBOL(v4l2_async_nf_register);
 
-- 
2.39.2


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

* [PATCH 2/2] media: v4l: async: Properly check for a notifier initialised or registered
  2024-03-11 12:17 [PATCH 0/2] V4L2 async fixes Sakari Ailus
  2024-03-11 12:17 ` [PATCH 1/2] media: v4l: async: Don't set notifier's V4L2 device if registering fails Sakari Ailus
@ 2024-03-11 12:17 ` Sakari Ailus
  2024-03-14 14:04   ` Alexander Stein
  1 sibling, 1 reply; 6+ messages in thread
From: Sakari Ailus @ 2024-03-11 12:17 UTC (permalink / raw)
  To: linux-media; +Cc: jacopo.mondi, Alexander Stein

Properly check that a notifier was never initialised or register. This can
now be done by looking at the entry in the notifier list, not the V4L2
device or sub-device that are set in the initialiser now.

Fixes: b8ec754ae4c5 ("media: v4l: async: Set v4l2_device and subdev in async notifier init")
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-async.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
index 2ff35d5d60f2..3b43d6285dfe 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -630,12 +630,14 @@ EXPORT_SYMBOL(v4l2_async_nf_register);
 static void
 __v4l2_async_nf_unregister(struct v4l2_async_notifier *notifier)
 {
-	if (!notifier || (!notifier->v4l2_dev && !notifier->sd))
+	/* Return here if the notifier is never initialised or registered. */
+	if (!notifier->notifier_entry.next ||
+	    list_empty(&notifier->notifier_entry))
 		return;
 
 	v4l2_async_nf_unbind_all_subdevs(notifier);
 
-	list_del(&notifier->notifier_entry);
+	list_del_init(&notifier->notifier_entry);
 }
 
 void v4l2_async_nf_unregister(struct v4l2_async_notifier *notifier)
-- 
2.39.2


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

* Re: [PATCH 2/2] media: v4l: async: Properly check for a notifier initialised or registered
  2024-03-11 12:17 ` [PATCH 2/2] media: v4l: async: Properly check for a notifier initialised or registered Sakari Ailus
@ 2024-03-14 14:04   ` Alexander Stein
  2024-03-20  7:07     ` Sakari Ailus
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander Stein @ 2024-03-14 14:04 UTC (permalink / raw)
  To: linux-media, Sakari Ailus; +Cc: jacopo.mondi

Hi Sakari,

I suppose on of your intentions of this series is to replace my patch, no?

Am Montag, 11. März 2024, 13:17:41 CET schrieb Sakari Ailus:
> Properly check that a notifier was never initialised or register. This can
> now be done by looking at the entry in the notifier list, not the V4L2
> device or sub-device that are set in the initialiser now.
> 
> Fixes: b8ec754ae4c5 ("media: v4l: async: Set v4l2_device and subdev in async notifier init")
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
>  drivers/media/v4l2-core/v4l2-async.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
> index 2ff35d5d60f2..3b43d6285dfe 100644
> --- a/drivers/media/v4l2-core/v4l2-async.c
> +++ b/drivers/media/v4l2-core/v4l2-async.c
> @@ -630,12 +630,14 @@ EXPORT_SYMBOL(v4l2_async_nf_register);
>  static void
>  __v4l2_async_nf_unregister(struct v4l2_async_notifier *notifier)
>  {
> -	if (!notifier || (!notifier->v4l2_dev && !notifier->sd))
> +	/* Return here if the notifier is never initialised or registered. */
> +	if (!notifier->notifier_entry.next ||

I don't like the idea checking the next pointer of a list.
Despite that it's not even necessary.

Best regards,
Alexander

> +	    list_empty(&notifier->notifier_entry))
>  		return;
>  
>  	v4l2_async_nf_unbind_all_subdevs(notifier);
>  
> -	list_del(&notifier->notifier_entry);
> +	list_del_init(&notifier->notifier_entry);
>  }
>  
>  void v4l2_async_nf_unregister(struct v4l2_async_notifier *notifier)
> 


-- 
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
http://www.tq-group.com/




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

* Re: [PATCH 2/2] media: v4l: async: Properly check for a notifier initialised or registered
  2024-03-14 14:04   ` Alexander Stein
@ 2024-03-20  7:07     ` Sakari Ailus
  2024-03-21  8:28       ` Alexander Stein
  0 siblings, 1 reply; 6+ messages in thread
From: Sakari Ailus @ 2024-03-20  7:07 UTC (permalink / raw)
  To: Alexander Stein; +Cc: linux-media, jacopo.mondi

Hi Alexander,

On Thu, Mar 14, 2024 at 03:04:44PM +0100, Alexander Stein wrote:
> Hi Sakari,
> 
> I suppose on of your intentions of this series is to replace my patch, no?

No, these are somewhat unrelated issues.

> 
> Am Montag, 11. März 2024, 13:17:41 CET schrieb Sakari Ailus:
> > Properly check that a notifier was never initialised or register. This can
> > now be done by looking at the entry in the notifier list, not the V4L2
> > device or sub-device that are set in the initialiser now.
> > 
> > Fixes: b8ec754ae4c5 ("media: v4l: async: Set v4l2_device and subdev in async notifier init")
> > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> > ---
> >  drivers/media/v4l2-core/v4l2-async.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
> > index 2ff35d5d60f2..3b43d6285dfe 100644
> > --- a/drivers/media/v4l2-core/v4l2-async.c
> > +++ b/drivers/media/v4l2-core/v4l2-async.c
> > @@ -630,12 +630,14 @@ EXPORT_SYMBOL(v4l2_async_nf_register);
> >  static void
> >  __v4l2_async_nf_unregister(struct v4l2_async_notifier *notifier)
> >  {
> > -	if (!notifier || (!notifier->v4l2_dev && !notifier->sd))
> > +	/* Return here if the notifier is never initialised or registered. */
> > +	if (!notifier->notifier_entry.next ||
> 
> I don't like the idea checking the next pointer of a list.
> Despite that it's not even necessary.

Actually I think we can drop the above change. But the list_del_init()
below is still necessary.

> 
> Best regards,
> Alexander
> 
> > +	    list_empty(&notifier->notifier_entry))
> >  		return;
> >  
> >  	v4l2_async_nf_unbind_all_subdevs(notifier);
> >  
> > -	list_del(&notifier->notifier_entry);
> > +	list_del_init(&notifier->notifier_entry);
> >  }
> >  
> >  void v4l2_async_nf_unregister(struct v4l2_async_notifier *notifier)
> > 
> 
> 

-- 
Regards,

Sakari Ailus

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

* Re: [PATCH 2/2] media: v4l: async: Properly check for a notifier initialised or registered
  2024-03-20  7:07     ` Sakari Ailus
@ 2024-03-21  8:28       ` Alexander Stein
  0 siblings, 0 replies; 6+ messages in thread
From: Alexander Stein @ 2024-03-21  8:28 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: linux-media, jacopo.mondi

Hi Sakari,

Am Mittwoch, 20. März 2024, 08:07:51 CET schrieb Sakari Ailus:
> Hi Alexander,
> 
> On Thu, Mar 14, 2024 at 03:04:44PM +0100, Alexander Stein wrote:
> > Hi Sakari,
> > 
> > I suppose on of your intentions of this series is to replace my patch, no?
> 
> No, these are somewhat unrelated issues.

Okay, thanks for confirmation.

> > 
> > Am Montag, 11. März 2024, 13:17:41 CET schrieb Sakari Ailus:
> > > Properly check that a notifier was never initialised or register. This can
> > > now be done by looking at the entry in the notifier list, not the V4L2
> > > device or sub-device that are set in the initialiser now.
> > > 
> > > Fixes: b8ec754ae4c5 ("media: v4l: async: Set v4l2_device and subdev in async notifier init")
> > > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> > > ---
> > >  drivers/media/v4l2-core/v4l2-async.c | 6 ++++--
> > >  1 file changed, 4 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
> > > index 2ff35d5d60f2..3b43d6285dfe 100644
> > > --- a/drivers/media/v4l2-core/v4l2-async.c
> > > +++ b/drivers/media/v4l2-core/v4l2-async.c
> > > @@ -630,12 +630,14 @@ EXPORT_SYMBOL(v4l2_async_nf_register);
> > >  static void
> > >  __v4l2_async_nf_unregister(struct v4l2_async_notifier *notifier)
> > >  {
> > > -	if (!notifier || (!notifier->v4l2_dev && !notifier->sd))
> > > +	/* Return here if the notifier is never initialised or registered. */
> > > +	if (!notifier->notifier_entry.next ||
> > 
> > I don't like the idea checking the next pointer of a list.
> > Despite that it's not even necessary.
> 
> Actually I think we can drop the above change. But the list_del_init()
> below is still necessary.

I agree about the list_del_init() change.

Best regards,
Alexander

> > 
> > Best regards,
> > Alexander
> > 
> > > +	    list_empty(&notifier->notifier_entry))
> > >  		return;
> > >  
> > >  	v4l2_async_nf_unbind_all_subdevs(notifier);
> > >  
> > > -	list_del(&notifier->notifier_entry);
> > > +	list_del_init(&notifier->notifier_entry);
> > >  }
> > >  
> > >  void v4l2_async_nf_unregister(struct v4l2_async_notifier *notifier)
> > > 
> > 
> > 
> 
> 


-- 
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
http://www.tq-group.com/



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

end of thread, other threads:[~2024-03-21  8:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-11 12:17 [PATCH 0/2] V4L2 async fixes Sakari Ailus
2024-03-11 12:17 ` [PATCH 1/2] media: v4l: async: Don't set notifier's V4L2 device if registering fails Sakari Ailus
2024-03-11 12:17 ` [PATCH 2/2] media: v4l: async: Properly check for a notifier initialised or registered Sakari Ailus
2024-03-14 14:04   ` Alexander Stein
2024-03-20  7:07     ` Sakari Ailus
2024-03-21  8:28       ` Alexander Stein

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).