linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Barry Song <21cnbao@gmail.com>
To: "刘海龙(LaoLiu)" <liuhailong@oppo.com>
Cc: "akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"urezki@gmail.com" <urezki@gmail.com>,
	 "hch@infradead.org" <hch@infradead.org>,
	"lstoakes@gmail.com" <lstoakes@gmail.com>,
	 "linux-mm@kvack.org" <linux-mm@kvack.org>,
	 "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] mm/vmalloc: Fix return value check for vb_alloc
Date: Wed, 28 Feb 2024 22:39:41 +1300	[thread overview]
Message-ID: <CAGsJ_4w+L03rPcFbLm4E5sWixkKLizB4vxR-Z6LHbqwV56vB4w@mail.gmail.com> (raw)
In-Reply-To: <CAGsJ_4w_itxmZR7ytu7HnptQNZQzM-vAJhE_zSZrTAH1iqBV6g@mail.gmail.com>

On Wed, Feb 28, 2024 at 10:34 PM Barry Song <21cnbao@gmail.com> wrote:
>
> On Wed, Feb 28, 2024 at 9:51 PM 刘海龙(LaoLiu) <liuhailong@oppo.com> wrote:
> >
> > If vm_map_ram(page, 0, 0) would cause panic by vmap_pages_range_noflush, so
> > change IS_ERR to IS_ERR_OR_NULL to fix this.
> >
> > Signed-off-by: Hailong.Liu <liuhailong@oppo.com>
> > ---
> >  mm/vmalloc.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> > index d12a17fc0c17..109732006cf7 100644
> > --- a/mm/vmalloc.c
> > +++ b/mm/vmalloc.c
> > @@ -2387,7 +2387,7 @@ void *vm_map_ram(struct page **pages, unsigned int
> > count, int node)
> >
> >         if (likely(count <= VMAP_MAX_ALLOC)) {
> >                 mem = vb_alloc(size, GFP_KERNEL);
> > -               if (IS_ERR(mem))
> > +               if (IS_ERR_OR_NULL(mem))
>
> it seems the only case for vb_alloc to return NULL is size = 0, isn't
> it a bug of
> caller?

what about the below?

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 25a8df497255..640157221c95 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2834,6 +2834,9 @@ void *vm_map_ram(struct page **pages, unsigned
int count, int node)
        unsigned long addr;
        void *mem;

+       if (unlikely(count == 0))
+               return NULL;
+
        if (likely(count <= VMAP_MAX_ALLOC)) {
                mem = vb_alloc(size, GFP_KERNEL);
                if (IS_ERR(mem))


>
> >                         return NULL;
> >                 addr = (unsigned long)mem;
> >         } else {
> > --
> > 2.34.1
Thanks
Barry


  reply	other threads:[~2024-02-28  9:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-28  8:50 刘海龙(LaoLiu)
2024-02-28  9:34 ` Barry Song
2024-02-28  9:39   ` Barry Song [this message]
2024-02-28 10:02   ` 刘海龙(LaoLiu)
2024-02-28 10:09     ` Barry Song

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=CAGsJ_4w+L03rPcFbLm4E5sWixkKLizB4vxR-Z6LHbqwV56vB4w@mail.gmail.com \
    --to=21cnbao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liuhailong@oppo.com \
    --cc=lstoakes@gmail.com \
    --cc=urezki@gmail.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