Re: LinuxPPS & spinlocks

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

 



On Sat, Jul 28, 2007 at 05:11:17AM +0530, Satyam Sharma wrote:

> Take the race between the time_pps_setparams() syscall and a concurrent
> pps_event() from an interrupt for instance. From sys_time_pps_setparams,
> the parameters for an existing source are not modified / set atomically,
> which means a pps_event() called on the same source in between will see
> invalid parameters ... and bad things will happen.

I think this should be a good solution... :)

diff --git a/drivers/pps/kapi.c b/drivers/pps/kapi.c
index 08de71d..f0c42ec 100644
--- a/drivers/pps/kapi.c
+++ b/drivers/pps/kapi.c
@@ -29,12 +29,6 @@
 #include <linux/pps.h>
 
 /*
- * Local variables
- */
-
-static spinlock_t pps_lock = SPIN_LOCK_UNLOCKED;
-
-/*
  * Local functions
  */
 
diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c
index 9176c01..91b7e4d 100644
--- a/drivers/pps/pps.c
+++ b/drivers/pps/pps.c
@@ -35,6 +35,7 @@
 
 struct pps_s pps_source[PPS_MAX_SOURCES];
 DEFINE_MUTEX(pps_mutex);
+spinlock_t pps_lock = SPIN_LOCK_UNLOCKED;
 
 /*
  * Misc functions
@@ -227,6 +228,8 @@ asmlinkage long sys_time_pps_setparams(int source,
                goto sys_time_pps_setparams_exit;
        }
 
+       spin_lock(&pps_lock);
+
        /* Save the new parameters */
        ret = copy_from_user(&pps_source[source].params, params,
                                                sizeof(struct pps_kparams));
@@ -245,6 +248,8 @@ asmlinkage long sys_time_pps_setparams(int source,
                pps_source[source].params.mode |= PPS_CANWAIT;
        pps_source[source].params.api_version = PPS_API_VERS;
 
+       spin_unlock(&pps_lock);
+
 sys_time_pps_setparams_exit:
        mutex_unlock(&pps_mutex);
 
diff --git a/include/linux/pps.h b/include/linux/pps.h
index 6eca3ea..93e7384 100644
--- a/include/linux/pps.h
+++ b/include/linux/pps.h
@@ -174,6 +174,7 @@ struct pps_s {
 
 extern struct pps_s pps_source[PPS_MAX_SOURCES];
 extern struct mutex pps_mutex;
+extern spinlock_t pps_lock;
 
 /*
  * Global functions

Ciao,

Rodolfo

-- 

GNU/Linux Solutions                  e-mail:    [email protected]
Linux Device Driver                             [email protected]
Embedded Systems                     		[email protected]
UNIX programming                     phone:     +39 349 2432127
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux