instance_create(u_int16_t group_num, int pid)
{
struct nfulnl_instance *inst;
+ int err;
write_lock_bh(&instances_lock);
if (__instance_lookup(group_num)) {
- inst = NULL;
+ err = -EEXIST;
goto out_unlock;
}
inst = kzalloc(sizeof(*inst), GFP_ATOMIC);
- if (!inst)
+ if (!inst) {
+ err = -ENOMEM;
goto out_unlock;
+ }
if (!try_module_get(THIS_MODULE)) {
kfree(inst);
+ err = -EAGAIN;
goto out_unlock;
}
out_unlock:
write_unlock_bh(&instances_lock);
- return NULL;
+ return ERR_PTR(err);
}
static void __nfulnl_flush(struct nfulnl_instance *inst);
inst = instance_create(group_num,
NETLINK_CB(skb).pid);
- if (!inst) {
- ret = -EINVAL;
+ if (IS_ERR(inst)) {
+ ret = PTR_ERR(inst);
goto out;
}
break;
static struct nfqnl_instance *
instance_create(u_int16_t queue_num, int pid)
{
- struct nfqnl_instance *inst = NULL;
+ struct nfqnl_instance *inst;
unsigned int h;
+ int err;
spin_lock(&instances_lock);
- if (instance_lookup(queue_num))
+ if (instance_lookup(queue_num)) {
+ err = -EEXIST;
goto out_unlock;
+ }
inst = kzalloc(sizeof(*inst), GFP_ATOMIC);
- if (!inst)
+ if (!inst) {
+ err = -ENOMEM;
goto out_unlock;
+ }
inst->queue_num = queue_num;
inst->peer_pid = pid;
INIT_LIST_HEAD(&inst->queue_list);
INIT_RCU_HEAD(&inst->rcu);
- if (!try_module_get(THIS_MODULE))
+ if (!try_module_get(THIS_MODULE)) {
+ err = -EAGAIN;
goto out_free;
+ }
h = instance_hashfn(queue_num);
hlist_add_head_rcu(&inst->hlist, &instance_table[h]);
kfree(inst);
out_unlock:
spin_unlock(&instances_lock);
- return NULL;
+ return ERR_PTR(err);
}
static void nfqnl_flush(struct nfqnl_instance *queue, nfqnl_cmpfn cmpfn,
goto err_out_unlock;
}
queue = instance_create(queue_num, NETLINK_CB(skb).pid);
- if (!queue) {
- ret = -EINVAL;
+ if (IS_ERR(queue)) {
+ ret = PTR_ERR(queue);
goto err_out_unlock;
}
break;