linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Chen Wandun <chenwandun@huawei.com>
Cc: hughd@google.com, akpm@linux-foundation.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, david@redhat.com,
	wangkefeng.wang@huawei.com
Subject: Re: [PATCH v2 1/3] mm/shmem: check return value of shmem_init_inodecache
Date: Mon, 6 Jun 2022 03:08:58 +0100	[thread overview]
Message-ID: <Yp1hujqmnbUmVKSc@casper.infradead.org> (raw)
In-Reply-To: <aaebf2a5-026b-54f8-3fad-8e9611732e5e@huawei.com>

On Mon, Jun 06, 2022 at 09:34:13AM +0800, Chen Wandun wrote:
> On 2022/6/5 19:49, Matthew Wilcox wrote:
> > On Sun, Jun 05, 2022 at 11:55:55AM +0800, Chen Wandun wrote:
> > > It will result in null pointer access if shmem_init_inodecache fail,
> > > so check return value of shmem_init_inodecache
> > You ignored my suggestion from v1.  Here, let me write it out for you.
> Hi Matthew,
> I didn't ignore your suggestion,  some explanation is needed, sorry for
> that.
> 
> In V1, Kefeng point:
> "kmem_cache_create return a pointer to the cache on success, NULL on
> failure,
> so error = -ENOMEM; is right :)"
> 
> so, I look some similar code such as init_inodecache in kinds of file
> system,  they all
> return -ENOMEM on failure, so is it OK to return -ENOMEM on failure :)
> 
> Besides,  kmem_cache_create return NULL on failure, maybe returning error
> code
> on failure is more proper, but it is another job.

I literally wrote out what I think you should do instead.  Stop arguing.

> > +static int shmem_init_inodecache(void)
> >   {
> >    	shmem_inode_cachep = kmem_cache_create("shmem_inode_cache",
> >    				sizeof(struct shmem_inode_info),
> >    				0, SLAB_PANIC|SLAB_ACCOUNT, shmem_init_inode);
> > +	if (!shmem_inode_cachep)
> > +		return -ENOMEM;
> > +	return 0;
> >   }
> > 
> > ...
> > 
> > +	error = shmem_init_inodecache();
> > +	if (error)
> > +		goto out2;
> > 
> > 
> > .
> 

  reply	other threads:[~2022-06-06  2:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-05  3:55 [PATCH v2 0/3] a few cleanup and bugfixes about shmem Chen Wandun
2022-06-05  3:55 ` [PATCH v2 1/3] mm/shmem: check return value of shmem_init_inodecache Chen Wandun
2022-06-05 11:49   ` Matthew Wilcox
2022-06-06  1:34     ` Chen Wandun
2022-06-06  2:08       ` Matthew Wilcox [this message]
2022-06-06  2:58         ` Chen Wandun
2022-06-05  3:55 ` [PATCH v2 2/3] mm/shmem: return error code directly for invalid addr Chen Wandun
2022-06-05  3:55 ` [PATCH v2 3/3] mm/shmem: rework calculation of inflated_addr in shmem_get_unmapped_area Chen Wandun

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=Yp1hujqmnbUmVKSc@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=chenwandun@huawei.com \
    --cc=david@redhat.com \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=wangkefeng.wang@huawei.com \
    /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).