diff options
author | Patrick McHardy <kaber@trash.net> | 2007-12-18 01:41:21 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-01-28 17:59:02 -0500 |
commit | baab2ce7d2a8dbf6280ab09c011cfec1dd5972de (patch) | |
tree | 60cc03f14468a7244ae49a621eaeb8f2dbac84e9 /net/netfilter | |
parent | 1792bab4caaa85bae858799bb6231f171f59b58a (diff) |
[NETFILTER]: nfnetlink_{queue,log}: return proper error codes in instance_create
Currently we return EINVAL for "instance exists", "allocation failed" and
"module unloaded below us", which is completely inapproriate.
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/netfilter')
-rw-r--r-- | net/netfilter/nfnetlink_log.c | 14 | ||||
-rw-r--r-- | net/netfilter/nfnetlink_queue.c | 21 |
2 files changed, 23 insertions, 12 deletions
diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c index c12e1d1bd00..ac58dc9d724 100644 --- a/net/netfilter/nfnetlink_log.c +++ b/net/netfilter/nfnetlink_log.c | |||
@@ -128,19 +128,23 @@ static struct nfulnl_instance * | |||
128 | instance_create(u_int16_t group_num, int pid) | 128 | instance_create(u_int16_t group_num, int pid) |
129 | { | 129 | { |
130 | struct nfulnl_instance *inst; | 130 | struct nfulnl_instance *inst; |
131 | int err; | ||
131 | 132 | ||
132 | write_lock_bh(&instances_lock); | 133 | write_lock_bh(&instances_lock); |
133 | if (__instance_lookup(group_num)) { | 134 | if (__instance_lookup(group_num)) { |
134 | inst = NULL; | 135 | err = -EEXIST; |
135 | goto out_unlock; | 136 | goto out_unlock; |
136 | } | 137 | } |
137 | 138 | ||
138 | inst = kzalloc(sizeof(*inst), GFP_ATOMIC); | 139 | inst = kzalloc(sizeof(*inst), GFP_ATOMIC); |
139 | if (!inst) | 140 | if (!inst) { |
141 | err = -ENOMEM; | ||
140 | goto out_unlock; | 142 | goto out_unlock; |
143 | } | ||
141 | 144 | ||
142 | if (!try_module_get(THIS_MODULE)) { | 145 | if (!try_module_get(THIS_MODULE)) { |
143 | kfree(inst); | 146 | kfree(inst); |
147 | err = -EAGAIN; | ||
144 | goto out_unlock; | 148 | goto out_unlock; |
145 | } | 149 | } |
146 | 150 | ||
@@ -169,7 +173,7 @@ instance_create(u_int16_t group_num, int pid) | |||
169 | 173 | ||
170 | out_unlock: | 174 | out_unlock: |
171 | write_unlock_bh(&instances_lock); | 175 | write_unlock_bh(&instances_lock); |
172 | return NULL; | 176 | return ERR_PTR(err); |
173 | } | 177 | } |
174 | 178 | ||
175 | static void __nfulnl_flush(struct nfulnl_instance *inst); | 179 | static void __nfulnl_flush(struct nfulnl_instance *inst); |
@@ -731,8 +735,8 @@ nfulnl_recv_config(struct sock *ctnl, struct sk_buff *skb, | |||
731 | 735 | ||
732 | inst = instance_create(group_num, | 736 | inst = instance_create(group_num, |
733 | NETLINK_CB(skb).pid); | 737 | NETLINK_CB(skb).pid); |
734 | if (!inst) { | 738 | if (IS_ERR(inst)) { |
735 | ret = -EINVAL; | 739 | ret = PTR_ERR(inst); |
736 | goto out; | 740 | goto out; |
737 | } | 741 | } |
738 | break; | 742 | break; |
diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c index 370f0af50f4..51476f82bb5 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c | |||
@@ -89,16 +89,21 @@ instance_lookup(u_int16_t queue_num) | |||
89 | static struct nfqnl_instance * | 89 | static struct nfqnl_instance * |
90 | instance_create(u_int16_t queue_num, int pid) | 90 | instance_create(u_int16_t queue_num, int pid) |
91 | { | 91 | { |
92 | struct nfqnl_instance *inst = NULL; | 92 | struct nfqnl_instance *inst; |
93 | unsigned int h; | 93 | unsigned int h; |
94 | int err; | ||
94 | 95 | ||
95 | spin_lock(&instances_lock); | 96 | spin_lock(&instances_lock); |
96 | if (instance_lookup(queue_num)) | 97 | if (instance_lookup(queue_num)) { |
98 | err = -EEXIST; | ||
97 | goto out_unlock; | 99 | goto out_unlock; |
100 | } | ||
98 | 101 | ||
99 | inst = kzalloc(sizeof(*inst), GFP_ATOMIC); | 102 | inst = kzalloc(sizeof(*inst), GFP_ATOMIC); |
100 | if (!inst) | 103 | if (!inst) { |
104 | err = -ENOMEM; | ||
101 | goto out_unlock; | 105 | goto out_unlock; |
106 | } | ||
102 | 107 | ||
103 | inst->queue_num = queue_num; | 108 | inst->queue_num = queue_num; |
104 | inst->peer_pid = pid; | 109 | inst->peer_pid = pid; |
@@ -109,8 +114,10 @@ instance_create(u_int16_t queue_num, int pid) | |||
109 | INIT_LIST_HEAD(&inst->queue_list); | 114 | INIT_LIST_HEAD(&inst->queue_list); |
110 | INIT_RCU_HEAD(&inst->rcu); | 115 | INIT_RCU_HEAD(&inst->rcu); |
111 | 116 | ||
112 | if (!try_module_get(THIS_MODULE)) | 117 | if (!try_module_get(THIS_MODULE)) { |
118 | err = -EAGAIN; | ||
113 | goto out_free; | 119 | goto out_free; |
120 | } | ||
114 | 121 | ||
115 | h = instance_hashfn(queue_num); | 122 | h = instance_hashfn(queue_num); |
116 | hlist_add_head_rcu(&inst->hlist, &instance_table[h]); | 123 | hlist_add_head_rcu(&inst->hlist, &instance_table[h]); |
@@ -123,7 +130,7 @@ out_free: | |||
123 | kfree(inst); | 130 | kfree(inst); |
124 | out_unlock: | 131 | out_unlock: |
125 | spin_unlock(&instances_lock); | 132 | spin_unlock(&instances_lock); |
126 | return NULL; | 133 | return ERR_PTR(err); |
127 | } | 134 | } |
128 | 135 | ||
129 | static void nfqnl_flush(struct nfqnl_instance *queue, nfqnl_cmpfn cmpfn, | 136 | static void nfqnl_flush(struct nfqnl_instance *queue, nfqnl_cmpfn cmpfn, |
@@ -724,8 +731,8 @@ nfqnl_recv_config(struct sock *ctnl, struct sk_buff *skb, | |||
724 | goto err_out_unlock; | 731 | goto err_out_unlock; |
725 | } | 732 | } |
726 | queue = instance_create(queue_num, NETLINK_CB(skb).pid); | 733 | queue = instance_create(queue_num, NETLINK_CB(skb).pid); |
727 | if (!queue) { | 734 | if (IS_ERR(queue)) { |
728 | ret = -EINVAL; | 735 | ret = PTR_ERR(queue); |
729 | goto err_out_unlock; | 736 | goto err_out_unlock; |
730 | } | 737 | } |
731 | break; | 738 | break; |