All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: "Aurélien Aptel" <aaptel@suse.com>
Cc: linux-sparse@vger.kernel.org
Subject: Re: using sparse to catch refcount leaks
Date: Thu, 9 Jul 2020 20:48:13 +0200	[thread overview]
Message-ID: <20200709184813.765ebmlta7mojqad@ltop.local> (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

Absolutely.
Sparse's 'context' can be reused for refcounting (conceptually,
it's quite similar to locking). You can even simply reuse the
existing macros __acquires(), ...

That's said, I suppose that in the present case the 'get' is done
by cifs_sb_tlink(). This corresponds to a 'conditional context'
(see __cond_lock()) which somehow annoying to use. I've some
patches improving things here but they need some more work.

Cheers,
-- Luc

  reply	other threads:[~2020-07-09 18:48 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 [this message]
2020-07-10  8:59 ` Dan Carpenter
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=20200709184813.765ebmlta7mojqad@ltop.local \
    --to=luc.vanoostenryck@gmail.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 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.