linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Yang Xiao <YangX92@hotmail.com>
Cc: "linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH] fs: namespace: convert mnt_namespace.count from atomic_t to refcount_t
Date: Wed, 28 Nov 2018 14:33:13 +0000	[thread overview]
Message-ID: <20181128143313.GF2217@ZenIV.linux.org.uk> (raw)
In-Reply-To: <HK0PR01MB2163CC40FE7D44C73668C462ADD10@HK0PR01MB2163.apcprd01.prod.exchangelabs.com>

On Wed, Nov 28, 2018 at 07:30:10AM +0000, Yang Xiao wrote:
> From: Young Xiao <YangX92@hotmail.com>
> 
> refcount_t type and corresponding API should be
					^^^^^^
					ITYM "could"
> used instead of atomic_t when the variable is used as
> a reference counter. This allows to avoid accidental
> refcounter overflows that might lead to use-after-free
> situations.


>  static inline void get_mnt_ns(struct mnt_namespace *ns)
>  {
> -	atomic_inc(&ns->count);
> +	if (ns)
> +		refcount_inc(&ns->count);
>  }

And this can be called with NULL ns... how, exactly?

>  void put_mnt_ns(struct mnt_namespace *ns)
>  {
> -	if (!atomic_dec_and_test(&ns->count))
> +	if (!ns || !refcount_dec_and_test(&ns->count))
>  		return;

Ditto.  Incidentally, if you are into "defensive programming"
voodoo, how do you choose between checking for NULL and checking
for ERR_PTR(...)?

This kind of "just in case" stuff has its place, but it should
never be used mindlessly.  NAK, unless you add a decent analysis
of the situation and a better rationale.

       reply	other threads:[~2018-11-29  1:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <HK0PR01MB2163CC40FE7D44C73668C462ADD10@HK0PR01MB2163.apcprd01.prod.exchangelabs.com>
2018-11-28 14:33 ` Al Viro [this message]
     [not found]   ` <HK0PR01MB21631393517B7937AF3FB55CADD20@HK0PR01MB2163.apcprd01.prod.exchangelabs.com>
2018-11-29  3:08     ` [PATCH] fs: namespace: convert mnt_namespace.count from atomic_t to refcount_t Al Viro

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=20181128143313.GF2217@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=YangX92@hotmail.com \
    --cc=linux-fsdevel@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).