Reads of dgnc_poll_tick are protected by dgnc_poll_lock spinlock, but the write
to dgnc_poll_tick is not. It could theoretically race.

Signed-off-by: Salah Triki <salah.tr...@acm.org>
---
 drivers/staging/dgnc/dgnc_driver.c | 2 +-
 drivers/staging/dgnc/dgnc_driver.h | 1 +
 drivers/staging/dgnc/dgnc_sysfs.c  | 9 ++++++++-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_driver.c 
b/drivers/staging/dgnc/dgnc_driver.c
index 7546aff..b402c9e 100644
--- a/drivers/staging/dgnc/dgnc_driver.c
+++ b/drivers/staging/dgnc/dgnc_driver.c
@@ -64,6 +64,7 @@ static const struct file_operations dgnc_BoardFops = {
 uint                   dgnc_NumBoards;
 struct dgnc_board              *dgnc_Board[MAXBOARDS];
 DEFINE_SPINLOCK(dgnc_global_lock);
+DEFINE_SPINLOCK(dgnc_poll_lock); /* Poll scheduling lock */
 uint                   dgnc_Major;
 int                    dgnc_poll_tick = 20;    /* Poll interval - 20 ms */
 
@@ -75,7 +76,6 @@ static struct class *dgnc_class;
 /*
  * Poller stuff
  */
-static DEFINE_SPINLOCK(dgnc_poll_lock); /* Poll scheduling lock */
 static ulong           dgnc_poll_time; /* Time of next poll */
 static uint            dgnc_poll_stop; /* Used to tell poller to stop */
 static struct timer_list dgnc_poll_timer;
diff --git a/drivers/staging/dgnc/dgnc_driver.h 
b/drivers/staging/dgnc/dgnc_driver.h
index 06ece51..c61884c 100644
--- a/drivers/staging/dgnc/dgnc_driver.h
+++ b/drivers/staging/dgnc/dgnc_driver.h
@@ -390,6 +390,7 @@ struct channel_t {
 extern uint            dgnc_Major;             /* Our driver/mgmt major */
 extern int             dgnc_poll_tick;         /* Poll interval - 20 ms */
 extern spinlock_t      dgnc_global_lock;       /* Driver global spinlock */
+extern spinlock_t      dgnc_poll_lock;         /* Poll scheduling lock */
 extern uint            dgnc_NumBoards;         /* Total number of boards */
 extern struct dgnc_board       *dgnc_Board[MAXBOARDS]; /* Array of board 
structs */
 
diff --git a/drivers/staging/dgnc/dgnc_sysfs.c 
b/drivers/staging/dgnc/dgnc_sysfs.c
index 44db870..48b6056 100644
--- a/drivers/staging/dgnc/dgnc_sysfs.c
+++ b/drivers/staging/dgnc/dgnc_sysfs.c
@@ -56,11 +56,18 @@ static ssize_t dgnc_driver_pollrate_show(struct 
device_driver *ddp, char *buf)
 static ssize_t dgnc_driver_pollrate_store(struct device_driver *ddp,
                                          const char *buf, size_t count)
 {
+       unsigned long flags;
+       int tick;
        int ret;
 
-       ret = sscanf(buf, "%d\n", &dgnc_poll_tick);
+       ret = sscanf(buf, "%d\n", &tick);
        if (ret != 1)
                return -EINVAL;
+
+       spin_lock_irqsave(&dgnc_poll_lock, flags);
+       dgnc_poll_tick = tick;
+       spin_unlock_irqrestore(&dgnc_poll_lock, flags);
+
        return count;
 }
 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgnc_driver_pollrate_show,
-- 
1.9.1

_______________________________________________
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

Reply via email to