2009-07-27 16:19:15

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 11/12] net/netlabel: Correct redundant test

From: Julia Lawall <[email protected]>

entry was tested for NULL near the beginning of the function, followed by a
return, and there is no intervening modification of its value.

A simplified version of the semantic match that finds this problem is as
follows: (http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@r exists@
local idexpression x;
expression E;
position p1,p2;
@@

if (x == NULL || ...) { ... when forall
return ...; }
... when != \(x=E\|x--\|x++\|--x\|++x\|x-=E\|x+=E\|x|=E\|x&=E\|&x\)
(
*x == NULL
|
*x != NULL
)
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
net/netlabel/netlabel_kapi.c | 6 ++----
1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/net/netlabel/netlabel_kapi.c b/net/netlabel/netlabel_kapi.c
index b0e582f..3ff6f32 100644
--- a/net/netlabel/netlabel_kapi.c
+++ b/net/netlabel/netlabel_kapi.c
@@ -185,8 +185,7 @@ int netlbl_cfg_unlbl_map_add(const char *domain,
return 0;

cfg_unlbl_map_add_failure:
- if (entry != NULL)
- kfree(entry->domain);
+ kfree(entry->domain);
kfree(entry);
kfree(addrmap);
kfree(map4);
@@ -385,8 +384,7 @@ int netlbl_cfg_cipsov4_map_add(u32 doi,

cfg_cipsov4_map_add_failure:
cipso_v4_doi_putdef(doi_def);
- if (entry != NULL)
- kfree(entry->domain);
+ kfree(entry->domain);
kfree(entry);
kfree(addrmap);
kfree(addrinfo);


2009-07-27 17:38:05

by Paul Moore

[permalink] [raw]
Subject: Re: [PATCH 11/12] net/netlabel: Correct redundant test

On Monday 27 July 2009 12:15:43 pm Julia Lawall wrote:
> From: Julia Lawall <[email protected]>
>
> entry was tested for NULL near the beginning of the function, followed by a
> return, and there is no intervening modification of its value.
>
> A simplified version of the semantic match that finds this problem is as
> follows: (http://www.emn.fr/x-info/coccinelle/)
>
> // <smpl>
> @r exists@
> local idexpression x;
> expression E;
> position p1,p2;
> @@
>
> if (x == NULL || ...) { ... when forall
> return ...; }
> ... when != \(x=E\|x--\|x++\|--x\|++x\|x-=E\|x+=E\|x|=E\|x&=E\|&x\)
> (
> *x == NULL
>
> *x != NULL
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <[email protected]>

Good catch, thanks.

Acked-by: Paul Moore <[email protected]>

> ---
> net/netlabel/netlabel_kapi.c | 6 ++----
> 1 files changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/net/netlabel/netlabel_kapi.c b/net/netlabel/netlabel_kapi.c
> index b0e582f..3ff6f32 100644
> --- a/net/netlabel/netlabel_kapi.c
> +++ b/net/netlabel/netlabel_kapi.c
> @@ -185,8 +185,7 @@ int netlbl_cfg_unlbl_map_add(const char *domain,
> return 0;
>
> cfg_unlbl_map_add_failure:
> - if (entry != NULL)
> - kfree(entry->domain);
> + kfree(entry->domain);
> kfree(entry);
> kfree(addrmap);
> kfree(map4);
> @@ -385,8 +384,7 @@ int netlbl_cfg_cipsov4_map_add(u32 doi,
>
> cfg_cipsov4_map_add_failure:
> cipso_v4_doi_putdef(doi_def);
> - if (entry != NULL)
> - kfree(entry->domain);
> + kfree(entry->domain);
> kfree(entry);
> kfree(addrmap);
> kfree(addrinfo);

--
paul moore
linux @ hp

2009-07-27 18:36:17

by David Miller

[permalink] [raw]
Subject: Re: [PATCH 11/12] net/netlabel: Correct redundant test

From: Paul Moore <[email protected]>
Date: Mon, 27 Jul 2009 13:37:29 -0400

> On Monday 27 July 2009 12:15:43 pm Julia Lawall wrote:
>> From: Julia Lawall <[email protected]>
>>
>> entry was tested for NULL near the beginning of the function, followed by a
>> return, and there is no intervening modification of its value.
>>
>> A simplified version of the semantic match that finds this problem is as
>> follows: (http://www.emn.fr/x-info/coccinelle/)
...
>> Signed-off-by: Julia Lawall <[email protected]>
>
> Good catch, thanks.
>
> Acked-by: Paul Moore <[email protected]>

Applied to net-next-2.6