Hi <div><br></div><div>I wrote a sample module which looked like this and i expected the module to hang as i have used 2 spin_lock simultaneously. But i find the print after the second spin_lock being printed and the module works perfectly fine. Can any body please help me in understanding this? I got this problem from a driver i wrote and had a typo "spin_lock" instead of "spin_unlock" the driver worked fine and i caught the mistake only during a review </div>
<div><br></div><div><div><i>#include <linux/module.h></i></div><div><i>#include <linux/spinlock.h></i></div><div><i><br></i></div><div><i>struct sp_q {</i></div><div><i>spinlock_t spinlock;</i></div><div><i>uint8_t data;</i></div>
<div><i>};</i></div><div><i><br></i></div><div><i>static int __init sp_lck_init(void)</i></div><div><i>{</i></div><div><i><br></i></div><div><i> struct sp_q test;</i></div><div><i> </i></div><div><i> /* Spin lock Init */</i></div>
<div><i><br></i></div><div><i> spin_lock_init(&test.spinlock);</i></div><div><i> </i></div><div><i> printk("<1>Test start\n");</i></div><div><i> </i></div><div><i> spin_lock(&test.spinlock);</i></div>
<div><i> test.data = 0; </i></div><div><i> spin_lock(&test.spinlock); </i></div><div><i> </i></div><div><i> printk("<1>How come???\n");</i></div><div><i> return 0;</i></div><div><i><br></i></div>
<div><i>}</i></div><div><i><br></i></div><div><i>static void __exit sp_lck_exit(void)</i></div><div><i>{</i></div><div><i><br></i></div><div><i>}</i></div><div><i><br></i></div><div><i>module_init(sp_lck_init);</i></div><div>
<i>module_exit(sp_lck_exit);</i></div><div><i>MODULE_LICENSE("GPL");</i></div></div><div><div><br></div>-- <br>Regards,<br><br>Prajosh Premdas<br>
</div>