Locking IOCTL
Dave Hylands
dhylands at gmail.com
Tue Nov 15 16:34:12 EST 2011
Hi Praveen,
On Tue, Nov 15, 2011 at 4:23 AM, Praveen kumar <chatpravi at gmail.com> wrote:
> The driver is opened by multiple processes, One such process is a
> diagnostics.
> Where I am checking sanity of some of the registers if I make ioctl open for
> all the processes.It can screw
> up my diagnostics check.(write some values to registers). This is basic
> reason I am using lock to my ioctl.
So "locking the data" means that you should create a lock for the data
registers in question.
You should acquire the lock around writing the values to the
registers, and presumably around reading them.
Acquiring the lock is about accessing the registers, not calling the
ioctl, even if today the only place that you access the registers is
from the ioctl. What happens if down the road you decide to add some
type of monitoring thread and it needs to access the registers? It's
not in an ioctl, so acquiring some type of ioctl lock is misleading.
The data that the lock is tied to is the registers, so make the code
work that way.
Also, som paths through the ioctl might not need to access the
registers, so you don't need or want to acquire the lock for those
cases.
--
Dave Hylands
Shuswap, BC, Canada
http://www.davehylands.com
More information about the Kernelnewbies
mailing list