From d40e2df1b27c2c1df088f457c1c183eac3f2478e Mon Sep 17 00:00:00 2001 From: Bharat Nihalani Date: Fri, 2 Dec 2022 17:15:08 +0530 Subject: [PATCH] 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 Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2820666 Reviewed-by: svc_kernel_abi Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-cert Reviewed-by: Suresh Venkatachalam Reviewed-by: Dara Ramesh GVS: Gerrit_Virtual_Submit --- drivers/platform/tegra/nvadsp/aram_manager.c | 22 +++++++---------- .../tegra/nvadsp/dram_app_mem_manager.c | 24 ++++++++----------- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/drivers/platform/tegra/nvadsp/aram_manager.c b/drivers/platform/tegra/nvadsp/aram_manager.c index 62182c7a..e575037b 100644 --- a/drivers/platform/tegra/nvadsp/aram_manager.c +++ b/drivers/platform/tegra/nvadsp/aram_manager.c @@ -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); } diff --git a/drivers/platform/tegra/nvadsp/dram_app_mem_manager.c b/drivers/platform/tegra/nvadsp/dram_app_mem_manager.c index ca809526..df45f019 100644 --- a/drivers/platform/tegra/nvadsp/dram_app_mem_manager.c +++ b/drivers/platform/tegra/nvadsp/dram_app_mem_manager.c @@ -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); }