* [PATCH] net/netlabel/netlabel_kapi.c: add missing cleanup code
@ 2011-08-11 9:40 Julia Lawall
2011-08-11 9:44 ` Dan Carpenter
0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2011-08-11 9:40 UTC (permalink / raw)
To: Paul Moore; +Cc: kernel-janitors, David S. Miller, netdev, linux-kernel
From: Julia Lawall <julia@diku.dk>
Use the same cleanup code for the failure of kzalloc as for the failure of
kstrdup just below.
Signed-off-by: Julia Lawall <julia@diku.dk>
---
net/netlabel/netlabel_kapi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/netlabel/netlabel_kapi.c b/net/netlabel/netlabel_kapi.c
index 58107d0..225e12c 100644
--- a/net/netlabel/netlabel_kapi.c
+++ b/net/netlabel/netlabel_kapi.c
@@ -341,7 +341,7 @@ int netlbl_cfg_cipsov4_map_add(u32 doi,
entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
if (entry == NULL)
- return -ENOMEM;
+ goto cfg_cipsov4_map_add_failure;
if (domain != NULL) {
entry->domain = kstrdup(domain, GFP_ATOMIC);
if (entry->domain == NULL)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] net/netlabel/netlabel_kapi.c: add missing cleanup code
2011-08-11 9:40 [PATCH] net/netlabel/netlabel_kapi.c: add missing cleanup code Julia Lawall
@ 2011-08-11 9:44 ` Dan Carpenter
2011-08-11 9:52 ` Julia Lawall
0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2011-08-11 9:44 UTC (permalink / raw)
To: Julia Lawall
Cc: Paul Moore, kernel-janitors, David S. Miller, netdev,
linux-kernel
On Thu, Aug 11, 2011 at 11:40:33AM +0200, Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
>
> Use the same cleanup code for the failure of kzalloc as for the failure of
> kstrdup just below.
>
That doesn't work. The kfree(entry->domain) would cause an oops.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net/netlabel/netlabel_kapi.c: add missing cleanup code
2011-08-11 9:44 ` Dan Carpenter
@ 2011-08-11 9:52 ` Julia Lawall
2011-08-11 10:06 ` Julia Lawall
0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2011-08-11 9:52 UTC (permalink / raw)
To: Dan Carpenter
Cc: Paul Moore, kernel-janitors, David S. Miller, netdev,
linux-kernel
On Thu, 11 Aug 2011, Dan Carpenter wrote:
> On Thu, Aug 11, 2011 at 11:40:33AM +0200, Julia Lawall wrote:
> > From: Julia Lawall <julia@diku.dk>
> >
> > Use the same cleanup code for the failure of kzalloc as for the failure of
> > kstrdup just below.
> >
>
> That doesn't work. The kfree(entry->domain) would cause an oops.
Of course... Thanks!
julia
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net/netlabel/netlabel_kapi.c: add missing cleanup code
2011-08-11 9:52 ` Julia Lawall
@ 2011-08-11 10:06 ` Julia Lawall
2011-08-11 12:53 ` David Miller
0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2011-08-11 10:06 UTC (permalink / raw)
To: Dan Carpenter
Cc: Paul Moore, kernel-janitors, David S. Miller, netdev,
linux-kernel
From: Julia Lawall <julia@diku.dk>
Call cipso_v4_doi_putdef in the case of the failure of the allocation of
entry. Reverse the order of the error handling code at the end of the
function and insert more labels in order to reduce the number of
unnecessary calls to kfree.
Signed-off-by: Julia Lawall <julia@diku.dk>
---
net/netlabel/netlabel_kapi.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/net/netlabel/netlabel_kapi.c b/net/netlabel/netlabel_kapi.c
index 58107d0..9c24de1 100644
--- a/net/netlabel/netlabel_kapi.c
+++ b/net/netlabel/netlabel_kapi.c
@@ -341,11 +341,11 @@ int netlbl_cfg_cipsov4_map_add(u32 doi,
entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
if (entry == NULL)
- return -ENOMEM;
+ goto out_entry;
if (domain != NULL) {
entry->domain = kstrdup(domain, GFP_ATOMIC);
if (entry->domain == NULL)
- goto cfg_cipsov4_map_add_failure;
+ goto out_domain;
}
if (addr == NULL && mask == NULL) {
@@ -354,13 +354,13 @@ int netlbl_cfg_cipsov4_map_add(u32 doi,
} else if (addr != NULL && mask != NULL) {
addrmap = kzalloc(sizeof(*addrmap), GFP_ATOMIC);
if (addrmap == NULL)
- goto cfg_cipsov4_map_add_failure;
+ goto out_addrmap;
INIT_LIST_HEAD(&addrmap->list4);
INIT_LIST_HEAD(&addrmap->list6);
addrinfo = kzalloc(sizeof(*addrinfo), GFP_ATOMIC);
if (addrinfo == NULL)
- goto cfg_cipsov4_map_add_failure;
+ goto out_addrinfo;
addrinfo->type_def.cipsov4 = doi_def;
addrinfo->type = NETLBL_NLTYPE_CIPSOV4;
addrinfo->list.addr = addr->s_addr & mask->s_addr;
@@ -374,7 +374,7 @@ int netlbl_cfg_cipsov4_map_add(u32 doi,
entry->type = NETLBL_NLTYPE_ADDRSELECT;
} else {
ret_val = -EINVAL;
- goto cfg_cipsov4_map_add_failure;
+ goto out_addrmap;
}
ret_val = netlbl_domhsh_add(entry, audit_info);
@@ -384,11 +384,15 @@ int netlbl_cfg_cipsov4_map_add(u32 doi,
return 0;
cfg_cipsov4_map_add_failure:
- cipso_v4_doi_putdef(doi_def);
+ kfree(addrinfo);
+out_addrinfo:
+ kfree(addrmap);
+out_addrmap:
kfree(entry->domain);
+out_domain:
kfree(entry);
- kfree(addrmap);
- kfree(addrinfo);
+out_entry:
+ cipso_v4_doi_putdef(doi_def);
return ret_val;
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] net/netlabel/netlabel_kapi.c: add missing cleanup code
2011-08-11 10:06 ` Julia Lawall
@ 2011-08-11 12:53 ` David Miller
0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2011-08-11 12:53 UTC (permalink / raw)
To: julia; +Cc: error27, paul, kernel-janitors, netdev, linux-kernel
From: Julia Lawall <julia@diku.dk>
Date: Thu, 11 Aug 2011 12:06:04 +0200 (CEST)
> From: Julia Lawall <julia@diku.dk>
>
> Call cipso_v4_doi_putdef in the case of the failure of the allocation of
> entry. Reverse the order of the error handling code at the end of the
> function and insert more labels in order to reduce the number of
> unnecessary calls to kfree.
>
> Signed-off-by: Julia Lawall <julia@diku.dk>
Applied.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-08-11 12:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-11 9:40 [PATCH] net/netlabel/netlabel_kapi.c: add missing cleanup code Julia Lawall
2011-08-11 9:44 ` Dan Carpenter
2011-08-11 9:52 ` Julia Lawall
2011-08-11 10:06 ` Julia Lawall
2011-08-11 12:53 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox