Bogus locking warnings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux