Commit 0a6e038f authored by Chenghai Huang's avatar Chenghai Huang Committed by Herbert Xu

crypto: hisilicon - Adjust debugfs creation and release order

There is a scenario where the file directory is created but the
file memory is not set. In this case, if a user accesses the
file, an error occurs.

So during the creation process of debugfs, memory should be
allocated first before creating the directory. In the release
process, the directory should be deleted first before releasing
the memory to avoid the situation where the memory does not
exist when accessing the directory.

In addition, the directory released by the debugfs is a global
variable. When the debugfs of an accelerator fails to be
initialized, releasing the directory of the global variable
affects the debugfs initialization of other accelerators.
The debugfs root directory released by debugfs init should be a
member of qm, not a global variable.
Signed-off-by: default avatarChenghai Huang <huangchenghai2@huawei.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 56f37cea
...@@ -1074,41 +1074,40 @@ static int hpre_debugfs_init(struct hisi_qm *qm) ...@@ -1074,41 +1074,40 @@ static int hpre_debugfs_init(struct hisi_qm *qm)
struct device *dev = &qm->pdev->dev; struct device *dev = &qm->pdev->dev;
int ret; int ret;
qm->debug.debug_root = debugfs_create_dir(dev_name(dev),
hpre_debugfs_root);
qm->debug.sqe_mask_offset = HPRE_SQE_MASK_OFFSET;
qm->debug.sqe_mask_len = HPRE_SQE_MASK_LEN;
ret = hisi_qm_regs_debugfs_init(qm, hpre_diff_regs, ARRAY_SIZE(hpre_diff_regs)); ret = hisi_qm_regs_debugfs_init(qm, hpre_diff_regs, ARRAY_SIZE(hpre_diff_regs));
if (ret) { if (ret) {
dev_warn(dev, "Failed to init HPRE diff regs!\n"); dev_warn(dev, "Failed to init HPRE diff regs!\n");
goto debugfs_remove; return ret;
} }
qm->debug.debug_root = debugfs_create_dir(dev_name(dev),
hpre_debugfs_root);
qm->debug.sqe_mask_offset = HPRE_SQE_MASK_OFFSET;
qm->debug.sqe_mask_len = HPRE_SQE_MASK_LEN;
hisi_qm_debug_init(qm); hisi_qm_debug_init(qm);
if (qm->pdev->device == PCI_DEVICE_ID_HUAWEI_HPRE_PF) { if (qm->pdev->device == PCI_DEVICE_ID_HUAWEI_HPRE_PF) {
ret = hpre_ctrl_debug_init(qm); ret = hpre_ctrl_debug_init(qm);
if (ret) if (ret)
goto failed_to_create; goto debugfs_remove;
} }
hpre_dfx_debug_init(qm); hpre_dfx_debug_init(qm);
return 0; return 0;
failed_to_create:
hisi_qm_regs_debugfs_uninit(qm, ARRAY_SIZE(hpre_diff_regs));
debugfs_remove: debugfs_remove:
debugfs_remove_recursive(qm->debug.debug_root); debugfs_remove_recursive(qm->debug.debug_root);
hisi_qm_regs_debugfs_uninit(qm, ARRAY_SIZE(hpre_diff_regs));
return ret; return ret;
} }
static void hpre_debugfs_exit(struct hisi_qm *qm) static void hpre_debugfs_exit(struct hisi_qm *qm)
{ {
hisi_qm_regs_debugfs_uninit(qm, ARRAY_SIZE(hpre_diff_regs));
debugfs_remove_recursive(qm->debug.debug_root); debugfs_remove_recursive(qm->debug.debug_root);
hisi_qm_regs_debugfs_uninit(qm, ARRAY_SIZE(hpre_diff_regs));
} }
static int hpre_pre_store_cap_reg(struct hisi_qm *qm) static int hpre_pre_store_cap_reg(struct hisi_qm *qm)
......
...@@ -901,37 +901,36 @@ static int sec_debugfs_init(struct hisi_qm *qm) ...@@ -901,37 +901,36 @@ static int sec_debugfs_init(struct hisi_qm *qm)
struct device *dev = &qm->pdev->dev; struct device *dev = &qm->pdev->dev;
int ret; int ret;
qm->debug.debug_root = debugfs_create_dir(dev_name(dev),
sec_debugfs_root);
qm->debug.sqe_mask_offset = SEC_SQE_MASK_OFFSET;
qm->debug.sqe_mask_len = SEC_SQE_MASK_LEN;
ret = hisi_qm_regs_debugfs_init(qm, sec_diff_regs, ARRAY_SIZE(sec_diff_regs)); ret = hisi_qm_regs_debugfs_init(qm, sec_diff_regs, ARRAY_SIZE(sec_diff_regs));
if (ret) { if (ret) {
dev_warn(dev, "Failed to init SEC diff regs!\n"); dev_warn(dev, "Failed to init SEC diff regs!\n");
goto debugfs_remove; return ret;
} }
qm->debug.debug_root = debugfs_create_dir(dev_name(dev),
sec_debugfs_root);
qm->debug.sqe_mask_offset = SEC_SQE_MASK_OFFSET;
qm->debug.sqe_mask_len = SEC_SQE_MASK_LEN;
hisi_qm_debug_init(qm); hisi_qm_debug_init(qm);
ret = sec_debug_init(qm); ret = sec_debug_init(qm);
if (ret) if (ret)
goto failed_to_create; goto debugfs_remove;
return 0; return 0;
failed_to_create:
hisi_qm_regs_debugfs_uninit(qm, ARRAY_SIZE(sec_diff_regs));
debugfs_remove: debugfs_remove:
debugfs_remove_recursive(sec_debugfs_root); debugfs_remove_recursive(qm->debug.debug_root);
hisi_qm_regs_debugfs_uninit(qm, ARRAY_SIZE(sec_diff_regs));
return ret; return ret;
} }
static void sec_debugfs_exit(struct hisi_qm *qm) static void sec_debugfs_exit(struct hisi_qm *qm)
{ {
hisi_qm_regs_debugfs_uninit(qm, ARRAY_SIZE(sec_diff_regs));
debugfs_remove_recursive(qm->debug.debug_root); debugfs_remove_recursive(qm->debug.debug_root);
hisi_qm_regs_debugfs_uninit(qm, ARRAY_SIZE(sec_diff_regs));
} }
static int sec_show_last_regs_init(struct hisi_qm *qm) static int sec_show_last_regs_init(struct hisi_qm *qm)
......
...@@ -887,36 +887,34 @@ static int hisi_zip_ctrl_debug_init(struct hisi_qm *qm) ...@@ -887,36 +887,34 @@ static int hisi_zip_ctrl_debug_init(struct hisi_qm *qm)
static int hisi_zip_debugfs_init(struct hisi_qm *qm) static int hisi_zip_debugfs_init(struct hisi_qm *qm)
{ {
struct device *dev = &qm->pdev->dev; struct device *dev = &qm->pdev->dev;
struct dentry *dev_d;
int ret; int ret;
dev_d = debugfs_create_dir(dev_name(dev), hzip_debugfs_root);
qm->debug.sqe_mask_offset = HZIP_SQE_MASK_OFFSET;
qm->debug.sqe_mask_len = HZIP_SQE_MASK_LEN;
qm->debug.debug_root = dev_d;
ret = hisi_qm_regs_debugfs_init(qm, hzip_diff_regs, ARRAY_SIZE(hzip_diff_regs)); ret = hisi_qm_regs_debugfs_init(qm, hzip_diff_regs, ARRAY_SIZE(hzip_diff_regs));
if (ret) { if (ret) {
dev_warn(dev, "Failed to init ZIP diff regs!\n"); dev_warn(dev, "Failed to init ZIP diff regs!\n");
goto debugfs_remove; return ret;
} }
qm->debug.sqe_mask_offset = HZIP_SQE_MASK_OFFSET;
qm->debug.sqe_mask_len = HZIP_SQE_MASK_LEN;
qm->debug.debug_root = debugfs_create_dir(dev_name(dev),
hzip_debugfs_root);
hisi_qm_debug_init(qm); hisi_qm_debug_init(qm);
if (qm->fun_type == QM_HW_PF) { if (qm->fun_type == QM_HW_PF) {
ret = hisi_zip_ctrl_debug_init(qm); ret = hisi_zip_ctrl_debug_init(qm);
if (ret) if (ret)
goto failed_to_create; goto debugfs_remove;
} }
hisi_zip_dfx_debug_init(qm); hisi_zip_dfx_debug_init(qm);
return 0; return 0;
failed_to_create:
hisi_qm_regs_debugfs_uninit(qm, ARRAY_SIZE(hzip_diff_regs));
debugfs_remove: debugfs_remove:
debugfs_remove_recursive(hzip_debugfs_root); debugfs_remove_recursive(qm->debug.debug_root);
hisi_qm_regs_debugfs_uninit(qm, ARRAY_SIZE(hzip_diff_regs));
return ret; return ret;
} }
...@@ -940,10 +938,10 @@ static void hisi_zip_debug_regs_clear(struct hisi_qm *qm) ...@@ -940,10 +938,10 @@ static void hisi_zip_debug_regs_clear(struct hisi_qm *qm)
static void hisi_zip_debugfs_exit(struct hisi_qm *qm) static void hisi_zip_debugfs_exit(struct hisi_qm *qm)
{ {
hisi_qm_regs_debugfs_uninit(qm, ARRAY_SIZE(hzip_diff_regs));
debugfs_remove_recursive(qm->debug.debug_root); debugfs_remove_recursive(qm->debug.debug_root);
hisi_qm_regs_debugfs_uninit(qm, ARRAY_SIZE(hzip_diff_regs));
if (qm->fun_type == QM_HW_PF) { if (qm->fun_type == QM_HW_PF) {
hisi_zip_debug_regs_clear(qm); hisi_zip_debug_regs_clear(qm);
qm->debug.curr_qm_qp_num = 0; qm->debug.curr_qm_qp_num = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment