From: John Garry <john.garry@huawei.com>
To: <jejb@linux.vnet.ibm.com>, <martin.petersen@oracle.com>
Cc: <linux-scsi@vger.kernel.org>, <linuxarm@huawei.com>,
<linux-kernel@vger.kernel.org>,
Luo Jiaxing <luojiaxing@huawei.com>,
"John Garry" <john.garry@huawei.com>
Subject: [PATCH 11/13] scsi: hisi_sas: Add hisi_sas_debugfs_alloc() to centralise allocation
Date: Fri, 6 Sep 2019 20:55:35 +0800 [thread overview]
Message-ID: <1567774537-20003-12-git-send-email-john.garry@huawei.com> (raw)
In-Reply-To: <1567774537-20003-1-git-send-email-john.garry@huawei.com>
From: Luo Jiaxing <luojiaxing@huawei.com>
We extract the code of memory allocate and construct an new function for
it. We think it's convenient for subsequent optimization.
Signed-off-by: Luo Jiaxing <luojiaxing@huawei.com>
Signed-off-by: John Garry <john.garry@huawei.com>
---
drivers/scsi/hisi_sas/hisi_sas_main.c | 102 +++++++++++++++-----------
1 file changed, 58 insertions(+), 44 deletions(-)
diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c
index b96732493137..e7056bbad7d7 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_main.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_main.c
@@ -3307,27 +3307,44 @@ void hisi_sas_debugfs_work_handler(struct work_struct *work)
}
EXPORT_SYMBOL_GPL(hisi_sas_debugfs_work_handler);
-void hisi_sas_debugfs_init(struct hisi_hba *hisi_hba)
+void hisi_sas_debugfs_release(struct hisi_hba *hisi_hba)
+{
+ struct device *dev = hisi_hba->dev;
+ int i;
+
+ devm_kfree(dev, hisi_hba->debugfs_iost_cache);
+ devm_kfree(dev, hisi_hba->debugfs_itct_cache);
+ devm_kfree(dev, hisi_hba->debugfs_iost);
+
+ for (i = 0; i < hisi_hba->queue_count; i++)
+ devm_kfree(dev, hisi_hba->debugfs_cmd_hdr[i]);
+
+ for (i = 0; i < hisi_hba->queue_count; i++)
+ devm_kfree(dev, hisi_hba->debugfs_complete_hdr[i]);
+
+ for (i = 0; i < DEBUGFS_REGS_NUM; i++)
+ devm_kfree(dev, hisi_hba->debugfs_regs[i]);
+
+ for (i = 0; i < hisi_hba->n_phy; i++)
+ devm_kfree(dev, hisi_hba->debugfs_port_reg[i]);
+}
+
+int hisi_sas_debugfs_alloc(struct hisi_hba *hisi_hba)
{
- int max_command_entries = HISI_SAS_MAX_COMMANDS;
const struct hisi_sas_hw *hw = hisi_hba->hw;
struct device *dev = hisi_hba->dev;
- int p, i, c, d;
+ int p, c, d;
size_t sz;
- hisi_hba->debugfs_dir = debugfs_create_dir(dev_name(dev),
- hisi_sas_debugfs_dir);
- debugfs_create_file("trigger_dump", 0600,
- hisi_hba->debugfs_dir,
- hisi_hba,
- &hisi_sas_debugfs_trigger_dump_fops);
+ hisi_hba->debugfs_dump_dentry =
+ debugfs_create_dir("dump", hisi_hba->debugfs_dir);
sz = hw->debugfs_reg_array[DEBUGFS_GLOBAL]->count * 4;
hisi_hba->debugfs_regs[DEBUGFS_GLOBAL] =
devm_kmalloc(dev, sz, GFP_KERNEL);
if (!hisi_hba->debugfs_regs[DEBUGFS_GLOBAL])
- goto fail_global;
+ goto fail;
sz = hw->debugfs_reg_port->count * 4;
for (p = 0; p < hisi_hba->n_phy; p++) {
@@ -3335,7 +3352,7 @@ void hisi_sas_debugfs_init(struct hisi_hba *hisi_hba)
devm_kmalloc(dev, sz, GFP_KERNEL);
if (!hisi_hba->debugfs_port_reg[p])
- goto fail_port;
+ goto fail;
}
sz = hw->debugfs_reg_array[DEBUGFS_AXI]->count * 4;
@@ -3343,14 +3360,14 @@ void hisi_sas_debugfs_init(struct hisi_hba *hisi_hba)
devm_kmalloc(dev, sz, GFP_KERNEL);
if (!hisi_hba->debugfs_regs[DEBUGFS_AXI])
- goto fail_axi;
+ goto fail;
sz = hw->debugfs_reg_array[DEBUGFS_RAS]->count * 4;
hisi_hba->debugfs_regs[DEBUGFS_RAS] =
devm_kmalloc(dev, sz, GFP_KERNEL);
if (!hisi_hba->debugfs_regs[DEBUGFS_RAS])
- goto fail_ras;
+ goto fail;
sz = hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS;
for (c = 0; c < hisi_hba->queue_count; c++) {
@@ -3358,7 +3375,7 @@ void hisi_sas_debugfs_init(struct hisi_hba *hisi_hba)
devm_kmalloc(dev, sz, GFP_KERNEL);
if (!hisi_hba->debugfs_complete_hdr[c])
- goto fail_cq;
+ goto fail;
}
sz = sizeof(struct hisi_sas_cmd_hdr) * HISI_SAS_QUEUE_SLOTS;
@@ -3367,60 +3384,57 @@ void hisi_sas_debugfs_init(struct hisi_hba *hisi_hba)
devm_kmalloc(dev, sz, GFP_KERNEL);
if (!hisi_hba->debugfs_cmd_hdr[d])
- goto fail_iost_dq;
+ goto fail;
}
- sz = max_command_entries * sizeof(struct hisi_sas_iost);
+ sz = HISI_SAS_MAX_COMMANDS * sizeof(struct hisi_sas_iost);
hisi_hba->debugfs_iost = devm_kmalloc(dev, sz, GFP_KERNEL);
if (!hisi_hba->debugfs_iost)
- goto fail_iost_dq;
+ goto fail;
sz = HISI_SAS_IOST_ITCT_CACHE_NUM *
sizeof(struct hisi_sas_iost_itct_cache);
hisi_hba->debugfs_iost_cache = devm_kmalloc(dev, sz, GFP_KERNEL);
if (!hisi_hba->debugfs_iost_cache)
- goto fail_iost_cache;
+ goto fail;
sz = HISI_SAS_IOST_ITCT_CACHE_NUM *
sizeof(struct hisi_sas_iost_itct_cache);
hisi_hba->debugfs_itct_cache = devm_kmalloc(dev, sz, GFP_KERNEL);
if (!hisi_hba->debugfs_itct_cache)
- goto fail_itct_cache;
+ goto fail;
/* New memory allocation must be locate before itct */
sz = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_itct);
hisi_hba->debugfs_itct = devm_kmalloc(dev, sz, GFP_KERNEL);
if (!hisi_hba->debugfs_itct)
- goto fail_itct;
+ goto fail;
- return;
-fail_itct:
- devm_kfree(dev, hisi_hba->debugfs_iost_cache);
-fail_itct_cache:
- devm_kfree(dev, hisi_hba->debugfs_iost_cache);
-fail_iost_cache:
- devm_kfree(dev, hisi_hba->debugfs_iost);
-fail_iost_dq:
- for (i = 0; i < d; i++)
- devm_kfree(dev, hisi_hba->debugfs_cmd_hdr[i]);
-fail_cq:
- for (i = 0; i < c; i++)
- devm_kfree(dev, hisi_hba->debugfs_complete_hdr[i]);
- devm_kfree(dev, hisi_hba->debugfs_regs[DEBUGFS_RAS]);
-fail_ras:
- devm_kfree(dev, hisi_hba->debugfs_regs[DEBUGFS_AXI]);
-fail_axi:
-fail_port:
- for (i = 0; i < p; i++)
- devm_kfree(dev, hisi_hba->debugfs_port_reg[i]);
- devm_kfree(dev, hisi_hba->debugfs_regs[DEBUGFS_GLOBAL]);
-fail_global:
- debugfs_remove_recursive(hisi_hba->debugfs_dir);
- dev_dbg(dev, "failed to init debugfs!\n");
+ return 0;
+fail:
+ hisi_sas_debugfs_release(hisi_hba);
+ return -ENOMEM;
+}
+
+void hisi_sas_debugfs_init(struct hisi_hba *hisi_hba)
+{
+ struct device *dev = hisi_hba->dev;
+
+ hisi_hba->debugfs_dir = debugfs_create_dir(dev_name(dev),
+ hisi_sas_debugfs_dir);
+ debugfs_create_file("trigger_dump", 0600,
+ hisi_hba->debugfs_dir,
+ hisi_hba,
+ &hisi_sas_debugfs_trigger_dump_fops);
+
+ if (hisi_sas_debugfs_alloc(hisi_hba)) {
+ debugfs_remove_recursive(hisi_hba->debugfs_dir);
+ dev_dbg(dev, "failed to init debugfs!\n");
+ }
}
EXPORT_SYMBOL_GPL(hisi_sas_debugfs_init);
--
2.17.1
next prev parent reply other threads:[~2019-09-06 12:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-06 12:55 [PATCH 00/13] hisi_sas: Some misc patches John Garry
2019-09-06 12:55 ` [PATCH 01/13] scsi: hisi_sas: add debugfs auto-trigger for internal abort time out John Garry
2019-09-06 12:55 ` [PATCH 02/13] scsi: hisi_sas: Use true/false as input parameter of sas_phy_reset() John Garry
2019-09-06 12:55 ` [PATCH 03/13] scsi: hisi_sas: Directly return when running I_T_nexus reset if phy disabled John Garry
2019-09-06 12:55 ` [PATCH 04/13] scsi: hisi_sas: Remove sleep after issue phy reset if sas_smp_phy_control() fails John Garry
2019-09-06 12:55 ` [PATCH 05/13] scsi: hisi_sas: Retry 3 times TMF IO for SAS disks when init device John Garry
2019-09-06 12:55 ` [PATCH 06/13] scsi: hisi_sas: Update all the registers after suspend and resume John Garry
2019-09-06 12:55 ` [PATCH 07/13] scsi: hisi_sas: Assign NCQ tag for all NCQ commands John Garry
2019-09-06 12:55 ` [PATCH 08/13] scsi: hisi_sas: Remove hisi_sas_hw.slot_complete John Garry
2019-09-06 12:55 ` [PATCH 09/13] scsi: hisi_sas: Remove redundant work declaration John Garry
2019-09-06 12:55 ` [PATCH 10/13] scsi: hisi_sas: Remove some unused function arguments John Garry
2019-09-06 12:55 ` John Garry [this message]
2019-09-06 12:55 ` [PATCH 12/13] scsi: hisi_sas: Add BIST support for phy loopback John Garry
2019-09-06 12:55 ` [PATCH 13/13] scsi: hisi_sas: Fix the conflict between device gone and host reset John Garry
2019-09-11 2:29 ` [PATCH 00/13] hisi_sas: Some misc patches Martin K. Petersen
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=1567774537-20003-12-git-send-email-john.garry@huawei.com \
--to=john.garry@huawei.com \
--cc=jejb@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=luojiaxing@huawei.com \
--cc=martin.petersen@oracle.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®