All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: skashyap@marvell.com, jhasan@marvell.com,
	GR-QLogic-Storage-Upstream@marvell.com, jejb@linux.ibm.com,
	martin.petersen@oracle.com, chad.dupuis@cavium.com,
	arun.easi@cavium.com, nilesh.javali@cavium.com
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org,
	Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Subject: [PATCH 2/3] scsi: qedf: Simplify 'qedf_alloc_global_queues()'
Date: Sun, 23 May 2021 13:02:36 +0200	[thread overview]
Message-ID: <8c53db1d644f09ee0ac1e23b0ce4c5df8eedcf14.1621765056.git.christophe.jaillet@wanadoo.fr> (raw)
In-Reply-To: <cover.1621765056.git.christophe.jaillet@wanadoo.fr>

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@wanadoo.fr>
---
 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


  parent reply	other threads:[~2021-05-23 11:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-23 11:01 [PATCH 0/3] scsi: qedf: Fix an error handling path + cleanups Christophe JAILLET
2021-05-23 11:02 ` [PATCH 1/3] scsi: qedf: Fix an error handling path in 'qedf_alloc_global_queues()' Christophe JAILLET
2021-05-23 11:02 ` Christophe JAILLET [this message]
2021-05-23 11:02 ` [PATCH 3/3] scsi: qedf: Axe a few useless lines of code Christophe JAILLET

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8c53db1d644f09ee0ac1e23b0ce4c5df8eedcf14.1621765056.git.christophe.jaillet@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=GR-QLogic-Storage-Upstream@marvell.com \
    --cc=arun.easi@cavium.com \
    --cc=chad.dupuis@cavium.com \
    --cc=jejb@linux.ibm.com \
    --cc=jhasan@marvell.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=nilesh.javali@cavium.com \
    --cc=skashyap@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.