The driver is opened by multiple processes, One such process is a diagnostics.<br>Where I am checking sanity of some of the registers if I make ioctl open for all the processes.It can screw <br>up my diagnostics check.(write some values to registers). This is basic reason I am using lock to my ioctl.<br>
<br>Thanks <br>Praveen<br><br><div class="gmail_quote">On Tue, Nov 15, 2011 at 1:28 PM, Dave Hylands <span dir="ltr"><<a href="mailto:dhylands@gmail.com">dhylands@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi Praveen,<br>
<div class="im"><br>
On Mon, Nov 14, 2011 at 11:22 PM, Praveen kumar <<a href="mailto:chatpravi@gmail.com">chatpravi@gmail.com</a>> wrote:<br>
><br>
> Hi All,<br>
> I have a situation where I have to lock the ioctl provided in my driver. I<br>
> have a uni processor (ARM) system.<br>
> I am using Mutex as the lock for my ioctl.<br>
> DEFINE_MUTEX(&lock_ioctl);<br>
> MyIoctl()<br>
> {<br>
> Mutex_lock(&lock_ioctl);<br>
> Switch(){<br>
> ...........<br>
> }<br>
> Mutex_unlock(&lock_ioctl);<br>
> return 0;<br>
> }<br>
> I just wanted to know am I using the best lock available for the situation<br>
> aor do I have any flaw in my implementation???<br>
><br>
> And from LKD I read that "*lock the data not the code*" and which I am<br>
> literally doing so ?? any comments on this ?<br>
<br>
</div>By creatiing something called lock_ioctl, I'd say you're locking the code.<br>
<br>
Locking the data means that lets suppose you have some data structure<br>
which requires mutual exclusion. Then I'd create a lock associated<br>
with that data structure (and probably the lock would be a member of<br>
the data structure), and anytime I needed to manipulate/access the<br>
data structure (in an atomic manner), I'd acquire the lock.<br>
<div class="im"><br>
> I have interrupts in my driver which is nothing to do with the lock.I am<br>
> taking care that where ever I return in my ioctl the lock is released.<br>
<br>
</div>What are you locking? Does every single ioctl really need to acquire<br>
the lock? Why?<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Dave Hylands<br>
Shuswap, BC, Canada<br>
<a href="http://www.davehylands.com" target="_blank">http://www.davehylands.com</a><br>
</font></span></blockquote></div><br>