2002-07-09 09:06:18

by Dave Hansen

[permalink] [raw]
Subject: Re: lock_kernel check...

#!/usr/bin/perl -w
use smatch;

sub print_url {
if (get_filename() =~ /home\/carp0110\/progs\/kernel\/devel\/linux-2.5.7\/(.*)/){
print 'http://lxr.linux.no/source/', $1, '?v=2.5.7#', get_lineno(), "\n";
}
}

while ($data = get_data()){
# if we see a lock_kernel then we set the state to "locked"
if ($data =~ /call_expr\(\(addr_expr function_decl\(lock_kernel/){
set_state("locked");
next;
}

# if we see an unlock_kernel we set the state to "unlocked"
if ($data =~ /call_expr\(\(addr_expr function_decl\(unlock_kernel/){
set_state("unlocked");
next;
}

# if we see a return statement and the kernel is
# locked then we print a mesg.
if ($data =~ /^return_stmt/){
if (get_state() =~ /^locked$/){
#print "Not unlocked: ", get_filename(), " ", get_start_line(), " ", get_lineno(), "\n";
print_url();
next;
}
}
}


Attachments:
lock-check.pl (883.00 B)

2002-07-09 10:11:00

by Zwane Mwaikambo

[permalink] [raw]
Subject: Re: lock_kernel check...

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...

Zwane Mwaikambo

--
function.linuxpower.ca