From: Tomer Tayar <ttayar@xxxxxxxxx> Currently the sysfs/debugfs interfaces and device un-registration are done as the last thing in hl_device_fini(), after several finalizations and releases are done. While a disabled flag is set at the beginning of hl_device_fini(), and it is being checked when handling user accesses to these interfaces, this check is not hermetic and it is better to just reverse the order of the code in hl_device_fini(). Signed-off-by: Tomer Tayar <ttayar@xxxxxxxxx> Reviewed-by: Oded Gabbay <ogabbay@xxxxxxxxxx> Signed-off-by: Oded Gabbay <ogabbay@xxxxxxxxxx> --- drivers/accel/habanalabs/common/device.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/accel/habanalabs/common/device.c b/drivers/accel/habanalabs/common/device.c index c0c9e9504672..5293ac3c7988 100644 --- a/drivers/accel/habanalabs/common/device.c +++ b/drivers/accel/habanalabs/common/device.c @@ -2408,6 +2408,12 @@ void hl_device_fini(struct hl_device *hdev) hdev->fw_loader.fw_comp_loaded = FW_TYPE_NONE; + /* Hide devices and sysfs/debugfs files from user */ + cdev_sysfs_debugfs_remove(hdev); + drm_dev_unregister(&hdev->drm); + + hl_debugfs_device_fini(hdev); + /* Release kernel context */ if ((hdev->kernel_ctx) && (hl_ctx_put(hdev->kernel_ctx) != 1)) dev_err(hdev->dev, "kernel ctx is still alive\n"); @@ -2436,12 +2442,6 @@ void hl_device_fini(struct hl_device *hdev) device_early_fini(hdev); - /* Hide devices and sysfs/debugfs files from user */ - cdev_sysfs_debugfs_remove(hdev); - drm_dev_unregister(&hdev->drm); - - hl_debugfs_device_fini(hdev); - pr_info("removed device successfully\n"); } -- 2.34.1