Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1c3d5794 authored by Thomas Meyer's avatar Thomas Meyer Committed by Nicholas Bellinger
Browse files

iscsi-target: Use kmemdup rather than duplicating its implementation



The semantic patch that makes this change is available
in scripts/coccinelle/api/memdup.cocci.

Signed-off-by: default avatarThomas Meyer <thomas@m3y3r.de>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent 7ae0b103
Loading
Loading
Loading
Loading
+2 −4
Original line number Original line Diff line number Diff line
@@ -614,13 +614,12 @@ int iscsit_add_reject(
	hdr	= (struct iscsi_reject *) cmd->pdu;
	hdr	= (struct iscsi_reject *) cmd->pdu;
	hdr->reason = reason;
	hdr->reason = reason;


	cmd->buf_ptr = kzalloc(ISCSI_HDR_LEN, GFP_KERNEL);
	cmd->buf_ptr = kmemdup(buf, ISCSI_HDR_LEN, GFP_KERNEL);
	if (!cmd->buf_ptr) {
	if (!cmd->buf_ptr) {
		pr_err("Unable to allocate memory for cmd->buf_ptr\n");
		pr_err("Unable to allocate memory for cmd->buf_ptr\n");
		iscsit_release_cmd(cmd);
		iscsit_release_cmd(cmd);
		return -1;
		return -1;
	}
	}
	memcpy(cmd->buf_ptr, buf, ISCSI_HDR_LEN);


	spin_lock_bh(&conn->cmd_lock);
	spin_lock_bh(&conn->cmd_lock);
	list_add_tail(&cmd->i_list, &conn->conn_cmd_list);
	list_add_tail(&cmd->i_list, &conn->conn_cmd_list);
@@ -661,13 +660,12 @@ int iscsit_add_reject_from_cmd(
	hdr	= (struct iscsi_reject *) cmd->pdu;
	hdr	= (struct iscsi_reject *) cmd->pdu;
	hdr->reason = reason;
	hdr->reason = reason;


	cmd->buf_ptr = kzalloc(ISCSI_HDR_LEN, GFP_KERNEL);
	cmd->buf_ptr = kmemdup(buf, ISCSI_HDR_LEN, GFP_KERNEL);
	if (!cmd->buf_ptr) {
	if (!cmd->buf_ptr) {
		pr_err("Unable to allocate memory for cmd->buf_ptr\n");
		pr_err("Unable to allocate memory for cmd->buf_ptr\n");
		iscsit_release_cmd(cmd);
		iscsit_release_cmd(cmd);
		return -1;
		return -1;
	}
	}
	memcpy(cmd->buf_ptr, buf, ISCSI_HDR_LEN);


	if (add_to_conn) {
	if (add_to_conn) {
		spin_lock_bh(&conn->cmd_lock);
		spin_lock_bh(&conn->cmd_lock);
+1 −2
Original line number Original line Diff line number Diff line
@@ -981,14 +981,13 @@ struct iscsi_login *iscsi_target_init_negotiation(
		return NULL;
		return NULL;
	}
	}


	login->req = kzalloc(ISCSI_HDR_LEN, GFP_KERNEL);
	login->req = kmemdup(login_pdu, ISCSI_HDR_LEN, GFP_KERNEL);
	if (!login->req) {
	if (!login->req) {
		pr_err("Unable to allocate memory for Login Request.\n");
		pr_err("Unable to allocate memory for Login Request.\n");
		iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
		iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
				ISCSI_LOGIN_STATUS_NO_RESOURCES);
				ISCSI_LOGIN_STATUS_NO_RESOURCES);
		goto out;
		goto out;
	}
	}
	memcpy(login->req, login_pdu, ISCSI_HDR_LEN);


	login->req_buf = kzalloc(MAX_KEY_VALUE_PAIRS, GFP_KERNEL);
	login->req_buf = kzalloc(MAX_KEY_VALUE_PAIRS, GFP_KERNEL);
	if (!login->req_buf) {
	if (!login->req_buf) {