linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* "unexpected unlock" when unlocking, conditional, lock in loop
@ 2012-10-06 19:47 ecashin
  2012-10-06 20:21 ` Josh Triplett
  0 siblings, 1 reply; 10+ messages in thread
From: ecashin @ 2012-10-06 19:47 UTC (permalink / raw)
  To: linux-sparse; +Cc: ecashin

Hi.  I have a function that enters with a lock held and does
an unlock inside a loop.

Sparse 0.4.4 is fine with this function until I introduce a conditional
between the unlock and the next lock.  In the minimal example below,
changing the "#if 1" to "#if 0" makes sparse generate the warning
below:

cd ~/git/linux && PATH=/opt/bin:$PATH make drivers/block/aoe/aoe.ko C=1
make[1]: Nothing to be done for `all'.
make[1]: Nothing to be done for `relocs'.
  CHK     include/linux/version.h
  CHK     include/generated/utsrelease.h
  CALL    scripts/checksyscalls.sh
  CHECK   drivers/block/aoe/demo.c
/build/ecashin/git/linux/arch/x86/include/asm/spinlock.h:81:9: warning: context imbalance in 'demofn' - unexpected unlock
  CC [M]  drivers/block/aoe/demo.o
  LD [M]  drivers/block/aoe/aoe.o
  MODPOST 1 modules
  CC      drivers/block/aoe/aoe.mod.o
  LD [M]  drivers/block/aoe/aoe.ko

I'm using 3.6.0-rc7 kernel sources.

Granted, I'm unusually tired today, but I can't think of a way that
conditionally printing a warning has changed the locking, so I
could use some help in determining whether this is a sparse bug
that might be fixed, one that I have to work around, or some
confusion of mine.

/* demo.c */
#include <linux/netdevice.h>

static spinlock_t lk;
static struct sk_buff_head q;
int demofn(void);

/* enters and returns with lk held */
int demofn(void)
{
	struct sk_buff *skb;

	while ((skb = skb_dequeue(&q))) {
		spin_unlock_irq(&lk);
#if 1
		dev_queue_xmit(skb);
#else
		if (dev_queue_xmit(skb) == NET_XMIT_DROP && net_ratelimit())
			pr_warn("informative warning\n");
#endif
		spin_lock_irq(&lk);
	}
	return 0;
}

-- 
  Ed Cashin
  ecashin@coraid.com	http://www.coraid.com/
  ecashin@noserose.net	http://noserose.net/e/

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

end of thread, other threads:[~2012-10-08  2:01 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-06 19:47 "unexpected unlock" when unlocking, conditional, lock in loop ecashin
2012-10-06 20:21 ` Josh Triplett
2012-10-07  1:56   ` Ed Cashin
2012-10-07  2:39     ` Josh Triplett
2012-10-07 12:49       ` Ed Cashin
2012-10-07 19:45         ` Josh Triplett
2012-10-07 21:28           ` Ed Cashin
2012-10-07 23:30             ` Josh Triplett
2012-10-08  0:35               ` Ed Cashin
2012-10-08  2:01                 ` Josh Triplett

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).