All of lore.kernel.org
 help / color / mirror / Atom feed
From: <xkernel.wang@foxmail.com>
To: <akpm@linux-foundation.org>
Cc: <glider@google.com>, <andreyknvl@gmail.com>, <elver@google.com>,
	<dvyukov@google.com>, <ryabinin.a.a@gmail.com>,
	<kasan-dev@googlegroups.com>, <linux-mm@kvack.org>,
	<linux-kernel@vger.kernel.org>, <xkernel.wang@foxmail.com>
Subject: Re: [PATCH] lib/test_meminit: add checks for the allocation functions
Date: Mon, 26 Sep 2022 11:16:37 +0800	[thread overview]
Message-ID: <tencent_F9A4327FE4DE726C503C873F2871FF0F810A@qq.com> (raw)
In-Reply-To: <tencent_D44A49FFB420EDCCBFB9221C8D14DFE12908@qq.com>

Hi Andrew,

This patch seems to have been forgotten.

Regards,
Xiaoke Wang

On Friday, March 4, 2022 5:12 PM, <xkernel.wang@foxmail.com> wrote:
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
> 
> alloc_pages(), kmalloc() and vmalloc() are all memory allocation
> functions which can return NULL when some internal memory failures
> happen. So it is better to check the return of them to catch the failure
> in time for better test them.
> 
> Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
> ---
>  lib/test_meminit.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/lib/test_meminit.c b/lib/test_meminit.c
> index e4f706a..2f4c4bc 100644
> --- a/lib/test_meminit.c
> +++ b/lib/test_meminit.c
> @@ -67,17 +67,24 @@ static int __init do_alloc_pages_order(int order, int
> *total_failures)
>  	size_t size = PAGE_SIZE << order;
> 
>  	page = alloc_pages(GFP_KERNEL, order);
> +	if (!page)
> +		goto err;
>  	buf = page_address(page);
>  	fill_with_garbage(buf, size);
>  	__free_pages(page, order);
> 
>  	page = alloc_pages(GFP_KERNEL, order);
> +	if (!page)
> +		goto err;
>  	buf = page_address(page);
>  	if (count_nonzero_bytes(buf, size))
>  		(*total_failures)++;
>  	fill_with_garbage(buf, size);
>  	__free_pages(page, order);
>  	return 1;
> +err:
> +	(*total_failures)++;
> +	return 1;
>  }
> 
>  /* Test the page allocator by calling alloc_pages with different orders. */
> @@ -100,15 +107,22 @@ static int __init do_kmalloc_size(size_t size, int
> *total_failures)
>  	void *buf;
> 
>  	buf = kmalloc(size, GFP_KERNEL);
> +	if (!buf)
> +		goto err;
>  	fill_with_garbage(buf, size);
>  	kfree(buf);
> 
>  	buf = kmalloc(size, GFP_KERNEL);
> +	if (!buf)
> +		goto err;
>  	if (count_nonzero_bytes(buf, size))
>  		(*total_failures)++;
>  	fill_with_garbage(buf, size);
>  	kfree(buf);
>  	return 1;
> +err:
> +	(*total_failures)++;
> +	return 1;
>  }
> 
>  /* Test vmalloc() with given parameters. */
> @@ -117,15 +131,22 @@ static int __init do_vmalloc_size(size_t size, int
> *total_failures)
>  	void *buf;
> 
>  	buf = vmalloc(size);
> +	if (!buf)
> +		goto err;
>  	fill_with_garbage(buf, size);
>  	vfree(buf);
> 
>  	buf = vmalloc(size);
> +	if (!buf)
> +		goto err;
>  	if (count_nonzero_bytes(buf, size))
>  		(*total_failures)++;
>  	fill_with_garbage(buf, size);
>  	vfree(buf);
>  	return 1;
> +err:
> +	(*total_failures)++;
> +	return 1;
>  }
> 
>  /* Test kmalloc()/vmalloc() by allocating objects of different sizes. */
> --


      parent reply	other threads:[~2022-09-26  3:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-04  9:12 [PATCH] lib/test_meminit: add checks for the allocation functions xkernel.wang
2022-03-07 14:13 ` Alexander Potapenko
2022-09-26  3:16 ` xkernel.wang [this message]

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=tencent_F9A4327FE4DE726C503C873F2871FF0F810A@qq.com \
    --to=xkernel.wang@foxmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@gmail.com \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=glider@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ryabinin.a.a@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 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.