diff mbox

[v2,08/36] target: Rework the transport_alloc_session_tags() error path

Message ID 20170202005853.23456-9-bart.vanassche@sandisk.com (mailing list archive)
State Superseded
Headers show

Commit Message

Bart Van Assche Feb. 2, 2017, 12:58 a.m. UTC
Move error handling code to the end of the function. Return the
percpu_ida_init() return value instead of -ENOMEM if
percpu_ida_init() fails.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
---
 drivers/target/target_core_transport.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

Comments

Christoph Hellwig Feb. 6, 2017, 9:07 a.m. UTC | #1
Looks fine,

Reviewed-by: Christoph Hellwig <hch@lst.de>
--
To unsubscribe from this list: send the line "unsubscribe target-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 1cadc9eefa21..ab4051fbab95 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -248,7 +248,7 @@  EXPORT_SYMBOL(transport_init_session);
 int transport_alloc_session_tags(struct se_session *se_sess,
 			         unsigned int tag_num, unsigned int tag_size)
 {
-	int rc;
+	int rc = -ENOMEM;
 
 	se_sess->sess_cmd_map = kzalloc(tag_num * tag_size,
 					GFP_KERNEL | __GFP_NOWARN | __GFP_REPEAT);
@@ -256,20 +256,24 @@  int transport_alloc_session_tags(struct se_session *se_sess,
 		se_sess->sess_cmd_map = vzalloc(tag_num * tag_size);
 		if (!se_sess->sess_cmd_map) {
 			pr_err("Unable to allocate se_sess->sess_cmd_map\n");
-			return -ENOMEM;
+			goto out;
 		}
 	}
 
 	rc = percpu_ida_init(&se_sess->sess_tag_pool, tag_num);
 	if (rc < 0) {
-		pr_err("Unable to init se_sess->sess_tag_pool,"
-			" tag_num: %u\n", tag_num);
-		kvfree(se_sess->sess_cmd_map);
-		se_sess->sess_cmd_map = NULL;
-		return -ENOMEM;
+		pr_err("Unable to init se_sess->sess_tag_pool, tag_num: %u\n",
+		       tag_num);
+		goto free_cmd_map;
 	}
 
-	return 0;
+out:
+	return rc;
+
+free_cmd_map:
+	kvfree(se_sess->sess_cmd_map);
+	se_sess->sess_cmd_map = NULL;
+	goto out;
 }
 EXPORT_SYMBOL(transport_alloc_session_tags);