2014-07-19 11:34:13

by Himangi Saraogi

[permalink] [raw]
Subject: [PATCH] uml/net_kern: Eliminate NULL test after alloc_bootmem

alloc_bootmem and related functions never return NULL. Thus a NULL
test or memset after calls to these functions is unnecessary.

The following Coccinelle semantic patch was used for making the change:

@@
expression E;
statement S;
@@

E = \(alloc_bootmem\|alloc_bootmem_low\|alloc_bootmem_pages\|alloc_bootmem_low_pages\)(...)
... when != E
- if (E == NULL) S

Signed-off-by: Himangi Saraogi <[email protected]>
Acked-by: Julia Lawall <[email protected]>
---
arch/um/drivers/net_kern.c | 4 ----
1 file changed, 4 deletions(-)

diff --git a/arch/um/drivers/net_kern.c b/arch/um/drivers/net_kern.c
index 7d26d9c..f70dd54 100644
--- a/arch/um/drivers/net_kern.c
+++ b/arch/um/drivers/net_kern.c
@@ -659,10 +659,6 @@ static int __init eth_setup(char *str)
}

new = alloc_bootmem(sizeof(*new));
- if (new == NULL) {
- printk(KERN_ERR "eth_init : alloc_bootmem failed\n");
- return 1;
- }

INIT_LIST_HEAD(&new->list);
new->index = n;
--
1.9.1


2014-07-23 22:24:35

by Richard Weinberger

[permalink] [raw]
Subject: Re: [PATCH] uml/net_kern: Eliminate NULL test after alloc_bootmem

Himangi,

Am 19.07.2014 13:34, schrieb Himangi Saraogi:
> alloc_bootmem and related functions never return NULL. Thus a NULL
> test or memset after calls to these functions is unnecessary.
>
> The following Coccinelle semantic patch was used for making the change:
>
> @@
> expression E;
> statement S;
> @@
>
> E = \(alloc_bootmem\|alloc_bootmem_low\|alloc_bootmem_pages\|alloc_bootmem_low_pages\)(...)
> ... when != E
> - if (E == NULL) S
>
> Signed-off-by: Himangi Saraogi <[email protected]>
> Acked-by: Julia Lawall <[email protected]>

Thank you! All three patches are now queued for 3.17.

Thanks,
//richard

> ---
> arch/um/drivers/net_kern.c | 4 ----
> 1 file changed, 4 deletions(-)
>
> diff --git a/arch/um/drivers/net_kern.c b/arch/um/drivers/net_kern.c
> index 7d26d9c..f70dd54 100644
> --- a/arch/um/drivers/net_kern.c
> +++ b/arch/um/drivers/net_kern.c
> @@ -659,10 +659,6 @@ static int __init eth_setup(char *str)
> }
>
> new = alloc_bootmem(sizeof(*new));
> - if (new == NULL) {
> - printk(KERN_ERR "eth_init : alloc_bootmem failed\n");
> - return 1;
> - }
>
> INIT_LIST_HEAD(&new->list);
> new->index = n;
>