From e3b9d00d97ff8553d6825a293ab7886e27c0ae16 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Wed, 11 Sep 2013 22:44:04 +0000 Subject: [PATCH] qla2x00t: Simplify q2t_create_sess() Replace a kmalloc() and sprintf() call by a kasprintf() call. This patch does not change any functionality. Signed-off-by: Bart Van Assche git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@4998 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- qla2x00t/qla2x00-target/qla2x00t.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/qla2x00t/qla2x00-target/qla2x00t.c b/qla2x00t/qla2x00-target/qla2x00t.c index 4b50449c5..291e5d580 100644 --- a/qla2x00t/qla2x00-target/qla2x00t.c +++ b/qla2x00t/qla2x00-target/qla2x00t.c @@ -1133,7 +1133,6 @@ static struct q2t_sess *q2t_create_sess(scsi_qla_host_t *ha, fc_port_t *fcport, bool local) { char *wwn_str; - const int wwn_str_len = 3*WWN_SIZE+2; struct q2t_tgt *tgt = ha->tgt; struct q2t_sess *sess; scsi_qla_host_t *pha = to_qla_parent(ha); @@ -1197,7 +1196,12 @@ static struct q2t_sess *q2t_create_sess(scsi_qla_host_t *ha, fc_port_t *fcport, BUILD_BUG_ON(sizeof(sess->port_name) != sizeof(fcport->port_name)); memcpy(sess->port_name, fcport->port_name, sizeof(sess->port_name)); - wwn_str = kmalloc(wwn_str_len, GFP_KERNEL); + wwn_str = kasprintf(GFP_KERNEL, + "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", + fcport->port_name[0], fcport->port_name[1], + fcport->port_name[2], fcport->port_name[3], + fcport->port_name[4], fcport->port_name[5], + fcport->port_name[6], fcport->port_name[7]); if (wwn_str == NULL) { PRINT_ERROR("qla2x00t(%ld): Allocation of wwn_str failed. " "All commands from port %02x:%02x:%02x:%02x:%02x:%02x:" @@ -1209,12 +1213,6 @@ static struct q2t_sess *q2t_create_sess(scsi_qla_host_t *ha, fc_port_t *fcport, goto out_free_sess; } - sprintf(wwn_str, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", - fcport->port_name[0], fcport->port_name[1], - fcport->port_name[2], fcport->port_name[3], - fcport->port_name[4], fcport->port_name[5], - fcport->port_name[6], fcport->port_name[7]); - /* Let's do the session creation async'ly */ sess->scst_sess = scst_register_session(tgt->scst_tgt, 1, wwn_str, sess, sess, q2t_alloc_session_done);