[PATCH] Locking in Siano driver (untested)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a simple but completely untested patch for linux/drivers/media/dvb/siano/smscoreapi.c

This patch addresses the apparent possible invocation of schedule while holding a spin lock. In the smscore_getbuffer function, the spin lock is simply dropped around the schedule call and in the accompanying smscore_putbuffer function the spin lock is used to synchronize both the wake up and addition of a new buffer.

Note that there is no explicit use of memory barriers so I am not certain as to whether this patch will address all possible locking issues with the smscore_getbuffer and smscore_putbuffer functions.

Since I don't actually use git to follow the development of Linux drivers and I don't actually have the relevant hardware, I can't easily test the change to the source. Perhaps this will be useful to someone who might want to look at and modifiy the siano code.

I've attached a simple unified diff.

I.e. in linux/drivers/media/dvb/siano:

% diff -u smscoreapi.c smscoreapi.c.orig

Tim
--- smscoreapi.c.orig	2009-11-11 11:22:44.000000000 +0000
+++ smscoreapi.c	2009-11-12 16:02:25.000000000 +0000
@@ -1120,8 +1120,11 @@
 
 	prepare_to_wait(&coredev->buffer_mng_waitq, &wait, TASK_INTERRUPTIBLE);
 
-	if (list_empty(&coredev->buffers))
+	if (list_empty(&coredev->buffers)) {
+		spin_unlock_irqrestore(&coredev->bufferslock, flags);
 		schedule();
+		spin_lock_irqsave(&coredev->bufferslock, flags);
+	}
 
 	finish_wait(&coredev->buffer_mng_waitq, &wait);
 
@@ -1144,8 +1147,14 @@
  */
 void smscore_putbuffer(struct smscore_device_t *coredev,
 		struct smscore_buffer_t *cb) {
+	unsigned long flags;
+
+	spin_lock_irqsave(&coredev->bufferslock, flags);
+
+	list_add(&cb->entry, &coredev->buffers);
 	wake_up_interruptible(&coredev->buffer_mng_waitq);
-	list_add_locked(&cb->entry, &coredev->buffers, &coredev->bufferslock);
+
+	spin_unlock_irqrestore(&coredev->bufferslock, flags);
 }
 EXPORT_SYMBOL_GPL(smscore_putbuffer);
 

[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux