* [patch] target/iscsi: cleanup some allocation style issues
@ 2012-04-17 6:33 Dan Carpenter
2012-04-18 7:15 ` Nicholas A. Bellinger
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2012-04-17 6:33 UTC (permalink / raw)
To: kernel-janitors
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: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/target/iscsi/iscsi_target_seq_pdu_list.c b/drivers/target/iscsi/iscsi_target_seq_pdu_list.c
index 7d0effa..85a306e 100644
--- a/drivers/target/iscsi/iscsi_target_seq_pdu_list.c
+++ b/drivers/target/iscsi/iscsi_target_seq_pdu_list.c
@@ -141,11 +141,11 @@ redo:
seq_count++;
continue;
}
- array = kzalloc(seq_count * sizeof(u32), GFP_KERNEL);
+ array = kcalloc(seq_count, sizeof(u32), GFP_KERNEL);
if (!array) {
pr_err("Unable to allocate memory"
" for random array.\n");
- return -1;
+ return -ENOMEM;
}
iscsit_create_random_array(array, seq_count);
@@ -161,11 +161,11 @@ redo:
}
if (seq_count) {
- array = kzalloc(seq_count * sizeof(u32), GFP_KERNEL);
+ array = kcalloc(seq_count, sizeof(u32), GFP_KERNEL);
if (!array) {
pr_err("Unable to allocate memory for"
" random array.\n");
- return -1;
+ return -ENOMEM;
}
iscsit_create_random_array(array, seq_count);
@@ -193,10 +193,10 @@ static int iscsit_randomize_seq_lists(
if (!seq_count)
return 0;
- array = kzalloc(seq_count * sizeof(u32), GFP_KERNEL);
+ array = kcalloc(seq_count, sizeof(u32), GFP_KERNEL);
if (!array) {
pr_err("Unable to allocate memory for random array.\n");
- return -1;
+ return -ENOMEM;
}
iscsit_create_random_array(array, seq_count);
@@ -546,21 +546,21 @@ int iscsit_build_pdu_and_seq_lists(
iscsit_determine_counts_for_list(cmd, &bl, &seq_count, &pdu_count);
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) {
pr_err("Unable to allocate struct iscsi_seq list\n");
- return -1;
+ return -ENOMEM;
}
cmd->seq_list = seq;
cmd->seq_count = seq_count;
}
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) {
pr_err("Unable to allocate struct iscsi_pdu list.\n");
kfree(seq);
- return -1;
+ return -ENOMEM;
}
cmd->pdu_list = pdu;
cmd->pdu_count = pdu_count;
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [patch] target/iscsi: cleanup some allocation style issues
2012-04-17 6:33 [patch] target/iscsi: cleanup some allocation style issues Dan Carpenter
@ 2012-04-18 7:15 ` Nicholas A. Bellinger
0 siblings, 0 replies; 2+ messages in thread
From: Nicholas A. Bellinger @ 2012-04-18 7:15 UTC (permalink / raw)
To: kernel-janitors
On Tue, 2012-04-17 at 09:33 +0300, Dan Carpenter wrote:
> 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: Dan Carpenter <dan.carpenter@oracle.com>
>
Also applied to lio-core. I'll make sure to include these into the next
target-pending update.
Thanks Dan!
--nab
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-04-18 7:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-17 6:33 [patch] target/iscsi: cleanup some allocation style issues Dan Carpenter
2012-04-18 7:15 ` Nicholas A. Bellinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox