diff mbox series

[-next] scsi: target: iscsi: Switch to kmemdup_nul()

Message ID 20210402092517.2445595-1-yangyingliang@huawei.com (mailing list archive)
State Accepted
Headers show
Series [-next] scsi: target: iscsi: Switch to kmemdup_nul() | expand

Commit Message

Yang Yingliang April 2, 2021, 9:25 a.m. UTC
Use kmemdup_nul() helper instead of open-coding to
simplify the code.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/target/iscsi/iscsi_target_nego.c       | 4 +---
 drivers/target/iscsi/iscsi_target_parameters.c | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)

Comments

Martin K. Petersen May 11, 2021, 3:25 a.m. UTC | #1
On Fri, 2 Apr 2021 17:25:17 +0800, Yang Yingliang wrote:

> Use kmemdup_nul() helper instead of open-coding to
> simplify the code.

Applied to 5.14/scsi-queue, thanks!

[1/1] scsi: target: iscsi: Switch to kmemdup_nul()
      https://git.kernel.org/mkp/scsi/c/6235bef6f990
diff mbox series

Patch

diff --git a/drivers/target/iscsi/iscsi_target_nego.c b/drivers/target/iscsi/iscsi_target_nego.c
index 151e2949bb75..9a4a632f631d 100644
--- a/drivers/target/iscsi/iscsi_target_nego.c
+++ b/drivers/target/iscsi/iscsi_target_nego.c
@@ -1082,14 +1082,12 @@  int iscsi_target_locate_portal(
 	login_req = (struct iscsi_login_req *) login->req;
 	payload_length = ntoh24(login_req->dlength);
 
-	tmpbuf = kzalloc(payload_length + 1, GFP_KERNEL);
+	tmpbuf = kmemdup_nul(login->req_buf, payload_length, GFP_KERNEL);
 	if (!tmpbuf) {
 		pr_err("Unable to allocate memory for tmpbuf.\n");
 		return -1;
 	}
 
-	memcpy(tmpbuf, login->req_buf, payload_length);
-	tmpbuf[payload_length] = '\0';
 	start = tmpbuf;
 	end = (start + payload_length);
 
diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c
index 7a461fbb1566..6bc3aaf655fc 100644
--- a/drivers/target/iscsi/iscsi_target_parameters.c
+++ b/drivers/target/iscsi/iscsi_target_parameters.c
@@ -1357,14 +1357,12 @@  int iscsi_decode_text_input(
 	struct iscsi_param_list *param_list = conn->param_list;
 	char *tmpbuf, *start = NULL, *end = NULL;
 
-	tmpbuf = kzalloc(length + 1, GFP_KERNEL);
+	tmpbuf = kmemdup_nul(textbuf, length, GFP_KERNEL);
 	if (!tmpbuf) {
 		pr_err("Unable to allocate %u + 1 bytes for tmpbuf.\n", length);
 		return -ENOMEM;
 	}
 
-	memcpy(tmpbuf, textbuf, length);
-	tmpbuf[length] = '\0';
 	start = tmpbuf;
 	end = (start + length);