linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lib/test_meminit: add checks for the allocation functions
@ 2022-03-04  9:12 xkernel.wang
  2022-03-07 14:13 ` Alexander Potapenko
  2022-09-26  3:16 ` xkernel.wang
  0 siblings, 2 replies; 3+ messages in thread
From: xkernel.wang @ 2022-03-04  9:12 UTC (permalink / raw)
  To: glider, akpm
  Cc: andreyknvl, elver, dvyukov, ryabinin.a.a, kasan-dev, linux-mm,
	linux-kernel, Xiaoke Wang

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. */
-- 


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] lib/test_meminit: add checks for the allocation functions
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Alexander Potapenko @ 2022-03-07 14:13 UTC (permalink / raw)
  To: xkernel.wang
  Cc: Andrew Morton, Andrey Konovalov, Marco Elver, Dmitriy Vyukov,
	Andrey Ryabinin, kasan-dev, Linux Memory Management List, LKML

[-- Attachment #1: Type: text/plain, Size: 3674 bytes --]

On Fri, Mar 4, 2022 at 10:13 AM <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>
>
Reviewed-by: Alexander Potapenko <glider@google.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. */
> --
>


-- 
Alexander Potapenko
Software Engineer

Google Germany GmbH
Erika-Mann-Straße, 33
80636 München

Geschäftsführer: Paul Manicle, Liana Sebastian
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg

Diese E-Mail ist vertraulich. Falls Sie diese fälschlicherweise erhalten
haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter,
löschen Sie alle Kopien und Anhänge davon und lassen Sie mich bitte wissen,
dass die E-Mail an die falsche Person gesendet wurde.



This e-mail is confidential. If you received this communication by mistake,
please don't forward it to anyone else, please erase all copies and
attachments, and please let me know that it has gone to the wrong person.

[-- Attachment #2: Type: text/html, Size: 4859 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] lib/test_meminit: add checks for the allocation functions
  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
  1 sibling, 0 replies; 3+ messages in thread
From: xkernel.wang @ 2022-09-26  3:16 UTC (permalink / raw)
  To: akpm
  Cc: glider, andreyknvl, elver, dvyukov, ryabinin.a.a, kasan-dev,
	linux-mm, linux-kernel, xkernel.wang

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. */
> --



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-26  3:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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).