linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 for v4.4 1/1] v4l: event: Add subscription to list before calling "add" operation
@ 2018-11-14  9:37 Sakari Ailus
  2018-11-19 15:14 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 9+ messages in thread
From: Sakari Ailus @ 2018-11-14  9:37 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Dave Stevenson, Hans Verkuil, mchehab, linux-media, Sasha Levin

[ upstream commit 92539d3eda2c090b382699bbb896d4b54e9bdece ]

Patch ad608fbcf166 changed how events were subscribed to address an issue
elsewhere. As a side effect of that change, the "add" callback was called
before the event subscription was added to the list of subscribed events,
causing the first event queued by the add callback (and possibly other
events arriving soon afterwards) to be lost.

Fix this by adding the subscription to the list before calling the "add"
callback, and clean up afterwards if that fails.

Fixes: ad608fbcf166 ("media: v4l: event: Prevent freeing event subscriptions while accessed")

Reported-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Tested-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
Reviewed-by: Hans Verkuil <hans.verkuil@cisco.com>
Tested-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
[Sakari Ailus: Backported to v4.4 stable]
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
since v1 (as requested by Sasha):

- Add my final SoB
- Indicate specifically this is a backport
- Remove the extra cc stable

 drivers/media/v4l2-core/v4l2-event.c | 43 ++++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-event.c b/drivers/media/v4l2-core/v4l2-event.c
index b47ac4e053d0e..f5c8a952f0aa3 100644
--- a/drivers/media/v4l2-core/v4l2-event.c
+++ b/drivers/media/v4l2-core/v4l2-event.c
@@ -197,6 +197,22 @@ int v4l2_event_pending(struct v4l2_fh *fh)
 }
 EXPORT_SYMBOL_GPL(v4l2_event_pending);
 
+static void __v4l2_event_unsubscribe(struct v4l2_subscribed_event *sev)
+{
+	struct v4l2_fh *fh = sev->fh;
+	unsigned int i;
+
+	lockdep_assert_held(&fh->subscribe_lock);
+	assert_spin_locked(&fh->vdev->fh_lock);
+
+	/* Remove any pending events for this subscription */
+	for (i = 0; i < sev->in_use; i++) {
+		list_del(&sev->events[sev_pos(sev, i)].list);
+		fh->navailable--;
+	}
+	list_del(&sev->list);
+}
+
 int v4l2_event_subscribe(struct v4l2_fh *fh,
 			 const struct v4l2_event_subscription *sub, unsigned elems,
 			 const struct v4l2_subscribed_event_ops *ops)
@@ -228,27 +244,23 @@ int v4l2_event_subscribe(struct v4l2_fh *fh,
 
 	spin_lock_irqsave(&fh->vdev->fh_lock, flags);
 	found_ev = v4l2_event_subscribed(fh, sub->type, sub->id);
+	if (!found_ev)
+		list_add(&sev->list, &fh->subscribed);
 	spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
 
 	if (found_ev) {
 		/* Already listening */
 		kfree(sev);
-		goto out_unlock;
-	}
-
-	if (sev->ops && sev->ops->add) {
+	} else if (sev->ops && sev->ops->add) {
 		ret = sev->ops->add(sev, elems);
 		if (ret) {
+			spin_lock_irqsave(&fh->vdev->fh_lock, flags);
+			__v4l2_event_unsubscribe(sev);
+			spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
 			kfree(sev);
-			goto out_unlock;
 		}
 	}
 
-	spin_lock_irqsave(&fh->vdev->fh_lock, flags);
-	list_add(&sev->list, &fh->subscribed);
-	spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
-
-out_unlock:
 	mutex_unlock(&fh->subscribe_lock);
 
 	return ret;
@@ -283,7 +295,6 @@ int v4l2_event_unsubscribe(struct v4l2_fh *fh,
 {
 	struct v4l2_subscribed_event *sev;
 	unsigned long flags;
-	int i;
 
 	if (sub->type == V4L2_EVENT_ALL) {
 		v4l2_event_unsubscribe_all(fh);
@@ -295,14 +306,8 @@ int v4l2_event_unsubscribe(struct v4l2_fh *fh,
 	spin_lock_irqsave(&fh->vdev->fh_lock, flags);
 
 	sev = v4l2_event_subscribed(fh, sub->type, sub->id);
-	if (sev != NULL) {
-		/* Remove any pending events for this subscription */
-		for (i = 0; i < sev->in_use; i++) {
-			list_del(&sev->events[sev_pos(sev, i)].list);
-			fh->navailable--;
-		}
-		list_del(&sev->list);
-	}
+	if (sev != NULL)
+		__v4l2_event_unsubscribe(sev);
 
 	spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
 
-- 
2.11.0

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

* Re: [PATCH v2 for v4.4 1/1] v4l: event: Add subscription to list before calling "add" operation
  2018-11-14  9:37 [PATCH v2 for v4.4 1/1] v4l: event: Add subscription to list before calling "add" operation Sakari Ailus
@ 2018-11-19 15:14 ` Greg Kroah-Hartman
  2018-11-19 17:03   ` Sakari Ailus
  0 siblings, 1 reply; 9+ messages in thread
From: Greg Kroah-Hartman @ 2018-11-19 15:14 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: Dave Stevenson, Hans Verkuil, mchehab, linux-media, Sasha Levin

On Wed, Nov 14, 2018 at 11:37:46AM +0200, Sakari Ailus wrote:
> [ upstream commit 92539d3eda2c090b382699bbb896d4b54e9bdece ]

There is no such git commit id in Linus's tree :(

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

* Re: [PATCH v2 for v4.4 1/1] v4l: event: Add subscription to list before calling "add" operation
  2018-11-19 15:14 ` Greg Kroah-Hartman
@ 2018-11-19 17:03   ` Sakari Ailus
  2018-11-19 17:46     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 9+ messages in thread
From: Sakari Ailus @ 2018-11-19 17:03 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Dave Stevenson, Hans Verkuil, mchehab, linux-media, Sasha Levin

Hi Greg,

On Mon, Nov 19, 2018 at 04:14:00PM +0100, Greg Kroah-Hartman wrote:
> On Wed, Nov 14, 2018 at 11:37:46AM +0200, Sakari Ailus wrote:
> > [ upstream commit 92539d3eda2c090b382699bbb896d4b54e9bdece ]
> 
> There is no such git commit id in Linus's tree :(

Right. At the moment it's in the media tree only. I expect it'll end up to
Linus's tree once Mauro will send the next pull request from the media tree
to Linus.

-- 
Regards,

Sakari Ailus
sakari.ailus@linux.intel.com

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

* Re: [PATCH v2 for v4.4 1/1] v4l: event: Add subscription to list before calling "add" operation
  2018-11-19 17:03   ` Sakari Ailus
@ 2018-11-19 17:46     ` Greg Kroah-Hartman
  2018-11-20 10:49       ` Sakari Ailus
  0 siblings, 1 reply; 9+ messages in thread
From: Greg Kroah-Hartman @ 2018-11-19 17:46 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: Dave Stevenson, Hans Verkuil, mchehab, linux-media, Sasha Levin

On Mon, Nov 19, 2018 at 07:03:54PM +0200, Sakari Ailus wrote:
> Hi Greg,
> 
> On Mon, Nov 19, 2018 at 04:14:00PM +0100, Greg Kroah-Hartman wrote:
> > On Wed, Nov 14, 2018 at 11:37:46AM +0200, Sakari Ailus wrote:
> > > [ upstream commit 92539d3eda2c090b382699bbb896d4b54e9bdece ]
> > 
> > There is no such git commit id in Linus's tree :(
> 
> Right. At the moment it's in the media tree only. I expect it'll end up to
> Linus's tree once Mauro will send the next pull request from the media tree
> to Linus.

Ok, please do not send requests for stable tree inclusion until _AFTER_
the patch is in Linus's tree, otherwise it just wastes the stable tree
maintainer's time :(

greg k-h

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

* Re: [PATCH v2 for v4.4 1/1] v4l: event: Add subscription to list before calling "add" operation
  2018-11-19 17:46     ` Greg Kroah-Hartman
@ 2018-11-20 10:49       ` Sakari Ailus
  2018-11-20 11:21         ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 9+ messages in thread
From: Sakari Ailus @ 2018-11-20 10:49 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Dave Stevenson, Hans Verkuil, mchehab, linux-media, Sasha Levin

Hi Greg,

On Mon, Nov 19, 2018 at 06:46:21PM +0100, Greg Kroah-Hartman wrote:
> On Mon, Nov 19, 2018 at 07:03:54PM +0200, Sakari Ailus wrote:
> > Hi Greg,
> > 
> > On Mon, Nov 19, 2018 at 04:14:00PM +0100, Greg Kroah-Hartman wrote:
> > > On Wed, Nov 14, 2018 at 11:37:46AM +0200, Sakari Ailus wrote:
> > > > [ upstream commit 92539d3eda2c090b382699bbb896d4b54e9bdece ]
> > > 
> > > There is no such git commit id in Linus's tree :(
> > 
> > Right. At the moment it's in the media tree only. I expect it'll end up to
> > Linus's tree once Mauro will send the next pull request from the media tree
> > to Linus.
> 
> Ok, please do not send requests for stable tree inclusion until _AFTER_
> the patch is in Linus's tree, otherwise it just wastes the stable tree
> maintainer's time :(

Apologies for the noise. I'll send you a note once the patches are in
Linus's tree.

Thanks.

-- 
Kind regards,

Sakari Ailus
sakari.ailus@linux.intel.com

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

* Re: [PATCH v2 for v4.4 1/1] v4l: event: Add subscription to list before calling "add" operation
  2018-11-20 10:49       ` Sakari Ailus
@ 2018-11-20 11:21         ` Mauro Carvalho Chehab
  2018-11-22 11:33           ` Sakari Ailus
  0 siblings, 1 reply; 9+ messages in thread
From: Mauro Carvalho Chehab @ 2018-11-20 11:21 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: Greg Kroah-Hartman, Dave Stevenson, Hans Verkuil, linux-media,
	Sasha Levin

Em Tue, 20 Nov 2018 12:49:46 +0200
Sakari Ailus <sakari.ailus@linux.intel.com> escreveu:

> Hi Greg,
> 
> On Mon, Nov 19, 2018 at 06:46:21PM +0100, Greg Kroah-Hartman wrote:
> > On Mon, Nov 19, 2018 at 07:03:54PM +0200, Sakari Ailus wrote:  
> > > Hi Greg,
> > > 
> > > On Mon, Nov 19, 2018 at 04:14:00PM +0100, Greg Kroah-Hartman wrote:  
> > > > On Wed, Nov 14, 2018 at 11:37:46AM +0200, Sakari Ailus wrote:  
> > > > > [ upstream commit 92539d3eda2c090b382699bbb896d4b54e9bdece ]  
> > > > 
> > > > There is no such git commit id in Linus's tree :(  
> > > 
> > > Right. At the moment it's in the media tree only. I expect it'll end up to
> > > Linus's tree once Mauro will send the next pull request from the media tree
> > > to Linus.  
> > 
> > Ok, please do not send requests for stable tree inclusion until _AFTER_
> > the patch is in Linus's tree, otherwise it just wastes the stable tree
> > maintainer's time :(  
> 
> Apologies for the noise. I'll send you a note once the patches are in
> Linus's tree.

Btw, just sent a pull request with this patch. 

I wanted to send this two weeks ago, but I had to do two trips 
(the final one to be at KS/LPC). This ended by delaying the pull request.

Thanks,
Mauro

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

* Re: [PATCH v2 for v4.4 1/1] v4l: event: Add subscription to list before calling "add" operation
  2018-11-20 11:21         ` Mauro Carvalho Chehab
@ 2018-11-22 11:33           ` Sakari Ailus
  2018-11-26  7:27             ` Greg Kroah-Hartman
  0 siblings, 1 reply; 9+ messages in thread
From: Sakari Ailus @ 2018-11-22 11:33 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Greg Kroah-Hartman, Dave Stevenson, Hans Verkuil, linux-media,
	Sasha Levin

On Tue, Nov 20, 2018 at 09:21:50AM -0200, Mauro Carvalho Chehab wrote:
> Em Tue, 20 Nov 2018 12:49:46 +0200
> Sakari Ailus <sakari.ailus@linux.intel.com> escreveu:
> 
> > Hi Greg,
> > 
> > On Mon, Nov 19, 2018 at 06:46:21PM +0100, Greg Kroah-Hartman wrote:
> > > On Mon, Nov 19, 2018 at 07:03:54PM +0200, Sakari Ailus wrote:  
> > > > Hi Greg,
> > > > 
> > > > On Mon, Nov 19, 2018 at 04:14:00PM +0100, Greg Kroah-Hartman wrote:  
> > > > > On Wed, Nov 14, 2018 at 11:37:46AM +0200, Sakari Ailus wrote:  
> > > > > > [ upstream commit 92539d3eda2c090b382699bbb896d4b54e9bdece ]  
> > > > > 
> > > > > There is no such git commit id in Linus's tree :(  
> > > > 
> > > > Right. At the moment it's in the media tree only. I expect it'll end up to
> > > > Linus's tree once Mauro will send the next pull request from the media tree
> > > > to Linus.  
> > > 
> > > Ok, please do not send requests for stable tree inclusion until _AFTER_
> > > the patch is in Linus's tree, otherwise it just wastes the stable tree
> > > maintainer's time :(  
> > 
> > Apologies for the noise. I'll send you a note once the patches are in
> > Linus's tree.
> 
> Btw, just sent a pull request with this patch. 
> 
> I wanted to send this two weeks ago, but I had to do two trips 
> (the final one to be at KS/LPC). This ended by delaying the pull request.

The patch is in Linus's tree now.

-- 
Regards,

Sakari Ailus
sakari.ailus@linux.intel.com

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

* Re: [PATCH v2 for v4.4 1/1] v4l: event: Add subscription to list before calling "add" operation
  2018-11-22 11:33           ` Sakari Ailus
@ 2018-11-26  7:27             ` Greg Kroah-Hartman
  2018-11-26  7:30               ` Greg Kroah-Hartman
  0 siblings, 1 reply; 9+ messages in thread
From: Greg Kroah-Hartman @ 2018-11-26  7:27 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: Mauro Carvalho Chehab, Dave Stevenson, Hans Verkuil, linux-media,
	Sasha Levin

On Thu, Nov 22, 2018 at 01:33:33PM +0200, Sakari Ailus wrote:
> On Tue, Nov 20, 2018 at 09:21:50AM -0200, Mauro Carvalho Chehab wrote:
> > Em Tue, 20 Nov 2018 12:49:46 +0200
> > Sakari Ailus <sakari.ailus@linux.intel.com> escreveu:
> > 
> > > Hi Greg,
> > > 
> > > On Mon, Nov 19, 2018 at 06:46:21PM +0100, Greg Kroah-Hartman wrote:
> > > > On Mon, Nov 19, 2018 at 07:03:54PM +0200, Sakari Ailus wrote:  
> > > > > Hi Greg,
> > > > > 
> > > > > On Mon, Nov 19, 2018 at 04:14:00PM +0100, Greg Kroah-Hartman wrote:  
> > > > > > On Wed, Nov 14, 2018 at 11:37:46AM +0200, Sakari Ailus wrote:  
> > > > > > > [ upstream commit 92539d3eda2c090b382699bbb896d4b54e9bdece ]  
> > > > > > 
> > > > > > There is no such git commit id in Linus's tree :(  
> > > > > 
> > > > > Right. At the moment it's in the media tree only. I expect it'll end up to
> > > > > Linus's tree once Mauro will send the next pull request from the media tree
> > > > > to Linus.  
> > > > 
> > > > Ok, please do not send requests for stable tree inclusion until _AFTER_
> > > > the patch is in Linus's tree, otherwise it just wastes the stable tree
> > > > maintainer's time :(  
> > > 
> > > Apologies for the noise. I'll send you a note once the patches are in
> > > Linus's tree.
> > 
> > Btw, just sent a pull request with this patch. 
> > 
> > I wanted to send this two weeks ago, but I had to do two trips 
> > (the final one to be at KS/LPC). This ended by delaying the pull request.
> 
> The patch is in Linus's tree now.

And what is the git commit id?

thanks,

gre k-h

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

* Re: [PATCH v2 for v4.4 1/1] v4l: event: Add subscription to list before calling "add" operation
  2018-11-26  7:27             ` Greg Kroah-Hartman
@ 2018-11-26  7:30               ` Greg Kroah-Hartman
  0 siblings, 0 replies; 9+ messages in thread
From: Greg Kroah-Hartman @ 2018-11-26  7:30 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: Mauro Carvalho Chehab, Dave Stevenson, Hans Verkuil, linux-media,
	Sasha Levin

On Mon, Nov 26, 2018 at 08:27:59AM +0100, Greg Kroah-Hartman wrote:
> On Thu, Nov 22, 2018 at 01:33:33PM +0200, Sakari Ailus wrote:
> > On Tue, Nov 20, 2018 at 09:21:50AM -0200, Mauro Carvalho Chehab wrote:
> > > Em Tue, 20 Nov 2018 12:49:46 +0200
> > > Sakari Ailus <sakari.ailus@linux.intel.com> escreveu:
> > > 
> > > > Hi Greg,
> > > > 
> > > > On Mon, Nov 19, 2018 at 06:46:21PM +0100, Greg Kroah-Hartman wrote:
> > > > > On Mon, Nov 19, 2018 at 07:03:54PM +0200, Sakari Ailus wrote:  
> > > > > > Hi Greg,
> > > > > > 
> > > > > > On Mon, Nov 19, 2018 at 04:14:00PM +0100, Greg Kroah-Hartman wrote:  
> > > > > > > On Wed, Nov 14, 2018 at 11:37:46AM +0200, Sakari Ailus wrote:  
> > > > > > > > [ upstream commit 92539d3eda2c090b382699bbb896d4b54e9bdece ]  
> > > > > > > 
> > > > > > > There is no such git commit id in Linus's tree :(  
> > > > > > 
> > > > > > Right. At the moment it's in the media tree only. I expect it'll end up to
> > > > > > Linus's tree once Mauro will send the next pull request from the media tree
> > > > > > to Linus.  
> > > > > 
> > > > > Ok, please do not send requests for stable tree inclusion until _AFTER_
> > > > > the patch is in Linus's tree, otherwise it just wastes the stable tree
> > > > > maintainer's time :(  
> > > > 
> > > > Apologies for the noise. I'll send you a note once the patches are in
> > > > Linus's tree.
> > > 
> > > Btw, just sent a pull request with this patch. 
> > > 
> > > I wanted to send this two weeks ago, but I had to do two trips 
> > > (the final one to be at KS/LPC). This ended by delaying the pull request.
> > 
> > The patch is in Linus's tree now.
> 
> And what is the git commit id?

Nevermind, I see it...

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

end of thread, other threads:[~2018-11-26 18:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-14  9:37 [PATCH v2 for v4.4 1/1] v4l: event: Add subscription to list before calling "add" operation Sakari Ailus
2018-11-19 15:14 ` Greg Kroah-Hartman
2018-11-19 17:03   ` Sakari Ailus
2018-11-19 17:46     ` Greg Kroah-Hartman
2018-11-20 10:49       ` Sakari Ailus
2018-11-20 11:21         ` Mauro Carvalho Chehab
2018-11-22 11:33           ` Sakari Ailus
2018-11-26  7:27             ` Greg Kroah-Hartman
2018-11-26  7:30               ` Greg Kroah-Hartman

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