* [PATCH net-next] ipv4/netfilter: remove unnecessary goto statement for error recovery
@ 2012-08-20 1:11 Jean Sacren
2012-08-22 22:33 ` Pablo Neira Ayuso
0 siblings, 1 reply; 3+ messages in thread
From: Jean Sacren @ 2012-08-20 1:11 UTC (permalink / raw)
To: netfilter-devel, netdev
Usually it's a good practice to use goto statement for error recovery
when initializing the module. This approach could be an overkill if:
1) there is only one fail case;
2) success and failure use the same return statement.
For a cleaner approach, remove the unnecessary goto statement and
directly implement error recovery.
Signed-off-by: Jean Sacren <sakiwit@gmail.com>
---
net/ipv4/netfilter/iptable_filter.c | 6 +-----
net/ipv4/netfilter/iptable_mangle.c | 6 +-----
net/ipv4/netfilter/iptable_raw.c | 6 +-----
3 files changed, 3 insertions(+), 15 deletions(-)
diff --git a/net/ipv4/netfilter/iptable_filter.c b/net/ipv4/netfilter/iptable_filter.c
index 851acec8..9255fd4 100644
--- a/net/ipv4/netfilter/iptable_filter.c
+++ b/net/ipv4/netfilter/iptable_filter.c
@@ -96,14 +96,10 @@ static int __init iptable_filter_init(void)
filter_ops = xt_hook_link(&packet_filter, iptable_filter_hook);
if (IS_ERR(filter_ops)) {
ret = PTR_ERR(filter_ops);
- goto cleanup_table;
+ unregister_pernet_subsys(&iptable_filter_net_ops);
}
return ret;
-
- cleanup_table:
- unregister_pernet_subsys(&iptable_filter_net_ops);
- return ret;
}
static void __exit iptable_filter_fini(void)
diff --git a/net/ipv4/netfilter/iptable_mangle.c b/net/ipv4/netfilter/iptable_mangle.c
index aef5d1f..25549c5 100644
--- a/net/ipv4/netfilter/iptable_mangle.c
+++ b/net/ipv4/netfilter/iptable_mangle.c
@@ -131,14 +131,10 @@ static int __init iptable_mangle_init(void)
mangle_ops = xt_hook_link(&packet_mangler, iptable_mangle_hook);
if (IS_ERR(mangle_ops)) {
ret = PTR_ERR(mangle_ops);
- goto cleanup_table;
+ unregister_pernet_subsys(&iptable_mangle_net_ops);
}
return ret;
-
- cleanup_table:
- unregister_pernet_subsys(&iptable_mangle_net_ops);
- return ret;
}
static void __exit iptable_mangle_fini(void)
diff --git a/net/ipv4/netfilter/iptable_raw.c b/net/ipv4/netfilter/iptable_raw.c
index 07fb710..6acf7ca 100644
--- a/net/ipv4/netfilter/iptable_raw.c
+++ b/net/ipv4/netfilter/iptable_raw.c
@@ -75,14 +75,10 @@ static int __init iptable_raw_init(void)
rawtable_ops = xt_hook_link(&packet_raw, iptable_raw_hook);
if (IS_ERR(rawtable_ops)) {
ret = PTR_ERR(rawtable_ops);
- goto cleanup_table;
+ unregister_pernet_subsys(&iptable_raw_net_ops);
}
return ret;
-
- cleanup_table:
- unregister_pernet_subsys(&iptable_raw_net_ops);
- return ret;
}
static void __exit iptable_raw_fini(void)
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH net-next] ipv4/netfilter: remove unnecessary goto statement for error recovery
@ 2012-08-20 2:43 Patrick McHardy
0 siblings, 0 replies; 3+ messages in thread
From: Patrick McHardy @ 2012-08-20 2:43 UTC (permalink / raw)
To: Jean Sacren; +Cc: netfilter-devel, netdev
> Usually it's a good practice to use goto statement for error recovery
> when initializing the module. This approach could be an overkill if:
>
> 1) there is only one fail case;
> 2) success and failure use the same return statement.
>
> For a cleaner approach, remove the unnecessary goto statement and
> directly implement error recovery.
We have tons of similar cases. And this is much better than directly
adding rollback since it doesn't require changing unrelated code if
anything new is added to the initialization code. Additionally its
usually directly comparable to the cleanup code.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] ipv4/netfilter: remove unnecessary goto statement for error recovery
2012-08-20 1:11 [PATCH net-next] ipv4/netfilter: remove unnecessary goto statement for error recovery Jean Sacren
@ 2012-08-22 22:33 ` Pablo Neira Ayuso
0 siblings, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2012-08-22 22:33 UTC (permalink / raw)
To: Jean Sacren; +Cc: netfilter-devel, netdev
On Sun, Aug 19, 2012 at 07:11:32PM -0600, Jean Sacren wrote:
> Usually it's a good practice to use goto statement for error recovery
> when initializing the module. This approach could be an overkill if:
>
> 1) there is only one fail case;
> 2) success and failure use the same return statement.
>
> For a cleaner approach, remove the unnecessary goto statement and
> directly implement error recovery.
Applied, thanks Jean.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-08-22 22:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-20 1:11 [PATCH net-next] ipv4/netfilter: remove unnecessary goto statement for error recovery Jean Sacren
2012-08-22 22:33 ` Pablo Neira Ayuso
-- strict thread matches above, loose matches on Subject: below --
2012-08-20 2:43 Patrick McHardy
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).