All of lore.kernel.org
 help / color / mirror / Atom feed
From: Larry Finger <Larry.Finger@lwfinger.net>
To: Josh Triplett <josh@joshtriplett.org>
Cc: Christopher Li <sparse@chrisli.org>,
	Linux-Sparse <linux-sparse@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: sparse: possible false report of context imbalance
Date: Thu, 17 Oct 2013 12:41:01 -0500	[thread overview]
Message-ID: <5260212D.2090905@lwfinger.net> (raw)
In-Reply-To: <20131017162551.GA4123@jtriplet-mobl1>

On 10/17/2013 11:25 AM, Josh Triplett wrote:
> On Wed, Oct 16, 2013 at 10:23:56PM -0500, Larry Finger wrote:
>> Sparse reports the following:
>>
>>    CHECK   drivers/staging/rtl8188eu/core/rtw_mlme.c
>> drivers/staging/rtl8188eu/core/rtw_mlme.c:1003:9: warning: context
>> imbalance in 'rtw_free_assoc_resources' - different lock contexts
>> for basic block
>>
>> The code in question is as follows:
>>
>>          if (lock_scanned_queue)
>>                  spin_lock_bh(&(pmlmepriv->scanned_queue.lock));
>>
>>          pwlan = rtw_find_network(&pmlmepriv->scanned_queue,
>> tgt_network->network.MacAddress);
>>
>>          if (lock_scanned_queue)
>>                  spin_unlock_bh(&(pmlmepriv->scanned_queue.lock));
>>
>> As this fragment uses the identical test to unlock that is used to
>> lock, and the test variable is not touched, I think this is a false
>> indication. I am using version 0.4.4 of sparse.
>
> Sparse can't track conditional contexts like this; sparse intentionally
> complains here that you're running the same basic block (the
> rtw_find_network call) with and without a lock held.
>
> The following workaround works when this is legitimate, though it isn't
> ideal:
>
> if (condition) {
> 	lock
> 	do_thing
> 	unlock
> } else {
> 	do_thing
> }
>
> Ideally, Sparse should be able to track conditional contexts, but that
> would require some form of abstract evaluation, or as a simplistic hack,
> looking for identical side-effect-free conditional expressions.

Thanks for the answer, which is about what I expected. Sparse is a great tool, 
particularly for endian-related issues.

Larry


      reply	other threads:[~2013-10-17 17:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-17  3:23 sparse: possible false report of context imbalance Larry Finger
2013-10-17 16:25 ` Josh Triplett
2013-10-17 17:41   ` Larry Finger [this message]

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=5260212D.2090905@lwfinger.net \
    --to=larry.finger@lwfinger.net \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=sparse@chrisli.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.