linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: "Aurélien Aptel" <aaptel@suse.com>
Cc: linux-sparse@vger.kernel.org
Subject: Re: using sparse to catch refcount leaks
Date: Fri, 10 Jul 2020 11:59:27 +0300	[thread overview]
Message-ID: <20200710085927.GN2549@kadam> (raw)
In-Reply-To: <871rlk6630.fsf@suse.com>

On Thu, Jul 09, 2020 at 05:50:11PM +0200, Aurélien Aptel wrote:
> Hi,
> 
> I was thinking the same mechanism for lock checks (lock() has matching
> unlock()) could be used for detecting refcount leaks (get() has matching
> put()).
> 
> This could be used to catch bugs like that:
> 
> https://lore.kernel.org/linux-cifs/CAH2r5mtJg0OONLuAYmcggj=M3euDDxRa3Y5-_W1=qxwbeZypqA@mail.gmail.com/T/#mf0e0397aa0b63043d7b3bb0981f0b7323713bfdc

You might be better off copying the Smatch's locking test instead of
Sparse's.  Smatch does cross function flow analysis which can help.

In this CIFS case, the leak is on the success path (as well as the
failure path) so my theory would be that it would be caught in testing
and will only cause false positives for static analysis.  I can't see
any automated way to know which success paths should take a reference
and which should not.

regards,
dan carpenter


  parent reply	other threads:[~2020-07-10  9:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-09 15:50 using sparse to catch refcount leaks Aurélien Aptel
2020-07-09 18:48 ` Luc Van Oostenryck
2020-07-10  8:59 ` Dan Carpenter [this message]
2020-07-13 10:50   ` Aurélien Aptel

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=20200710085927.GN2549@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=aaptel@suse.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 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).