staging: dgnc: take a lock when storing value in dgnc_poll_tick
authorSalah Triki <salah.triki@acm.org>
Sun, 4 Oct 2015 01:49:48 +0000 (02:49 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 4 Oct 2015 08:30:14 +0000 (09:30 +0100)
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.triki@acm.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/dgnc/dgnc_driver.c
drivers/staging/dgnc/dgnc_driver.h
drivers/staging/dgnc/dgnc_sysfs.c

index ae81a8b1184eb4142f524fefc04c8e4b9e01f340..ce2d1c7ed29e841160fa40689d7839b668a458a5 100644 (file)
@@ -63,6 +63,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 */
 
@@ -74,7 +75,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;
index 06ece5151fe4a170ad04972d5bf3789e7c33ee21..c61884c14777f0bc2d349a25f03b5d4aa70cc3fc 100644 (file)
@@ -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 */
 
index 44db8703eba47fc40677d39426ba955a0035976f..48b605678c32a33706fb483d193f6739f3403d3d 100644 (file)
@@ -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,