Skip to content

Commit eb1a6bd

Browse files
JuliaLawallummakynes
authored andcommitted
netfilter: x_tables: simplify IS_ERR_OR_NULL to NULL test
Since commit 7926dbf ("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 <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 7e416ad commit eb1a6bd

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

net/ipv4/netfilter/arp_tables.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ static int get_info(struct net *net, void __user *user,
805805
#endif
806806
t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name),
807807
"arptable_%s", name);
808-
if (!IS_ERR_OR_NULL(t)) {
808+
if (t) {
809809
struct arpt_getinfo info;
810810
const struct xt_table_info *private = t->private;
811811
#ifdef CONFIG_COMPAT
@@ -834,7 +834,7 @@ static int get_info(struct net *net, void __user *user,
834834
xt_table_unlock(t);
835835
module_put(t->me);
836836
} else
837-
ret = t ? PTR_ERR(t) : -ENOENT;
837+
ret = -ENOENT;
838838
#ifdef CONFIG_COMPAT
839839
if (compat)
840840
xt_compat_unlock(NFPROTO_ARP);
@@ -859,7 +859,7 @@ static int get_entries(struct net *net, struct arpt_get_entries __user *uptr,
859859
get.name[sizeof(get.name) - 1] = '\0';
860860

861861
t = xt_find_table_lock(net, NFPROTO_ARP, get.name);
862-
if (!IS_ERR_OR_NULL(t)) {
862+
if (t) {
863863
const struct xt_table_info *private = t->private;
864864

865865
if (get.size == private->size)
@@ -871,7 +871,7 @@ static int get_entries(struct net *net, struct arpt_get_entries __user *uptr,
871871
module_put(t->me);
872872
xt_table_unlock(t);
873873
} else
874-
ret = t ? PTR_ERR(t) : -ENOENT;
874+
ret = -ENOENT;
875875

876876
return ret;
877877
}
@@ -898,8 +898,8 @@ static int __do_replace(struct net *net, const char *name,
898898

899899
t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name),
900900
"arptable_%s", name);
901-
if (IS_ERR_OR_NULL(t)) {
902-
ret = t ? PTR_ERR(t) : -ENOENT;
901+
if (!t) {
902+
ret = -ENOENT;
903903
goto free_newinfo_counters_untrans;
904904
}
905905

@@ -1014,8 +1014,8 @@ static int do_add_counters(struct net *net, const void __user *user,
10141014
return PTR_ERR(paddc);
10151015

10161016
t = xt_find_table_lock(net, NFPROTO_ARP, tmp.name);
1017-
if (IS_ERR_OR_NULL(t)) {
1018-
ret = t ? PTR_ERR(t) : -ENOENT;
1017+
if (!t) {
1018+
ret = -ENOENT;
10191019
goto free;
10201020
}
10211021

@@ -1404,7 +1404,7 @@ static int compat_get_entries(struct net *net,
14041404

14051405
xt_compat_lock(NFPROTO_ARP);
14061406
t = xt_find_table_lock(net, NFPROTO_ARP, get.name);
1407-
if (!IS_ERR_OR_NULL(t)) {
1407+
if (t) {
14081408
const struct xt_table_info *private = t->private;
14091409
struct xt_table_info info;
14101410

@@ -1419,7 +1419,7 @@ static int compat_get_entries(struct net *net,
14191419
module_put(t->me);
14201420
xt_table_unlock(t);
14211421
} else
1422-
ret = t ? PTR_ERR(t) : -ENOENT;
1422+
ret = -ENOENT;
14231423

14241424
xt_compat_unlock(NFPROTO_ARP);
14251425
return ret;

net/ipv4/netfilter/ip_tables.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ static int get_info(struct net *net, void __user *user,
973973
#endif
974974
t = try_then_request_module(xt_find_table_lock(net, AF_INET, name),
975975
"iptable_%s", name);
976-
if (!IS_ERR_OR_NULL(t)) {
976+
if (t) {
977977
struct ipt_getinfo info;
978978
const struct xt_table_info *private = t->private;
979979
#ifdef CONFIG_COMPAT
@@ -1003,7 +1003,7 @@ static int get_info(struct net *net, void __user *user,
10031003
xt_table_unlock(t);
10041004
module_put(t->me);
10051005
} else
1006-
ret = t ? PTR_ERR(t) : -ENOENT;
1006+
ret = -ENOENT;
10071007
#ifdef CONFIG_COMPAT
10081008
if (compat)
10091009
xt_compat_unlock(AF_INET);
@@ -1028,7 +1028,7 @@ get_entries(struct net *net, struct ipt_get_entries __user *uptr,
10281028
get.name[sizeof(get.name) - 1] = '\0';
10291029

10301030
t = xt_find_table_lock(net, AF_INET, get.name);
1031-
if (!IS_ERR_OR_NULL(t)) {
1031+
if (t) {
10321032
const struct xt_table_info *private = t->private;
10331033
if (get.size == private->size)
10341034
ret = copy_entries_to_user(private->size,
@@ -1039,7 +1039,7 @@ get_entries(struct net *net, struct ipt_get_entries __user *uptr,
10391039
module_put(t->me);
10401040
xt_table_unlock(t);
10411041
} else
1042-
ret = t ? PTR_ERR(t) : -ENOENT;
1042+
ret = -ENOENT;
10431043

10441044
return ret;
10451045
}
@@ -1064,8 +1064,8 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
10641064

10651065
t = try_then_request_module(xt_find_table_lock(net, AF_INET, name),
10661066
"iptable_%s", name);
1067-
if (IS_ERR_OR_NULL(t)) {
1068-
ret = t ? PTR_ERR(t) : -ENOENT;
1067+
if (!t) {
1068+
ret = -ENOENT;
10691069
goto free_newinfo_counters_untrans;
10701070
}
10711071

@@ -1180,8 +1180,8 @@ do_add_counters(struct net *net, const void __user *user,
11801180
return PTR_ERR(paddc);
11811181

11821182
t = xt_find_table_lock(net, AF_INET, tmp.name);
1183-
if (IS_ERR_OR_NULL(t)) {
1184-
ret = t ? PTR_ERR(t) : -ENOENT;
1183+
if (!t) {
1184+
ret = -ENOENT;
11851185
goto free;
11861186
}
11871187

@@ -1626,7 +1626,7 @@ compat_get_entries(struct net *net, struct compat_ipt_get_entries __user *uptr,
16261626

16271627
xt_compat_lock(AF_INET);
16281628
t = xt_find_table_lock(net, AF_INET, get.name);
1629-
if (!IS_ERR_OR_NULL(t)) {
1629+
if (t) {
16301630
const struct xt_table_info *private = t->private;
16311631
struct xt_table_info info;
16321632
ret = compat_table_info(private, &info);
@@ -1640,7 +1640,7 @@ compat_get_entries(struct net *net, struct compat_ipt_get_entries __user *uptr,
16401640
module_put(t->me);
16411641
xt_table_unlock(t);
16421642
} else
1643-
ret = t ? PTR_ERR(t) : -ENOENT;
1643+
ret = -ENOENT;
16441644

16451645
xt_compat_unlock(AF_INET);
16461646
return ret;

net/ipv6/netfilter/ip6_tables.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ static int get_info(struct net *net, void __user *user,
10031003
#endif
10041004
t = try_then_request_module(xt_find_table_lock(net, AF_INET6, name),
10051005
"ip6table_%s", name);
1006-
if (!IS_ERR_OR_NULL(t)) {
1006+
if (t) {
10071007
struct ip6t_getinfo info;
10081008
const struct xt_table_info *private = t->private;
10091009
#ifdef CONFIG_COMPAT
@@ -1033,7 +1033,7 @@ static int get_info(struct net *net, void __user *user,
10331033
xt_table_unlock(t);
10341034
module_put(t->me);
10351035
} else
1036-
ret = t ? PTR_ERR(t) : -ENOENT;
1036+
ret = -ENOENT;
10371037
#ifdef CONFIG_COMPAT
10381038
if (compat)
10391039
xt_compat_unlock(AF_INET6);
@@ -1059,7 +1059,7 @@ get_entries(struct net *net, struct ip6t_get_entries __user *uptr,
10591059
get.name[sizeof(get.name) - 1] = '\0';
10601060

10611061
t = xt_find_table_lock(net, AF_INET6, get.name);
1062-
if (!IS_ERR_OR_NULL(t)) {
1062+
if (t) {
10631063
struct xt_table_info *private = t->private;
10641064
if (get.size == private->size)
10651065
ret = copy_entries_to_user(private->size,
@@ -1070,7 +1070,7 @@ get_entries(struct net *net, struct ip6t_get_entries __user *uptr,
10701070
module_put(t->me);
10711071
xt_table_unlock(t);
10721072
} else
1073-
ret = t ? PTR_ERR(t) : -ENOENT;
1073+
ret = -ENOENT;
10741074

10751075
return ret;
10761076
}
@@ -1095,8 +1095,8 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
10951095

10961096
t = try_then_request_module(xt_find_table_lock(net, AF_INET6, name),
10971097
"ip6table_%s", name);
1098-
if (IS_ERR_OR_NULL(t)) {
1099-
ret = t ? PTR_ERR(t) : -ENOENT;
1098+
if (!t) {
1099+
ret = -ENOENT;
11001100
goto free_newinfo_counters_untrans;
11011101
}
11021102

@@ -1210,8 +1210,8 @@ do_add_counters(struct net *net, const void __user *user, unsigned int len,
12101210
if (IS_ERR(paddc))
12111211
return PTR_ERR(paddc);
12121212
t = xt_find_table_lock(net, AF_INET6, tmp.name);
1213-
if (IS_ERR_OR_NULL(t)) {
1214-
ret = t ? PTR_ERR(t) : -ENOENT;
1213+
if (!t) {
1214+
ret = -ENOENT;
12151215
goto free;
12161216
}
12171217

@@ -1647,7 +1647,7 @@ compat_get_entries(struct net *net, struct compat_ip6t_get_entries __user *uptr,
16471647

16481648
xt_compat_lock(AF_INET6);
16491649
t = xt_find_table_lock(net, AF_INET6, get.name);
1650-
if (!IS_ERR_OR_NULL(t)) {
1650+
if (t) {
16511651
const struct xt_table_info *private = t->private;
16521652
struct xt_table_info info;
16531653
ret = compat_table_info(private, &info);
@@ -1661,7 +1661,7 @@ compat_get_entries(struct net *net, struct compat_ip6t_get_entries __user *uptr,
16611661
module_put(t->me);
16621662
xt_table_unlock(t);
16631663
} else
1664-
ret = t ? PTR_ERR(t) : -ENOENT;
1664+
ret = -ENOENT;
16651665

16661666
xt_compat_unlock(AF_INET6);
16671667
return ret;

net/netfilter/x_tables.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ void xt_free_table_info(struct xt_table_info *info)
982982
}
983983
EXPORT_SYMBOL(xt_free_table_info);
984984

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. */
986986
struct xt_table *xt_find_table_lock(struct net *net, u_int8_t af,
987987
const char *name)
988988
{

0 commit comments

Comments
 (0)