Commit 381e309a authored by Dan Carpenter's avatar Dan Carpenter Committed by Nicholas Bellinger

target/iscsi: cleanup some allocation style issues

We can use kcalloc() here instead of kzalloc().  It's better style and
it has overflow checking built in.

Also -ENOMEM is the correct error code for allocation errors.  -1 means
-EPERM.  None of the callers preserve the error codes so it doesn't
matter except as a cleanup.
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent bfb79eac
...@@ -141,11 +141,11 @@ static int iscsit_randomize_pdu_lists( ...@@ -141,11 +141,11 @@ static int iscsit_randomize_pdu_lists(
seq_count++; seq_count++;
continue; continue;
} }
array = kzalloc(seq_count * sizeof(u32), GFP_KERNEL); array = kcalloc(seq_count, sizeof(u32), GFP_KERNEL);
if (!array) { if (!array) {
pr_err("Unable to allocate memory" pr_err("Unable to allocate memory"
" for random array.\n"); " for random array.\n");
return -1; return -ENOMEM;
} }
iscsit_create_random_array(array, seq_count); iscsit_create_random_array(array, seq_count);
...@@ -161,11 +161,11 @@ static int iscsit_randomize_pdu_lists( ...@@ -161,11 +161,11 @@ static int iscsit_randomize_pdu_lists(
} }
if (seq_count) { if (seq_count) {
array = kzalloc(seq_count * sizeof(u32), GFP_KERNEL); array = kcalloc(seq_count, sizeof(u32), GFP_KERNEL);
if (!array) { if (!array) {
pr_err("Unable to allocate memory for" pr_err("Unable to allocate memory for"
" random array.\n"); " random array.\n");
return -1; return -ENOMEM;
} }
iscsit_create_random_array(array, seq_count); iscsit_create_random_array(array, seq_count);
...@@ -193,10 +193,10 @@ static int iscsit_randomize_seq_lists( ...@@ -193,10 +193,10 @@ static int iscsit_randomize_seq_lists(
if (!seq_count) if (!seq_count)
return 0; return 0;
array = kzalloc(seq_count * sizeof(u32), GFP_KERNEL); array = kcalloc(seq_count, sizeof(u32), GFP_KERNEL);
if (!array) { if (!array) {
pr_err("Unable to allocate memory for random array.\n"); pr_err("Unable to allocate memory for random array.\n");
return -1; return -ENOMEM;
} }
iscsit_create_random_array(array, seq_count); iscsit_create_random_array(array, seq_count);
...@@ -546,21 +546,21 @@ int iscsit_build_pdu_and_seq_lists( ...@@ -546,21 +546,21 @@ int iscsit_build_pdu_and_seq_lists(
iscsit_determine_counts_for_list(cmd, &bl, &seq_count, &pdu_count); iscsit_determine_counts_for_list(cmd, &bl, &seq_count, &pdu_count);
if (!conn->sess->sess_ops->DataSequenceInOrder) { if (!conn->sess->sess_ops->DataSequenceInOrder) {
seq = kzalloc(seq_count * sizeof(struct iscsi_seq), GFP_ATOMIC); seq = kcalloc(seq_count, sizeof(struct iscsi_seq), GFP_ATOMIC);
if (!seq) { if (!seq) {
pr_err("Unable to allocate struct iscsi_seq list\n"); pr_err("Unable to allocate struct iscsi_seq list\n");
return -1; return -ENOMEM;
} }
cmd->seq_list = seq; cmd->seq_list = seq;
cmd->seq_count = seq_count; cmd->seq_count = seq_count;
} }
if (!conn->sess->sess_ops->DataPDUInOrder) { if (!conn->sess->sess_ops->DataPDUInOrder) {
pdu = kzalloc(pdu_count * sizeof(struct iscsi_pdu), GFP_ATOMIC); pdu = kcalloc(pdu_count, sizeof(struct iscsi_pdu), GFP_ATOMIC);
if (!pdu) { if (!pdu) {
pr_err("Unable to allocate struct iscsi_pdu list.\n"); pr_err("Unable to allocate struct iscsi_pdu list.\n");
kfree(seq); kfree(seq);
return -1; return -ENOMEM;
} }
cmd->pdu_list = pdu; cmd->pdu_list = pdu;
cmd->pdu_count = pdu_count; cmd->pdu_count = pdu_count;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment