linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josh Triplett <josh@joshtriplett.org>
To: Larry Finger <Larry.Finger@lwfinger.net>
Cc: Christopher Li <sparse@chrisli.org>,
	Linux-Sparse <linux-sparse@vger.kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: False warning from Sparse
Date: Sat, 21 Jul 2012 21:44:21 -0700	[thread overview]
Message-ID: <20120722044421.GA3934@leaf> (raw)
In-Reply-To: <500B7916.6060804@lwfinger.net>

On Sat, Jul 21, 2012 at 10:52:54PM -0500, Larry Finger wrote:
> I am getting the following false warning from sparse:
> 
>   CHECK   drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
> drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c:1158:13: warning:
> context imbalance in 'rtl92c_dm_refresh_rate_adaptive_mask' -
> different lock contexts for basic block
> 
> The only code in that routine that does any locking is the following:
> 
>              /* Only the PCI card uses sta in the update rate table
>               * callback routine */
>              if (rtlhal->interface == INTF_PCI) {
>                      rcu_read_lock();
>                      sta = ieee80211_find_sta(mac->vif, mac->bssid);
>              }
>              rtlpriv->cfg->ops->update_rate_tbl(hw, sta,
>                                   p_ra->ratr_state);
> 
>              p_ra->pre_ratr_state = p_ra->ratr_state;
>              if (rtlhal->interface == INTF_PCI)
>                      rcu_read_unlock();
> 
> Does the warning get output because the code cannot assume that
> rtlhal->interface is the same in both if statements?

Correct; sparse does not have enough dataflow analysis to connect the
two if bodies, nor can it verify that nothing between the two changes
rtlhal->interface.

> If that is the
> case, are there any compiler directives that would tell sparse of
> the situation?

No, none of Sparse's directives will let you override this.  However,
you could do something like the following:

              /* Only the PCI card uses sta in the update rate table
               * callback routine */
              if (rtlhal->interface == INTF_PCI) {
                      rcu_read_lock();
                      sta = ieee80211_find_sta(mac->vif, mac->bssid);
                      rtlpriv->cfg->ops->update_rate_tbl(hw, sta, p_ra->ratr_state);
                      p_ra->pre_ratr_state = p_ra->ratr_state;
                      rcu_read_unlock();
              } else {
                      rtlpriv->cfg->ops->update_rate_tbl(hw, sta, p_ra->ratr_state);
                      p_ra->pre_ratr_state = p_ra->ratr_state;
              }

You could wrap those two lines in a function if you don't want to
duplicate them.

If that solution or a similar refactoring doesn't appeal to you, then
you don't currently have any way of making that context warning go away,
short of improving Sparse to handle this situation better.

- Josh Triplett

      reply	other threads:[~2012-07-22  4:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-22  3:52 False warning from Sparse Larry Finger
2012-07-22  4:44 ` Josh Triplett [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=20120722044421.GA3934@leaf \
    --to=josh@joshtriplett.org \
    --cc=Larry.Finger@lwfinger.net \
    --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 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).