All of lore.kernel.org
 help / color / mirror / Atom feed
* Bogus locking warnings
@ 2007-02-27  1:42 Pavel Roskin
  2007-02-27  4:19 ` Linus Torvalds
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Roskin @ 2007-02-27  1:42 UTC (permalink / raw)
  To: linux-sparse

Hello!

The current sparse issues a warning about this file:

void my_lock(void) __attribute__ ((context(lock, 0, 1)));
void my_unlock(void) __attribute__ ((context(lock, 1, 0)));
void foo(void);
static void bar(const int locked)
{
	if (!locked)
		my_lock();
	foo();
	if (!locked)
		my_unlock();
}


$ sparse test.c 
test.c:10:3: warning: context imbalance in 'bar' - unexpected unlock

Commenting out foo() call eliminated the warning.  I understand that
sparse suspects that foo() could change "locked".

Changing "int locked" to "const int locked" makes no difference.  I
don't see what else could be done to tell sparse that "locked" won't
change throughout the function call.

Something interesting happens if I change "!locked" to "locked" in both
places:

$ sparse test.c 
test.c:9:2: warning: context imbalance in 'bar' - different lock
contexts for basic block

Although sparse doesn't know anything about the semantic of "locked", it
issues different warnings whether the variable is used "positively" or
"negatively".  No amount of paranoia about foo() can excuse this
inconsistency.

-- 
Regards,
Pavel Roskin

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-02-27  7:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-27  1:42 Bogus locking warnings Pavel Roskin
2007-02-27  4:19 ` Linus Torvalds
2007-02-27  7:24   ` Pavel Roskin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.