@@ -1585,22 +1585,18 @@ static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
if (ret == 0) {
int new_index;
new_index = nbd_dev_add(-1);
- if (new_index < 0) {
- mutex_unlock(&nbd_index_mutex);
- printk(KERN_ERR "nbd: failed to add new device\n");
- return ret;
- }
+ if (new_index < 0)
+ goto report_failure;
+
nbd = idr_find(&nbd_index_idr, new_index);
}
} else {
nbd = idr_find(&nbd_index_idr, index);
if (!nbd) {
ret = nbd_dev_add(index);
- if (ret < 0) {
- mutex_unlock(&nbd_index_mutex);
- printk(KERN_ERR "nbd: failed to add new device\n");
- return ret;
- }
+ if (ret < 0)
+ goto report_failure;
+
nbd = idr_find(&nbd_index_idr, index);
}
}
@@ -1716,6 +1712,11 @@ static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
if (put_dev)
nbd_put(nbd);
return ret;
+
+report_failure:
+ mutex_unlock(&nbd_index_mutex);
+ pr_err("nbd: failed to add new device\n");
+ return ret;
}
static int nbd_genl_disconnect(struct sk_buff *skb, struct genl_info *info)