From: Rodolfo Giometti <giometti@enneenne.com>
To: Satyam Sharma <satyam.sharma@gmail.com>
Cc: Chris Friesen <cfriesen@nortel.com>,
David Woodhouse <dwmw2@infradead.org>,
linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: LinuxPPS & spinlocks
Date: Sun, 29 Jul 2007 12:00:07 +0200 [thread overview]
Message-ID: <20070729100007.GB9840@enneenne.com> (raw)
In-Reply-To: <a781481a0707271641n20353a12u7467d093346f2f4c@mail.gmail.com>
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: giometti@enneenne.com
Linux Device Driver giometti@gnudd.com
Embedded Systems giometti@linux.it
UNIX programming phone: +39 349 2432127
next prev parent reply other threads:[~2007-07-29 9:58 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-17 18:05 [PATCH] LinuxPPS - definitive version Rodolfo Giometti
2007-07-23 13:35 ` David Woodhouse
2007-07-23 16:04 ` Rodolfo Giometti
2007-07-23 19:28 ` Andrew Morton
2007-07-23 19:48 ` David Woodhouse
2007-07-24 8:00 ` Rodolfo Giometti
2007-07-24 13:49 ` David Woodhouse
2007-07-24 14:20 ` Rodolfo Giometti
2007-07-24 14:46 ` David Woodhouse
2007-07-24 14:52 ` David Woodhouse
2007-07-24 16:01 ` Rodolfo Giometti
2007-07-27 18:44 ` LinuxPPS & spinlocks Rodolfo Giometti
2007-07-27 19:08 ` Chris Friesen
2007-07-27 19:28 ` Rodolfo Giometti
2007-07-27 19:40 ` Chris Friesen
2007-07-27 19:45 ` Rodolfo Giometti
2007-07-27 20:47 ` Satyam Sharma
2007-07-27 23:41 ` Satyam Sharma
2007-07-29 9:50 ` Rodolfo Giometti
2007-07-30 5:03 ` Satyam Sharma
2007-07-30 8:51 ` Rodolfo Giometti
2007-07-30 9:20 ` Satyam Sharma
2007-08-01 22:14 ` Christopher Hoover
2007-08-01 23:03 ` Satyam Sharma
2007-07-29 9:57 ` Rodolfo Giometti
2007-07-29 10:00 ` Rodolfo Giometti [this message]
2007-07-30 5:09 ` Satyam Sharma
2007-07-30 8:53 ` Rodolfo Giometti
2007-07-30 9:31 ` Satyam Sharma
2007-07-29 9:17 ` Rodolfo Giometti
2007-07-30 4:19 ` Satyam Sharma
2007-07-30 8:32 ` Rodolfo Giometti
2007-07-30 9:07 ` Satyam Sharma
2007-07-30 14:55 ` Rodolfo Giometti
2007-07-30 22:01 ` Satyam Sharma
2007-07-31 8:20 ` Rodolfo Giometti
2007-07-31 18:49 ` Satyam Sharma
2007-07-31 19:44 ` Rodolfo Giometti
2007-07-31 21:15 ` Satyam Sharma
2007-07-24 14:31 ` [PATCH] LinuxPPS - definitive version Rodolfo Giometti
2007-07-24 14:45 ` David Woodhouse
2007-07-24 16:09 ` Rodolfo Giometti
2007-07-26 19:52 ` Roman Zippel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070729100007.GB9840@enneenne.com \
--to=giometti@enneenne.com \
--cc=akpm@linux-foundation.org \
--cc=cfriesen@nortel.com \
--cc=dwmw2@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=satyam.sharma@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox