[PATCH 2/3] scsi: qedf: Simplify 'qedf_alloc_global_queues()'
From: Christophe JAILLET
Date: Sun May 23 2021 - 07:02:43 EST
In 'qedf_alloc_global_queues()', 'qedf->global_queues[i]', is used many
times. Use an intermediate variable with a much shorter name, 'q', to
simplify and make the code more readable.
Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx>
---
drivers/scsi/qedf/qedf_main.c | 53 +++++++++++++++--------------------
1 file changed, 22 insertions(+), 31 deletions(-)
diff --git a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c
index ff3a1b183a7c..3b80d4298f15 100644
--- a/drivers/scsi/qedf/qedf_main.c
+++ b/drivers/scsi/qedf/qedf_main.c
@@ -3045,55 +3045,46 @@ static int qedf_alloc_global_queues(struct qedf_ctx *qedf)
/* Allocate a CQ and an associated PBL for each MSI-X vector */
for (i = 0; i < qedf->num_queues; i++) {
- qedf->global_queues[i] = kzalloc(sizeof(struct global_queue),
- GFP_KERNEL);
- if (!qedf->global_queues[i]) {
+ struct global_queue *q;
+
+ q = kzalloc(sizeof(*q), GFP_KERNEL);
+ if (!q) {
QEDF_WARN(&(qedf->dbg_ctx), "Unable to allocate "
"global queue %d.\n", i);
status = -ENOMEM;
goto mem_alloc_failure;
}
+ qedf->global_queues[i] = q;
- qedf->global_queues[i]->cq_mem_size =
+ q->cq_mem_size =
FCOE_PARAMS_CQ_NUM_ENTRIES * sizeof(struct fcoe_cqe);
- qedf->global_queues[i]->cq_mem_size =
- ALIGN(qedf->global_queues[i]->cq_mem_size, QEDF_PAGE_SIZE);
-
- qedf->global_queues[i]->cq_pbl_size =
- (qedf->global_queues[i]->cq_mem_size /
- PAGE_SIZE) * sizeof(void *);
- qedf->global_queues[i]->cq_pbl_size =
- ALIGN(qedf->global_queues[i]->cq_pbl_size, QEDF_PAGE_SIZE);
-
- qedf->global_queues[i]->cq =
- dma_alloc_coherent(&qedf->pdev->dev,
- qedf->global_queues[i]->cq_mem_size,
- &qedf->global_queues[i]->cq_dma,
- GFP_KERNEL);
-
- if (!qedf->global_queues[i]->cq) {
+ q->cq_mem_size = ALIGN(q->cq_mem_size, QEDF_PAGE_SIZE);
+
+ q->cq_pbl_size = (q->cq_mem_size / PAGE_SIZE) * sizeof(void *);
+ q->cq_pbl_size = ALIGN(q->cq_pbl_size, QEDF_PAGE_SIZE);
+
+ q->cq = dma_alloc_coherent(&qedf->pdev->dev, q->cq_mem_size,
+ &q->cq_dma, GFP_KERNEL);
+
+ if (!q->cq) {
QEDF_WARN(&(qedf->dbg_ctx), "Could not allocate cq.\n");
status = -ENOMEM;
goto mem_alloc_failure;
}
- qedf->global_queues[i]->cq_pbl =
- dma_alloc_coherent(&qedf->pdev->dev,
- qedf->global_queues[i]->cq_pbl_size,
- &qedf->global_queues[i]->cq_pbl_dma,
- GFP_KERNEL);
+ q->cq_pbl = dma_alloc_coherent(&qedf->pdev->dev, q->cq_pbl_size,
+ &q->cq_pbl_dma, GFP_KERNEL);
- if (!qedf->global_queues[i]->cq_pbl) {
+ if (!q->cq_pbl) {
QEDF_WARN(&(qedf->dbg_ctx), "Could not allocate cq PBL.\n");
status = -ENOMEM;
goto mem_alloc_failure;
}
/* Create PBL */
- num_pages = qedf->global_queues[i]->cq_mem_size /
- QEDF_PAGE_SIZE;
- page = qedf->global_queues[i]->cq_dma;
- pbl = (u32 *)qedf->global_queues[i]->cq_pbl;
+ num_pages = q->cq_mem_size / QEDF_PAGE_SIZE;
+ page = q->cq_dma;
+ pbl = (u32 *)q->cq_pbl;
while (num_pages--) {
*pbl = U64_LO(page);
@@ -3103,7 +3094,7 @@ static int qedf_alloc_global_queues(struct qedf_ctx *qedf)
page += QEDF_PAGE_SIZE;
}
/* Set the initial consumer index for cq */
- qedf->global_queues[i]->cq_cons_idx = 0;
+ q->cq_cons_idx = 0;
}
list = (u32 *)qedf->p_cpuq;
--
2.30.2