public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] media: bt8xx: Fix a possible data race in buffer_queue()
@ 2023-06-28  7:19 Tuo Li
  2023-07-03 12:36 ` Deborah Brouwer
  0 siblings, 1 reply; 2+ messages in thread
From: Tuo Li @ 2023-06-28  7:19 UTC (permalink / raw)
  To: mchehab, hverkuil-cisco
  Cc: linux-media, linux-kernel, baijiaju1990, Tuo Li, BassCheck

The variable btv->loop_irq is often protected by the lock btv->s_lock when
is accessed. Here is an example in bttv_irq_timeout():

  spin_lock_irqsave(&btv->s_lock,flags); 
  ...
  btv->loop_irq = 0;
  ...
  spin_unlock_irqrestore(&btv->s_lock,flags);

However, it is accessed without holding the lock btv->s_lock in 
buffer_queue():

  btv->loop_irq |= 1;

And thus a data race can occur.
To fix this possible data race, a lock and unlock pair is added when
accessing the variable btv->loop_irq in buffer_queue().

Reported-by: BassCheck <bass@buaa.edu.cn>
Signed-off-by: Tuo Li <islituo@gmail.com>
---
 drivers/media/pci/bt8xx/bttv-driver.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c
index 734f02b91aa3..241c51951627 100644
--- a/drivers/media/pci/bt8xx/bttv-driver.c
+++ b/drivers/media/pci/bt8xx/bttv-driver.c
@@ -1617,13 +1617,16 @@ buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
 	struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb);
 	struct bttv_fh *fh = q->priv_data;
 	struct bttv    *btv = fh->btv;
+	unsigned long flags;
 
+	spin_lock_irqsave(&btv->s_lock,flags);
 	buf->vb.state = VIDEOBUF_QUEUED;
 	list_add_tail(&buf->vb.queue,&btv->capture);
 	if (!btv->curr.frame_irq) {
 		btv->loop_irq |= 1;
 		bttv_set_dma(btv, 0x03);
 	}
+	spin_unlock_irqrestore(&btv->s_lock,flags);
 }
 
 static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
-- 
2.34.1


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

end of thread, other threads:[~2023-07-03 12:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-28  7:19 [PATCH] media: bt8xx: Fix a possible data race in buffer_queue() Tuo Li
2023-07-03 12:36 ` Deborah Brouwer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox