]> git.baikalelectronics.ru Git - kernel.git/commit
pps: fix race in PPS_FETCH handler
authorAlexander Gordeev <lasaine@lvk.cs.msu.su>
Thu, 13 Jan 2011 01:00:50 +0000 (17:00 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 13 Jan 2011 16:03:19 +0000 (08:03 -0800)
commit767ba3486d0f5bd69ada870d77613f3d8abe47a4
treed7fbadca22907cb90b9e94b283bf8abe6d508c73
parent37da3ee9002d94a107cf4a009f07a2520679c266
pps: fix race in PPS_FETCH handler

There was a race in PPS_FETCH ioctl handler when several processes want to
obtain PPS data simultaneously using sleeping PPS_FETCH.  They all sleep
most of the time in the system call.

With the old approach when the first process waiting on the pps queue is
waken up it makes new system call right away and zeroes pps->go.  So other
processes continue to sleep.  This is a clear race condition because of
the global 'go' variable.

With the new approach pps->last_ev holds some value increasing at each PPS
event.  PPS_FETCH ioctl handler saves current value to the local variable
at the very beginning so it can safely check that there is a new event by
just comparing both variables.

Signed-off-by: Alexander Gordeev <lasaine@lvk.cs.msu.su>
Acked-by: Rodolfo Giometti <giometti@linux.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/pps/kapi.c
drivers/pps/pps.c
include/linux/pps_kernel.h