drivers: Use runtime debugfs check

When kernel command line debugfs=off is specified instead of
disabling CONFIG_DEBUG_FS in defconfig to disable Debug-FS,
debugfs functions like debugfs_create_dir will fail.

Use function debugfs_initialized() to check if debugfs
functionality is enabled before calling any debugfs functions.

This allows us to by-pass debugfs initialization if debugfs
is not enabled.

Also, there is no need to protect debugfs related code under
CONFIG_DEBUG_FS, as stub functions for all debugfs APIs are
defined when CONFIG_DEBUG_FS is disabled.

Bug 3752450

Change-Id: I1aa2c46bc822da54fdc87504ac75c91845e02c12
Signed-off-by: Bharat Nihalani <bnihalani@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2820666
Reviewed-by: svc_kernel_abi <svc_kernel_abi@nvidia.com>
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-cert <svc-mobile-cert@nvidia.com>
Reviewed-by: Suresh Venkatachalam <skathirampat@nvidia.com>
Reviewed-by: Dara Ramesh <dramesh@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
This commit is contained in:
Bharat Nihalani
2022-12-02 17:15:08 +05:30
committed by Laxman Dewangan
parent 83ee116f72
commit d40e2df1b2
2 changed files with 19 additions and 27 deletions

View File

@@ -3,7 +3,7 @@
*
* ARAM manager
*
* Copyright (C) 2014-2018, NVIDIA Corporation. All rights reserved.
* Copyright (C) 2014-2022, NVIDIA Corporation. All rights reserved.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
@@ -48,7 +48,6 @@ unsigned long nvadsp_aram_get_address(void *handle)
return mem_get_address(handle);
}
#ifdef CONFIG_DEBUG_FS
static struct dentry *aram_dump_debugfs_file;
static int nvadsp_aram_dump(struct seq_file *s, void *data)
@@ -68,7 +67,6 @@ static const struct file_operations aram_dump_fops = {
.llseek = seq_lseek,
.release = single_release,
};
#endif
int nvadsp_aram_init(unsigned long addr, unsigned long size)
{
@@ -78,23 +76,21 @@ int nvadsp_aram_init(unsigned long addr, unsigned long size)
return PTR_ERR(aram_handle);
}
#ifdef CONFIG_DEBUG_FS
aram_dump_debugfs_file = debugfs_create_file("aram_dump",
S_IRUSR, NULL, NULL, &aram_dump_fops);
if (!aram_dump_debugfs_file) {
pr_err("ERROR: failed to create aram_dump debugfs");
destroy_mem_manager(aram_handle);
return -ENOMEM;
if (debugfs_initialized()) {
aram_dump_debugfs_file = debugfs_create_file("aram_dump",
S_IRUSR, NULL, NULL, &aram_dump_fops);
if (!aram_dump_debugfs_file) {
pr_err("ERROR: failed to create aram_dump debugfs");
destroy_mem_manager(aram_handle);
return -ENOMEM;
}
}
#endif
return 0;
}
void nvadsp_aram_exit(void)
{
#ifdef CONFIG_DEBUG_FS
debugfs_remove(aram_dump_debugfs_file);
#endif
destroy_mem_manager(aram_handle);
}

View File

@@ -3,7 +3,7 @@
*
* dram app memory manager for allocating memory for text,bss and data
*
* Copyright (C) 2014-2018, NVIDIA Corporation. All rights reserved.
* Copyright (C) 2014-2022, NVIDIA Corporation. All rights reserved.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
@@ -50,7 +50,6 @@ unsigned long dram_app_mem_get_address(void *handle)
return mem_get_address(handle);
}
#ifdef CONFIG_DEBUG_FS
static struct dentry *dram_app_mem_dump_debugfs_file;
static int dram_app_mem_dump(struct seq_file *s, void *data)
@@ -70,7 +69,6 @@ static const struct file_operations dram_app_mem_dump_fops = {
.llseek = seq_lseek,
.release = single_release,
};
#endif
int dram_app_mem_init(unsigned long start, unsigned long size)
{
@@ -81,24 +79,22 @@ int dram_app_mem_init(unsigned long start, unsigned long size)
return PTR_ERR(dram_app_mem_handle);
}
#ifdef CONFIG_DEBUG_FS
dram_app_mem_dump_debugfs_file =
debugfs_create_file("dram_app_mem_dump",
S_IRUSR, NULL, NULL, &dram_app_mem_dump_fops);
if (!dram_app_mem_dump_debugfs_file) {
pr_err("ERROR: failed to create dram_app_mem_dump debugfs");
destroy_mem_manager(dram_app_mem_handle);
return -ENOMEM;
if (debugfs_initialized()) {
dram_app_mem_dump_debugfs_file =
debugfs_create_file("dram_app_mem_dump",
S_IRUSR, NULL, NULL, &dram_app_mem_dump_fops);
if (!dram_app_mem_dump_debugfs_file) {
pr_err("ERROR: failed to create dram_app_mem_dump debugfs");
destroy_mem_manager(dram_app_mem_handle);
return -ENOMEM;
}
}
#endif
return 0;
}
void dram_app_mem_exit(void)
{
#ifdef CONFIG_DEBUG_FS
debugfs_remove(dram_app_mem_dump_debugfs_file);
#endif
destroy_mem_manager(dram_app_mem_handle);
}