* Context imbalance false positive
@ 2008-07-17 23:52 Luis R. Rodriguez
2008-07-18 8:25 ` Johannes Berg
0 siblings, 1 reply; 3+ messages in thread
From: Luis R. Rodriguez @ 2008-07-17 23:52 UTC (permalink / raw)
To: linux-sparse; +Cc: Johannes Berg
I'm not sure how to resolve a situation like this:
#include <linux/module.h>
#include <linux/spinlock.h>
MODULE_AUTHOR("Luis R. Rodriguez");
MODULE_LICENSE("GPL");
static spinlock_t some_lock;
static void lock(int bh_flag)
{
if (bh_flag)
spin_lock_bh(&some_lock);
else
spin_lock(&some_lock);
}
static void unlock(int bh_flag)
{
if (bh_flag)
spin_unlock_bh(&some_lock);
else
spin_unlock(&some_lock);
}
static int hello_init(void)
{
spin_lock_init(&some_lock);
lock(1);
printk("I am a module, cheers!\n");
unlock(1);
return 0;
}
static void goodbye_exit(void)
{
printk("Goodbye cruel world!\n");
}
module_init(hello_init);
module_exit(goodbye_exit);
----
Sparse complains with:
/home/mcgrof/devel/spin_lock_sparse/sparse_spinlock.c:14:3: warning:
context imbalance in 'lock': wrong count at exit
/home/mcgrof/devel/spin_lock_sparse/sparse_spinlock.c:14:3: context
'lock': wanted 0, got 1
/home/mcgrof/devel/spin_lock_sparse/sparse_spinlock.c:20:3: warning:
context problem in 'unlock': '_spin_unlock_bh' expected different
context
/home/mcgrof/devel/spin_lock_sparse/sparse_spinlock.c:20:3: context
'lock': wanted >= 1, got 0
You can test compile from files here:
http://ruslug.rutgers.edu/~mcgrof/spin_lock_sparse/
Luis
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Context imbalance false positive
2008-07-17 23:52 Context imbalance false positive Luis R. Rodriguez
@ 2008-07-18 8:25 ` Johannes Berg
2008-07-18 14:25 ` Luis R. Rodriguez
0 siblings, 1 reply; 3+ messages in thread
From: Johannes Berg @ 2008-07-18 8:25 UTC (permalink / raw)
To: Luis R. Rodriguez; +Cc: linux-sparse
[-- Attachment #1: Type: text/plain, Size: 461 bytes --]
On Thu, 2008-07-17 at 16:52 -0700, Luis R. Rodriguez wrote:
> I'm not sure how to resolve a situation like this:
> static void lock(int bh_flag)
> {
> if (bh_flag)
> spin_lock_bh(&some_lock);
> else
> spin_lock(&some_lock);
The only generally accepted way is to not program locking dependent on
flags.
You can sneak in sparse annotations to do it anyway, but I won't tell
you how :)
johannes
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Context imbalance false positive
2008-07-18 8:25 ` Johannes Berg
@ 2008-07-18 14:25 ` Luis R. Rodriguez
0 siblings, 0 replies; 3+ messages in thread
From: Luis R. Rodriguez @ 2008-07-18 14:25 UTC (permalink / raw)
To: Johannes Berg; +Cc: linux-sparse
On Fri, Jul 18, 2008 at 1:25 AM, Johannes Berg
<johannes@sipsolutions.net> wrote:
> On Thu, 2008-07-17 at 16:52 -0700, Luis R. Rodriguez wrote:
>> I'm not sure how to resolve a situation like this:
>
>> static void lock(int bh_flag)
>> {
>> if (bh_flag)
>> spin_lock_bh(&some_lock);
>> else
>> spin_lock(&some_lock);
>
> The only generally accepted way is to not program locking dependent on
> flags.
Agreed, and that's what I'm trying to do actually. I think the above
is pure absolute garbage.
> You can sneak in sparse annotations to do it anyway, but I won't tell
> you how :)
If you mean by __acquires() and __releases() then that didn't help.
Luis
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-07-18 14:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-17 23:52 Context imbalance false positive Luis R. Rodriguez
2008-07-18 8:25 ` Johannes Berg
2008-07-18 14:25 ` Luis R. Rodriguez
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).