V4L2: fix subdevice matching in asynchronous probing

Message ID Pine.LNX.4.64.1304191640010.591@axis700.grange (mailing list archive)
State Superseded, archived
Delegated to: Guennadi Liakhovetski
Headers

Commit Message

Guennadi Liakhovetski April 19, 2013, 2:41 p.m. UTC
  A wrapped list iterating loop hasn't been correctly recognised in
v4l2_async_belongs(), which led to false positives. Fix the bug by
verifying the loop termination condition.

Reported-by: Prabhakar Lad <prabhakar.csengg@gmail.com>
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
---

Prabhakar, please, check, whether this fixes your problem.

 drivers/media/v4l2-core/v4l2-async.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
  

Comments

Laurent Pinchart April 22, 2013, 10:34 a.m. UTC | #1
Hi Guennadi,

On Friday 19 April 2013 16:41:02 Guennadi Liakhovetski wrote:
> A wrapped list iterating loop hasn't been correctly recognised in
> v4l2_async_belongs(), which led to false positives. Fix the bug by
> verifying the loop termination condition.
> 
> Reported-by: Prabhakar Lad <prabhakar.csengg@gmail.com>
> Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
> ---
> 
> Prabhakar, please, check, whether this fixes your problem.
> 
>  drivers/media/v4l2-core/v4l2-async.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-async.c
> b/drivers/media/v4l2-core/v4l2-async.c index 5d6b428..5631944 100644
> --- a/drivers/media/v4l2-core/v4l2-async.c
> +++ b/drivers/media/v4l2-core/v4l2-async.c
> @@ -76,6 +76,10 @@ static struct v4l2_async_subdev
> *v4l2_async_belongs(struct v4l2_async_notifier *
> 			break;
>  	}
> 
> +	if (&asd->list == &notifier->waiting)
> +		/* Wrapped - no match found */
> +		return NULL;
> +
>  	return asd;
>  }

What about just

                if (match && match(sd->dev, hw))
                        return asd;
        }

        return NULL;
}

That's a bit simpler.
  
Guennadi Liakhovetski April 22, 2013, 10:43 a.m. UTC | #2
On Mon, 22 Apr 2013, Laurent Pinchart wrote:

> Hi Guennadi,
> 
> On Friday 19 April 2013 16:41:02 Guennadi Liakhovetski wrote:
> > A wrapped list iterating loop hasn't been correctly recognised in
> > v4l2_async_belongs(), which led to false positives. Fix the bug by
> > verifying the loop termination condition.
> > 
> > Reported-by: Prabhakar Lad <prabhakar.csengg@gmail.com>
> > Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
> > ---
> > 
> > Prabhakar, please, check, whether this fixes your problem.
> > 
> >  drivers/media/v4l2-core/v4l2-async.c |    4 ++++
> >  1 files changed, 4 insertions(+), 0 deletions(-)
> > 
> > diff --git a/drivers/media/v4l2-core/v4l2-async.c
> > b/drivers/media/v4l2-core/v4l2-async.c index 5d6b428..5631944 100644
> > --- a/drivers/media/v4l2-core/v4l2-async.c
> > +++ b/drivers/media/v4l2-core/v4l2-async.c
> > @@ -76,6 +76,10 @@ static struct v4l2_async_subdev
> > *v4l2_async_belongs(struct v4l2_async_notifier *
> > 			break;
> >  	}
> > 
> > +	if (&asd->list == &notifier->waiting)
> > +		/* Wrapped - no match found */
> > +		return NULL;
> > +
> >  	return asd;
> >  }
> 
> What about just
> 
>                 if (match && match(sd->dev, hw))
>                         return asd;
>         }
> 
>         return NULL;
> }
> 
> That's a bit simpler.

Well, if it were simpler, it would've occurred to me instead of the other 
"more complex" solution, tight? ;-) No, sure, looks better, thanks! As 
soon as the actual patches are approved in principle, I'll merge this into 
them.

Regards
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
  

Patch

diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
index 5d6b428..5631944 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -76,6 +76,10 @@  static struct v4l2_async_subdev *v4l2_async_belongs(struct v4l2_async_notifier *
 			break;
 	}
 
+	if (&asd->list == &notifier->waiting)
+		/* Wrapped - no match found */
+		return NULL;
+
 	return asd;
 }