From patchwork Sun May 23 11:02:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 12274855 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 396F3C47081 for ; Sun, 23 May 2021 11:02:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1868B611ED for ; Sun, 23 May 2021 11:02:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231756AbhEWLD5 (ORCPT ); Sun, 23 May 2021 07:03:57 -0400 Received: from smtp07.smtpout.orange.fr ([80.12.242.129]:36285 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231749AbhEWLD4 (ORCPT ); Sun, 23 May 2021 07:03:56 -0400 Received: from localhost.localdomain ([86.243.172.93]) by mwinf5d83 with ME id 8B2V2500121Fzsu03B2VuF; Sun, 23 May 2021 13:02:29 +0200 X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 23 May 2021 13:02:29 +0200 X-ME-IP: 86.243.172.93 From: Christophe JAILLET 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 Subject: [PATCH 1/3] scsi: qedf: Fix an error handling path in 'qedf_alloc_global_queues()' Date: Sun, 23 May 2021 13:02:29 +0200 Message-Id: <4c9c67bcad414c1128d26fceb9d6b579cb39cdc9.1621765056.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org If 'qedf_alloc_bdq()' fails, 'status' is known to be 0, so we report success to the caller. In fact going to 'mem_alloc_failure' is pointless here, because we try to free some resources that have not been allocated yet. This is however harmless because 'qedf_free_global_queues()' is robust enough. So make a direct return instead, as already done just a few lines above. While at it, also do a direct return if '!qedf->p_cpuq'. Going to 'mem_alloc_failure' is also pointless here and mixing goto and direct return is spurious. So make it clear that nothing has to be undone. Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.") Signed-off-by: Christophe JAILLET --- drivers/scsi/qedf/qedf_main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c index 7368a40ba649..ff3a1b183a7c 100644 --- a/drivers/scsi/qedf/qedf_main.c +++ b/drivers/scsi/qedf/qedf_main.c @@ -3022,9 +3022,8 @@ static int qedf_alloc_global_queues(struct qedf_ctx *qedf) * addresses of our queues */ if (!qedf->p_cpuq) { - status = 1; QEDF_ERR(&qedf->dbg_ctx, "p_cpuq is NULL.\n"); - goto mem_alloc_failure; + return 1; } qedf->global_queues = kzalloc((sizeof(struct global_queue *) @@ -3041,7 +3040,7 @@ static int qedf_alloc_global_queues(struct qedf_ctx *qedf) rc = qedf_alloc_bdq(qedf); if (rc) { QEDF_ERR(&qedf->dbg_ctx, "Unable to allocate bdq.\n"); - goto mem_alloc_failure; + return -ENOMEM; } /* Allocate a CQ and an associated PBL for each MSI-X vector */ From patchwork Sun May 23 11:02:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 12274857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71F33C4707A for ; Sun, 23 May 2021 11:02:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 536AF61244 for ; Sun, 23 May 2021 11:02:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231770AbhEWLEG (ORCPT ); Sun, 23 May 2021 07:04:06 -0400 Received: from smtp07.smtpout.orange.fr ([80.12.242.129]:24748 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231767AbhEWLEE (ORCPT ); Sun, 23 May 2021 07:04:04 -0400 Received: from localhost.localdomain ([86.243.172.93]) by mwinf5d83 with ME id 8B2d2500221Fzsu03B2dup; Sun, 23 May 2021 13:02:37 +0200 X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 23 May 2021 13:02:37 +0200 X-ME-IP: 86.243.172.93 From: Christophe JAILLET 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 Subject: [PATCH 2/3] scsi: qedf: Simplify 'qedf_alloc_global_queues()' Date: Sun, 23 May 2021 13:02:36 +0200 Message-Id: <8c53db1d644f09ee0ac1e23b0ce4c5df8eedcf14.1621765056.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org 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 --- 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; From patchwork Sun May 23 11:02:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 12274859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF859C47080 for ; Sun, 23 May 2021 11:02:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A42576109E for ; Sun, 23 May 2021 11:02:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231775AbhEWLEO (ORCPT ); Sun, 23 May 2021 07:04:14 -0400 Received: from smtp07.smtpout.orange.fr ([80.12.242.129]:38567 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231764AbhEWLEN (ORCPT ); Sun, 23 May 2021 07:04:13 -0400 Received: from localhost.localdomain ([86.243.172.93]) by mwinf5d83 with ME id 8B2m2500321Fzsu03B2mvL; Sun, 23 May 2021 13:02:46 +0200 X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 23 May 2021 13:02:46 +0200 X-ME-IP: 86.243.172.93 From: Christophe JAILLET 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 Subject: [PATCH 3/3] scsi: qedf: Axe a few useless lines of code Date: Sun, 23 May 2021 13:02:46 +0200 Message-Id: <7b3469d65dad1a4a187533b0dab101c66e8f61d5.1621765056.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Simplify a bit this file a remove a few lines of code: - keep function parameters on the same line - remove unneeded return at the end of a function that return void - remove duplicated and useless empty lines - remove unneeded {} when there is only one statement - remove a few () around 'qedf->dbg_ctx' so that we can... - ... merge a few messages that were split on 2 lines Signed-off-by: Christophe JAILLET --- Many more clean-up could be done to improve readability in this file. The above few steps have the advantage to also reduce the number of LoC. Anyway, that's mostly a matter of taste. --- drivers/scsi/qedf/qedf_main.c | 44 +++++++++++------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c index 3b80d4298f15..0fb5b89fa4a2 100644 --- a/drivers/scsi/qedf/qedf_main.c +++ b/drivers/scsi/qedf/qedf_main.c @@ -304,9 +304,7 @@ static void qedf_flogi_resp(struct fc_seq *seq, struct fc_frame *fp, static struct fc_seq *qedf_elsct_send(struct fc_lport *lport, u32 did, struct fc_frame *fp, unsigned int op, - void (*resp)(struct fc_seq *, - struct fc_frame *, - void *), + void (*resp)(struct fc_seq *, struct fc_frame *, void *), void *arg, u32 timeout) { struct qedf_ctx *qedf = lport_priv(lport); @@ -630,7 +628,6 @@ static void qedf_link_update(void *dev, struct qed_link_output *link) } } - static void qedf_dcbx_handler(void *dev, struct qed_dcbx_get *get, u32 mib_type) { struct qedf_ctx *qedf = (struct qedf_ctx *)dev; @@ -739,7 +736,6 @@ static int qedf_eh_abort(struct scsi_cmnd *sc_cmd) goto out; } - io_req = (struct qedf_ioreq *)sc_cmd->SCp.ptr; if (!io_req) { QEDF_ERR(&qedf->dbg_ctx, @@ -972,9 +968,8 @@ static int qedf_eh_host_reset(struct scsi_cmnd *sc_cmd) static int qedf_slave_configure(struct scsi_device *sdev) { - if (qedf_queue_depth) { + if (qedf_queue_depth) scsi_change_queue_depth(sdev, qedf_queue_depth); - } return 0; } @@ -1181,7 +1176,6 @@ static int qedf_xmit(struct fc_lport *lport, struct fc_frame *fp) cp = NULL; } - /* adjust skb network/transport offsets to match mac/fcoe/port */ skb_push(skb, elen + hlen); skb_reset_mac_header(skb); @@ -1899,7 +1893,6 @@ static int qedf_vport_create(struct fc_vport *vport, bool disabled) fc_disc_init(vn_port); fc_disc_config(vn_port, vn_port); - /* Allocate the exchange manager */ shost = vport_to_shost(vport); n_port = shost_priv(shost); @@ -2000,8 +1993,7 @@ static void qedf_wait_for_vport_destroy(struct qedf_ctx *qedf) { struct fc_host_attrs *fc_host = shost_to_fc_host(qedf->lport->host); - QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_NPIV, - "Entered.\n"); + QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_NPIV, "Entered.\n"); while (fc_host->npiv_vports_inuse > 0) { QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_NPIV, "Waiting for all vports to be reaped.\n"); @@ -2289,7 +2281,6 @@ static bool qedf_process_completions(struct qedf_fastpath *fp) return true; } - /* MSI-X fastpath handler code */ static irqreturn_t qedf_msix_handler(int irq, void *dev_id) { @@ -2623,7 +2614,6 @@ static void qedf_ll2_process_skb(struct work_struct *work) kfree_skb(skb); out: kfree(skb_work); - return; } static int qedf_ll2_rx(void *cookie, struct sk_buff *skb, @@ -2746,8 +2736,7 @@ static int qedf_prepare_sb(struct qedf_ctx *qedf) GFP_KERNEL); if (!qedf->fp_array) { - QEDF_ERR(&(qedf->dbg_ctx), "fastpath array allocation " - "failed.\n"); + QEDF_ERR(&qedf->dbg_ctx, "fastpath array allocation failed.\n"); return -ENOMEM; } @@ -2768,9 +2757,8 @@ static int qedf_prepare_sb(struct qedf_ctx *qedf) } fp->sb_id = id; fp->qedf = qedf; - fp->cq_num_entries = - qedf->global_queues[id]->cq_mem_size / - sizeof(struct fcoe_cqe); + fp->cq_num_entries = qedf->global_queues[id]->cq_mem_size / + sizeof(struct fcoe_cqe); } err: return 0; @@ -2815,7 +2803,6 @@ void qedf_process_cqe(struct qedf_ctx *qedf, struct fcoe_cqe *cqe) return; } - switch (comp_type) { case FCOE_GOOD_COMPLETION_CQE_TYPE: atomic_inc(&fcport->free_sqes); @@ -3154,8 +3141,7 @@ static int qedf_set_fcoe_pf_param(struct qedf_ctx *qedf) rval = qedf_alloc_global_queues(qedf); if (rval) { - QEDF_ERR(&(qedf->dbg_ctx), "Global queue allocation " - "failed.\n"); + QEDF_ERR(&qedf->dbg_ctx, "Global queue allocation failed.\n"); return 1; } @@ -3326,8 +3312,7 @@ static int __qedf_probe(struct pci_dev *pdev, int mode) QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_INFO, "qedf->io_mempool=%p.\n", qedf->io_mempool); - sprintf(host_buf, "qedf_%u_link", - qedf->lport->host->host_no); + sprintf(host_buf, "qedf_%u_link", qedf->lport->host->host_no); qedf->link_update_wq = create_workqueue(host_buf); INIT_DELAYED_WORK(&qedf->link_update, qedf_handle_link_update); INIT_DELAYED_WORK(&qedf->link_recovery, qedf_link_recovery); @@ -3581,8 +3566,7 @@ static int __qedf_probe(struct pci_dev *pdev, int mode) qedf->timer_work_queue = create_workqueue(host_buf); if (!qedf->timer_work_queue) { - QEDF_ERR(&(qedf->dbg_ctx), "Failed to start timer " - "workqueue.\n"); + QEDF_ERR(&qedf->dbg_ctx, "Failed to start timer workqueue.\n"); rc = -ENOMEM; goto err7; } @@ -3826,13 +3810,13 @@ void qedf_schedule_hw_err_handler(void *dev, enum qed_hw_err_type err_type) { struct qedf_ctx *qedf = dev; - QEDF_ERR(&(qedf->dbg_ctx), - "Hardware error handler scheduled, event=%d.\n", - err_type); + QEDF_ERR(&qedf->dbg_ctx, + "Hardware error handler scheduled, event=%d.\n", + err_type); if (test_bit(QEDF_IN_RECOVERY, &qedf->flags)) { - QEDF_ERR(&(qedf->dbg_ctx), - "Already in recovery, not scheduling board disable work.\n"); + QEDF_ERR(&qedf->dbg_ctx, + "Already in recovery, not scheduling board disable work.\n"); return; }