Re: lock_kernel check...

Dave Hansen (haveblue@us.ibm.com)
Tue, 09 Jul 2002 10:04:11 -0700


Zwane Mwaikambo wrote:
> On Tue, 9 Jul 2002, Dave Hansen wrote:
>
>
>>It isn't absoulutely a bad thing to return while you have a lock held.
>> It might be hard to understand, or even crazy, but not immediately
>>wrong :)
>>
>>// BKL protects both "a", and io port 0xF00D
>>bar()
>>{
>> lock_kernel();
>> return inb(0xF00D);
>>}
>>
>>int a;
>>foo()
>>{
>> a = bar();
>> a--;
>> unlock_kernel();
>>}
>
> But broken nonetheless, that kinda thing just looks ugly. Especially when
> someone tries to call bar multiple times or consecutively or with the lock
> already held or...

Yes, it is horribly ugly, but it is not broken. As a function, if you
document what you require your caller to do, there shouldn't be a
problem.

Also, it is valid to have nested holds of the BKL. You can never
deadlock with another lock_kernel() which was done in the same process.

-- 
Dave Hansen
haveblue@us.ibm.com

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/