Skip to contentSkip to conversation

ipv4/netfilter: remove unnecessary goto statement for error recovery

PATCH Applied Jean Sacren 2 participants 2 messages Aug 20, 2012 – Aug 22, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipv4/netfilter: remove unnecessary goto statement for error recovery

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.

---
 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(-)
net/ipv4/netfilter/iptable_filter.c +1 -5
index 851acec8..9255fd4 100644
@@ -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)
net/ipv4/netfilter/iptable_mangle.c +1 -5
index aef5d1f..25549c5 100644
@@ -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)
net/ipv4/netfilter/iptable_raw.c +1 -5
index 07fb710..6acf7ca 100644
@@ -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)
maintainer Applied
#1 lore raw
Quoted 8 lines · Jean Sacren

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.