The existing cedar driver code already has a semaphore, but is
only doing some strange and pointless manipulations with it.
Now use this semaphore to actually protect /dev/cedar_dev from
being simultaneously opened by multiple users.

When the cedar driver is already occupied, any new attempts to
open /dev/cedar_dev just block until the current user closes it.

Signed-off-by: Siarhei Siamashka <siarhei.siamas...@gmail.com>
---
 drivers/media/video/sunxi/sunxi_cedar.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/media/video/sunxi/sunxi_cedar.c 
b/drivers/media/video/sunxi/sunxi_cedar.c
index f30d086..64f4151 100644
--- a/drivers/media/video/sunxi/sunxi_cedar.c
+++ b/drivers/media/video/sunxi/sunxi_cedar.c
@@ -797,8 +797,7 @@ static int cedardev_open(struct inode *inode, struct file 
*filp)
                return -ERESTARTSYS;
        }
        /* init other resource here */
-    devp->irq_flag = 0;
-       up(&devp->sem);
+       devp->irq_flag = 0;
        nonseekable_open(inode, filp);
        return 0;
 }
@@ -808,11 +807,9 @@ static int cedardev_release(struct inode *inode, struct 
file *filp)
        struct cedar_dev *devp;
 
        devp = filp->private_data;
-       if (down_interruptible(&devp->sem)) {
-               return -ERESTARTSYS;
-       }
+
        /* release other resource here */
-    devp->irq_flag = 1;
+       devp->irq_flag = 1;
        up(&devp->sem);
        return 0;
 }
-- 
2.4.10

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to linux-sunxi+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to