From: ecashin@coraid.com
To: linux-sparse@vger.kernel.org
Cc: ecashin@coraid.com
Subject: "unexpected unlock" when unlocking, conditional, lock in loop
Date: Sat, 6 Oct 2012 12:47:56 -0700 [thread overview]
Message-ID: <1349552876.20963@cat.he.net> (raw)
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/
next reply other threads:[~2012-10-06 19:55 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-06 19:47 ecashin [this message]
2012-10-06 20:21 ` "unexpected unlock" when unlocking, conditional, lock in loop 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1349552876.20963@cat.he.net \
--to=ecashin@coraid.com \
--cc=linux-sparse@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.