Skip to content

Commit

Permalink
scsi: target: iscsi: Switch to kmemdup_nul()
Browse files Browse the repository at this point in the history
Use kmemdup_nul() helper instead of open-coding to simplify the code.

Link: https://lore.kernel.org/r/20210402092517.2445595-1-yangyingliang@huawei.com
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
  • Loading branch information
Yang Yingliang authored and Martin K. Petersen committed May 10, 2021
1 parent 1ee2753 commit 6235bef
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
4 changes: 1 addition & 3 deletions drivers/target/iscsi/iscsi_target_nego.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 1 addition & 3 deletions drivers/target/iscsi/iscsi_target_parameters.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 6235bef

Please sign in to comment.