diff options
author | Julia Lawall <julia.lawall@lip6.fr> | 2016-11-11 07:32:38 -0500 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2016-11-13 16:26:13 -0500 |
commit | eb1a6bdc28268afa964e4c9f3399961dff9fd691 (patch) | |
tree | 65f4441a51bb69fa64b659bfe64a3d53c066a2bd | |
parent | 7e416ad7416307e22871a0ef0f0f14e2bb66a0d1 (diff) |
netfilter: x_tables: simplify IS_ERR_OR_NULL to NULL test
Since commit 7926dbfa4bc1 ("netfilter: don't use
mutex_lock_interruptible()"), the function xt_find_table_lock can only
return NULL on an error. Simplify the call sites and update the
comment before the function.
The semantic patch that change the code is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@@
expression t,e;
@@
t = \(xt_find_table_lock(...)\|
try_then_request_module(xt_find_table_lock(...),...)\)
... when != t=e
- ! IS_ERR_OR_NULL(t)
+ t
@@
expression t,e;
@@
t = \(xt_find_table_lock(...)\|
try_then_request_module(xt_find_table_lock(...),...)\)
... when != t=e
- IS_ERR_OR_NULL(t)
+ !t
@@
expression t,e,e1;
@@
t = \(xt_find_table_lock(...)\|
try_then_request_module(xt_find_table_lock(...),...)\)
... when != t=e
?- t ? PTR_ERR(t) : e1
+ e1
... when any
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r-- | net/ipv4/netfilter/arp_tables.c | 20 | ||||
-rw-r--r-- | net/ipv4/netfilter/ip_tables.c | 20 | ||||
-rw-r--r-- | net/ipv6/netfilter/ip6_tables.c | 20 | ||||
-rw-r--r-- | net/netfilter/x_tables.c | 2 |
4 files changed, 31 insertions, 31 deletions
diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c index e76ab23a2deb..39004da318e2 100644 --- a/net/ipv4/netfilter/arp_tables.c +++ b/net/ipv4/netfilter/arp_tables.c | |||
@@ -805,7 +805,7 @@ static int get_info(struct net *net, void __user *user, | |||
805 | #endif | 805 | #endif |
806 | t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name), | 806 | t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name), |
807 | "arptable_%s", name); | 807 | "arptable_%s", name); |
808 | if (!IS_ERR_OR_NULL(t)) { | 808 | if (t) { |
809 | struct arpt_getinfo info; | 809 | struct arpt_getinfo info; |
810 | const struct xt_table_info *private = t->private; | 810 | const struct xt_table_info *private = t->private; |
811 | #ifdef CONFIG_COMPAT | 811 | #ifdef CONFIG_COMPAT |
@@ -834,7 +834,7 @@ static int get_info(struct net *net, void __user *user, | |||
834 | xt_table_unlock(t); | 834 | xt_table_unlock(t); |
835 | module_put(t->me); | 835 | module_put(t->me); |
836 | } else | 836 | } else |
837 | ret = t ? PTR_ERR(t) : -ENOENT; | 837 | ret = -ENOENT; |
838 | #ifdef CONFIG_COMPAT | 838 | #ifdef CONFIG_COMPAT |
839 | if (compat) | 839 | if (compat) |
840 | xt_compat_unlock(NFPROTO_ARP); | 840 | xt_compat_unlock(NFPROTO_ARP); |
@@ -859,7 +859,7 @@ static int get_entries(struct net *net, struct arpt_get_entries __user *uptr, | |||
859 | get.name[sizeof(get.name) - 1] = '\0'; | 859 | get.name[sizeof(get.name) - 1] = '\0'; |
860 | 860 | ||
861 | t = xt_find_table_lock(net, NFPROTO_ARP, get.name); | 861 | t = xt_find_table_lock(net, NFPROTO_ARP, get.name); |
862 | if (!IS_ERR_OR_NULL(t)) { | 862 | if (t) { |
863 | const struct xt_table_info *private = t->private; | 863 | const struct xt_table_info *private = t->private; |
864 | 864 | ||
865 | if (get.size == private->size) | 865 | if (get.size == private->size) |
@@ -871,7 +871,7 @@ static int get_entries(struct net *net, struct arpt_get_entries __user *uptr, | |||
871 | module_put(t->me); | 871 | module_put(t->me); |
872 | xt_table_unlock(t); | 872 | xt_table_unlock(t); |
873 | } else | 873 | } else |
874 | ret = t ? PTR_ERR(t) : -ENOENT; | 874 | ret = -ENOENT; |
875 | 875 | ||
876 | return ret; | 876 | return ret; |
877 | } | 877 | } |
@@ -898,8 +898,8 @@ static int __do_replace(struct net *net, const char *name, | |||
898 | 898 | ||
899 | t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name), | 899 | t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name), |
900 | "arptable_%s", name); | 900 | "arptable_%s", name); |
901 | if (IS_ERR_OR_NULL(t)) { | 901 | if (!t) { |
902 | ret = t ? PTR_ERR(t) : -ENOENT; | 902 | ret = -ENOENT; |
903 | goto free_newinfo_counters_untrans; | 903 | goto free_newinfo_counters_untrans; |
904 | } | 904 | } |
905 | 905 | ||
@@ -1014,8 +1014,8 @@ static int do_add_counters(struct net *net, const void __user *user, | |||
1014 | return PTR_ERR(paddc); | 1014 | return PTR_ERR(paddc); |
1015 | 1015 | ||
1016 | t = xt_find_table_lock(net, NFPROTO_ARP, tmp.name); | 1016 | t = xt_find_table_lock(net, NFPROTO_ARP, tmp.name); |
1017 | if (IS_ERR_OR_NULL(t)) { | 1017 | if (!t) { |
1018 | ret = t ? PTR_ERR(t) : -ENOENT; | 1018 | ret = -ENOENT; |
1019 | goto free; | 1019 | goto free; |
1020 | } | 1020 | } |
1021 | 1021 | ||
@@ -1404,7 +1404,7 @@ static int compat_get_entries(struct net *net, | |||
1404 | 1404 | ||
1405 | xt_compat_lock(NFPROTO_ARP); | 1405 | xt_compat_lock(NFPROTO_ARP); |
1406 | t = xt_find_table_lock(net, NFPROTO_ARP, get.name); | 1406 | t = xt_find_table_lock(net, NFPROTO_ARP, get.name); |
1407 | if (!IS_ERR_OR_NULL(t)) { | 1407 | if (t) { |
1408 | const struct xt_table_info *private = t->private; | 1408 | const struct xt_table_info *private = t->private; |
1409 | struct xt_table_info info; | 1409 | struct xt_table_info info; |
1410 | 1410 | ||
@@ -1419,7 +1419,7 @@ static int compat_get_entries(struct net *net, | |||
1419 | module_put(t->me); | 1419 | module_put(t->me); |
1420 | xt_table_unlock(t); | 1420 | xt_table_unlock(t); |
1421 | } else | 1421 | } else |
1422 | ret = t ? PTR_ERR(t) : -ENOENT; | 1422 | ret = -ENOENT; |
1423 | 1423 | ||
1424 | xt_compat_unlock(NFPROTO_ARP); | 1424 | xt_compat_unlock(NFPROTO_ARP); |
1425 | return ret; | 1425 | return ret; |
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c index de4fa03f46f3..46815c8a60d7 100644 --- a/net/ipv4/netfilter/ip_tables.c +++ b/net/ipv4/netfilter/ip_tables.c | |||
@@ -973,7 +973,7 @@ static int get_info(struct net *net, void __user *user, | |||
973 | #endif | 973 | #endif |
974 | t = try_then_request_module(xt_find_table_lock(net, AF_INET, name), | 974 | t = try_then_request_module(xt_find_table_lock(net, AF_INET, name), |
975 | "iptable_%s", name); | 975 | "iptable_%s", name); |
976 | if (!IS_ERR_OR_NULL(t)) { | 976 | if (t) { |
977 | struct ipt_getinfo info; | 977 | struct ipt_getinfo info; |
978 | const struct xt_table_info *private = t->private; | 978 | const struct xt_table_info *private = t->private; |
979 | #ifdef CONFIG_COMPAT | 979 | #ifdef CONFIG_COMPAT |
@@ -1003,7 +1003,7 @@ static int get_info(struct net *net, void __user *user, | |||
1003 | xt_table_unlock(t); | 1003 | xt_table_unlock(t); |
1004 | module_put(t->me); | 1004 | module_put(t->me); |
1005 | } else | 1005 | } else |
1006 | ret = t ? PTR_ERR(t) : -ENOENT; | 1006 | ret = -ENOENT; |
1007 | #ifdef CONFIG_COMPAT | 1007 | #ifdef CONFIG_COMPAT |
1008 | if (compat) | 1008 | if (compat) |
1009 | xt_compat_unlock(AF_INET); | 1009 | xt_compat_unlock(AF_INET); |
@@ -1028,7 +1028,7 @@ get_entries(struct net *net, struct ipt_get_entries __user *uptr, | |||
1028 | get.name[sizeof(get.name) - 1] = '\0'; | 1028 | get.name[sizeof(get.name) - 1] = '\0'; |
1029 | 1029 | ||
1030 | t = xt_find_table_lock(net, AF_INET, get.name); | 1030 | t = xt_find_table_lock(net, AF_INET, get.name); |
1031 | if (!IS_ERR_OR_NULL(t)) { | 1031 | if (t) { |
1032 | const struct xt_table_info *private = t->private; | 1032 | const struct xt_table_info *private = t->private; |
1033 | if (get.size == private->size) | 1033 | if (get.size == private->size) |
1034 | ret = copy_entries_to_user(private->size, | 1034 | ret = copy_entries_to_user(private->size, |
@@ -1039,7 +1039,7 @@ get_entries(struct net *net, struct ipt_get_entries __user *uptr, | |||
1039 | module_put(t->me); | 1039 | module_put(t->me); |
1040 | xt_table_unlock(t); | 1040 | xt_table_unlock(t); |
1041 | } else | 1041 | } else |
1042 | ret = t ? PTR_ERR(t) : -ENOENT; | 1042 | ret = -ENOENT; |
1043 | 1043 | ||
1044 | return ret; | 1044 | return ret; |
1045 | } | 1045 | } |
@@ -1064,8 +1064,8 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks, | |||
1064 | 1064 | ||
1065 | t = try_then_request_module(xt_find_table_lock(net, AF_INET, name), | 1065 | t = try_then_request_module(xt_find_table_lock(net, AF_INET, name), |
1066 | "iptable_%s", name); | 1066 | "iptable_%s", name); |
1067 | if (IS_ERR_OR_NULL(t)) { | 1067 | if (!t) { |
1068 | ret = t ? PTR_ERR(t) : -ENOENT; | 1068 | ret = -ENOENT; |
1069 | goto free_newinfo_counters_untrans; | 1069 | goto free_newinfo_counters_untrans; |
1070 | } | 1070 | } |
1071 | 1071 | ||
@@ -1180,8 +1180,8 @@ do_add_counters(struct net *net, const void __user *user, | |||
1180 | return PTR_ERR(paddc); | 1180 | return PTR_ERR(paddc); |
1181 | 1181 | ||
1182 | t = xt_find_table_lock(net, AF_INET, tmp.name); | 1182 | t = xt_find_table_lock(net, AF_INET, tmp.name); |
1183 | if (IS_ERR_OR_NULL(t)) { | 1183 | if (!t) { |
1184 | ret = t ? PTR_ERR(t) : -ENOENT; | 1184 | ret = -ENOENT; |
1185 | goto free; | 1185 | goto free; |
1186 | } | 1186 | } |
1187 | 1187 | ||
@@ -1626,7 +1626,7 @@ compat_get_entries(struct net *net, struct compat_ipt_get_entries __user *uptr, | |||
1626 | 1626 | ||
1627 | xt_compat_lock(AF_INET); | 1627 | xt_compat_lock(AF_INET); |
1628 | t = xt_find_table_lock(net, AF_INET, get.name); | 1628 | t = xt_find_table_lock(net, AF_INET, get.name); |
1629 | if (!IS_ERR_OR_NULL(t)) { | 1629 | if (t) { |
1630 | const struct xt_table_info *private = t->private; | 1630 | const struct xt_table_info *private = t->private; |
1631 | struct xt_table_info info; | 1631 | struct xt_table_info info; |
1632 | ret = compat_table_info(private, &info); | 1632 | ret = compat_table_info(private, &info); |
@@ -1640,7 +1640,7 @@ compat_get_entries(struct net *net, struct compat_ipt_get_entries __user *uptr, | |||
1640 | module_put(t->me); | 1640 | module_put(t->me); |
1641 | xt_table_unlock(t); | 1641 | xt_table_unlock(t); |
1642 | } else | 1642 | } else |
1643 | ret = t ? PTR_ERR(t) : -ENOENT; | 1643 | ret = -ENOENT; |
1644 | 1644 | ||
1645 | xt_compat_unlock(AF_INET); | 1645 | xt_compat_unlock(AF_INET); |
1646 | return ret; | 1646 | return ret; |
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c index 7eac01d5d621..6ff42b8301cc 100644 --- a/net/ipv6/netfilter/ip6_tables.c +++ b/net/ipv6/netfilter/ip6_tables.c | |||
@@ -1003,7 +1003,7 @@ static int get_info(struct net *net, void __user *user, | |||
1003 | #endif | 1003 | #endif |
1004 | t = try_then_request_module(xt_find_table_lock(net, AF_INET6, name), | 1004 | t = try_then_request_module(xt_find_table_lock(net, AF_INET6, name), |
1005 | "ip6table_%s", name); | 1005 | "ip6table_%s", name); |
1006 | if (!IS_ERR_OR_NULL(t)) { | 1006 | if (t) { |
1007 | struct ip6t_getinfo info; | 1007 | struct ip6t_getinfo info; |
1008 | const struct xt_table_info *private = t->private; | 1008 | const struct xt_table_info *private = t->private; |
1009 | #ifdef CONFIG_COMPAT | 1009 | #ifdef CONFIG_COMPAT |
@@ -1033,7 +1033,7 @@ static int get_info(struct net *net, void __user *user, | |||
1033 | xt_table_unlock(t); | 1033 | xt_table_unlock(t); |
1034 | module_put(t->me); | 1034 | module_put(t->me); |
1035 | } else | 1035 | } else |
1036 | ret = t ? PTR_ERR(t) : -ENOENT; | 1036 | ret = -ENOENT; |
1037 | #ifdef CONFIG_COMPAT | 1037 | #ifdef CONFIG_COMPAT |
1038 | if (compat) | 1038 | if (compat) |
1039 | xt_compat_unlock(AF_INET6); | 1039 | xt_compat_unlock(AF_INET6); |
@@ -1059,7 +1059,7 @@ get_entries(struct net *net, struct ip6t_get_entries __user *uptr, | |||
1059 | get.name[sizeof(get.name) - 1] = '\0'; | 1059 | get.name[sizeof(get.name) - 1] = '\0'; |
1060 | 1060 | ||
1061 | t = xt_find_table_lock(net, AF_INET6, get.name); | 1061 | t = xt_find_table_lock(net, AF_INET6, get.name); |
1062 | if (!IS_ERR_OR_NULL(t)) { | 1062 | if (t) { |
1063 | struct xt_table_info *private = t->private; | 1063 | struct xt_table_info *private = t->private; |
1064 | if (get.size == private->size) | 1064 | if (get.size == private->size) |
1065 | ret = copy_entries_to_user(private->size, | 1065 | ret = copy_entries_to_user(private->size, |
@@ -1070,7 +1070,7 @@ get_entries(struct net *net, struct ip6t_get_entries __user *uptr, | |||
1070 | module_put(t->me); | 1070 | module_put(t->me); |
1071 | xt_table_unlock(t); | 1071 | xt_table_unlock(t); |
1072 | } else | 1072 | } else |
1073 | ret = t ? PTR_ERR(t) : -ENOENT; | 1073 | ret = -ENOENT; |
1074 | 1074 | ||
1075 | return ret; | 1075 | return ret; |
1076 | } | 1076 | } |
@@ -1095,8 +1095,8 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks, | |||
1095 | 1095 | ||
1096 | t = try_then_request_module(xt_find_table_lock(net, AF_INET6, name), | 1096 | t = try_then_request_module(xt_find_table_lock(net, AF_INET6, name), |
1097 | "ip6table_%s", name); | 1097 | "ip6table_%s", name); |
1098 | if (IS_ERR_OR_NULL(t)) { | 1098 | if (!t) { |
1099 | ret = t ? PTR_ERR(t) : -ENOENT; | 1099 | ret = -ENOENT; |
1100 | goto free_newinfo_counters_untrans; | 1100 | goto free_newinfo_counters_untrans; |
1101 | } | 1101 | } |
1102 | 1102 | ||
@@ -1210,8 +1210,8 @@ do_add_counters(struct net *net, const void __user *user, unsigned int len, | |||
1210 | if (IS_ERR(paddc)) | 1210 | if (IS_ERR(paddc)) |
1211 | return PTR_ERR(paddc); | 1211 | return PTR_ERR(paddc); |
1212 | t = xt_find_table_lock(net, AF_INET6, tmp.name); | 1212 | t = xt_find_table_lock(net, AF_INET6, tmp.name); |
1213 | if (IS_ERR_OR_NULL(t)) { | 1213 | if (!t) { |
1214 | ret = t ? PTR_ERR(t) : -ENOENT; | 1214 | ret = -ENOENT; |
1215 | goto free; | 1215 | goto free; |
1216 | } | 1216 | } |
1217 | 1217 | ||
@@ -1647,7 +1647,7 @@ compat_get_entries(struct net *net, struct compat_ip6t_get_entries __user *uptr, | |||
1647 | 1647 | ||
1648 | xt_compat_lock(AF_INET6); | 1648 | xt_compat_lock(AF_INET6); |
1649 | t = xt_find_table_lock(net, AF_INET6, get.name); | 1649 | t = xt_find_table_lock(net, AF_INET6, get.name); |
1650 | if (!IS_ERR_OR_NULL(t)) { | 1650 | if (t) { |
1651 | const struct xt_table_info *private = t->private; | 1651 | const struct xt_table_info *private = t->private; |
1652 | struct xt_table_info info; | 1652 | struct xt_table_info info; |
1653 | ret = compat_table_info(private, &info); | 1653 | ret = compat_table_info(private, &info); |
@@ -1661,7 +1661,7 @@ compat_get_entries(struct net *net, struct compat_ip6t_get_entries __user *uptr, | |||
1661 | module_put(t->me); | 1661 | module_put(t->me); |
1662 | xt_table_unlock(t); | 1662 | xt_table_unlock(t); |
1663 | } else | 1663 | } else |
1664 | ret = t ? PTR_ERR(t) : -ENOENT; | 1664 | ret = -ENOENT; |
1665 | 1665 | ||
1666 | xt_compat_unlock(AF_INET6); | 1666 | xt_compat_unlock(AF_INET6); |
1667 | return ret; | 1667 | return ret; |
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c index fc4977456c30..ad818e52859b 100644 --- a/net/netfilter/x_tables.c +++ b/net/netfilter/x_tables.c | |||
@@ -982,7 +982,7 @@ void xt_free_table_info(struct xt_table_info *info) | |||
982 | } | 982 | } |
983 | EXPORT_SYMBOL(xt_free_table_info); | 983 | EXPORT_SYMBOL(xt_free_table_info); |
984 | 984 | ||
985 | /* Find table by name, grabs mutex & ref. Returns ERR_PTR() on error. */ | 985 | /* Find table by name, grabs mutex & ref. Returns NULL on error. */ |
986 | struct xt_table *xt_find_table_lock(struct net *net, u_int8_t af, | 986 | struct xt_table *xt_find_table_lock(struct net *net, u_int8_t af, |
987 | const char *name) | 987 | const char *name) |
988 | { | 988 | { |