dma: debug: no need to check return value of debugfs_create functions
PATCH 1/1 dma: debug: no need to check return value of debugfs_create functions
When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this.
Also delete the variables for the file dentries for the debugfs entries as they are never used at all once they are created.
--- kernel/dma/debug.c | 81 ++++++---------------------------------------- 1 file changed, 10 insertions(+), 71 deletions(-)
kernel/dma/debug.c +10 -71
@@ -136,14 +136,6 @@ static u32 nr_prealloc_entries = PREALLOC_DMA_DEBUG_ENTRIES;/* debugfs dentry's for the stuff above */ static struct dentry *dma_debug_dent__read_mostly ; -static struct dentry *global_disable_dent__read_mostly ; -static struct dentry *error_count_dent__read_mostly ; -static struct dentry *show_all_errors_dent__read_mostly ; -static struct dentry *show_num_errors_dent__read_mostly ; -static struct dentry *num_free_entries_dent__read_mostly ; -static struct dentry *min_free_entries_dent__read_mostly ; -static struct dentry *nr_total_entries_dent__read_mostly ; -static struct dentry *filter_dent__read_mostly ;/* per-driver filter related state */
@@ -840,66 +832,18 @@ static const struct file_operations filter_fops = { .llseek = default_llseek, }; -static int dma_debug_fs_init (void ) +static void dma_debug_fs_init (void ) { dma_debug_dent =debugfs_create_dir ("dma-api" ,NULL ); -if (!dma_debug_dent) { -pr_err ("can not create debugfs directory\n" ); -return -ENOMEM ; - } - - global_disable_dent =debugfs_create_bool ("disabled" ,0444 , - dma_debug_dent, - &global_disable); -if (!global_disable_dent) - goto out_err; - - error_count_dent =debugfs_create_u32 ("error_count" ,0444 , - dma_debug_dent, &error_count); -if (!error_count_dent) - goto out_err; - - show_all_errors_dent =debugfs_create_u32 ("all_errors" ,0644 , - dma_debug_dent, - &show_all_errors); -if (!show_all_errors_dent) - goto out_err; - - show_num_errors_dent =debugfs_create_u32 ("num_errors" ,0644 , - dma_debug_dent, - &show_num_errors); -if (!show_num_errors_dent) - goto out_err; - - num_free_entries_dent =debugfs_create_u32 ("num_free_entries" ,0444 , - dma_debug_dent, - &num_free_entries); -if (!num_free_entries_dent) - goto out_err; - - min_free_entries_dent =debugfs_create_u32 ("min_free_entries" ,0444 , - dma_debug_dent, - &min_free_entries); -if (!min_free_entries_dent) - goto out_err; - - nr_total_entries_dent =debugfs_create_u32 ("nr_total_entries" ,0444 , - dma_debug_dent, - &nr_total_entries); -if (!nr_total_entries_dent) - goto out_err; - - filter_dent =debugfs_create_file ("driver_filter" ,0644 , - dma_debug_dent,NULL , &filter_fops); -if (!filter_dent) - goto out_err; - -return 0 ; -out_err: -debugfs_remove_recursive (dma_debug_dent); - -return -ENOMEM ; +debugfs_create_bool ("disabled" ,0444 , dma_debug_dent, &global_disable); +debugfs_create_u32 ("error_count" ,0444 , dma_debug_dent, &error_count); +debugfs_create_u32 ("all_errors" ,0644 , dma_debug_dent, &show_all_errors); +debugfs_create_u32 ("num_errors" ,0644 , dma_debug_dent, &show_num_errors); +debugfs_create_u32 ("num_free_entries" ,0444 , dma_debug_dent, &num_free_entries); +debugfs_create_u32 ("min_free_entries" ,0444 , dma_debug_dent, &min_free_entries); +debugfs_create_u32 ("nr_total_entries" ,0444 , dma_debug_dent, &nr_total_entries); +debugfs_create_file ("driver_filter" ,0644 , dma_debug_dent,NULL , &filter_fops); }static int device_dma_allocations (struct device *dev,struct dma_debug_entry **out_entry)
@@ -985,12 +929,7 @@ static int dma_debug_init(void)spin_lock_init (&dma_entry_hash[i].lock); } -if (dma_debug_fs_init () !=0 ) { -pr_err ("error creating debugfs entries - disabling\n" ); - global_disable = true; - -return 0 ; - } +dma_debug_fs_init (); nr_pages =DIV_ROUND_UP (nr_prealloc_entries,DMA_DEBUG_DYNAMIC_ENTRIES );for (i =0 ; i < nr_pages; ++i)
Signature · 1 line
2.20.1
Hi Greg,
Quoted 6 lines · Greg Kroah-Hartman
When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this.
Also delete the variables for the file dentries for the debugfs entries as they are never used at all once they are created.
Modulo one nit below, I certainly approve of the cleanup :)
Quoted 14 lines
Cc Christoph Hellwig <[email protected]>Cc Marek Szyprowski <[email protected]>Cc Robin Murphy <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- kernel/dma/debug.c | 81 ++++++---------------------------------------- 1 file changed, 10 insertions(+), 71 deletions(-)kernel/dma/debug.c +0
-0
kernel/dma/debug.c static u32 nr_prealloc_entries = PREALLOC_DMA_DEBUG_ENTRIES; · line 138
Quoted 3 lines
kernel/dma/debug.c +0
-0@@ -136,14 +136,6 @@ static u32 nr_prealloc_entries = PREALLOC_DMA_DEBUG_ENTRIES;/* debugfs dentry's for the stuff above */ static struct dentry *dma_debug_dent__read_mostly ;
Does this actually need to be at file scope, or could it be punted to a local in dma_debug_fs_init() while we're here?
Robin.
Quoted 102 lines
kernel/dma/debug.c +10
-71-static struct dentry *global_disable_dent__read_mostly ; -static struct dentry *error_count_dent__read_mostly ; -static struct dentry *show_all_errors_dent__read_mostly ; -static struct dentry *show_num_errors_dent__read_mostly ; -static struct dentry *num_free_entries_dent__read_mostly ; -static struct dentry *min_free_entries_dent__read_mostly ; -static struct dentry *nr_total_entries_dent__read_mostly ; -static struct dentry *filter_dent__read_mostly ;/* per-driver filter related state */ @@ -840,66 +832,18 @@ static const struct file_operations filter_fops = { .llseek = default_llseek, }; -static int dma_debug_fs_init (void ) +static void dma_debug_fs_init (void ) { dma_debug_dent =debugfs_create_dir ("dma-api" ,NULL ); -if (!dma_debug_dent) { -pr_err ("can not create debugfs directory\n" ); -return -ENOMEM ; - } - - global_disable_dent =debugfs_create_bool ("disabled" ,0444 , - dma_debug_dent, - &global_disable); -if (!global_disable_dent) - goto out_err; - - error_count_dent =debugfs_create_u32 ("error_count" ,0444 , - dma_debug_dent, &error_count); -if (!error_count_dent) - goto out_err; - - show_all_errors_dent =debugfs_create_u32 ("all_errors" ,0644 , - dma_debug_dent, - &show_all_errors); -if (!show_all_errors_dent) - goto out_err; - - show_num_errors_dent =debugfs_create_u32 ("num_errors" ,0644 , - dma_debug_dent, - &show_num_errors); -if (!show_num_errors_dent) - goto out_err; - - num_free_entries_dent =debugfs_create_u32 ("num_free_entries" ,0444 , - dma_debug_dent, - &num_free_entries); -if (!num_free_entries_dent) - goto out_err; - - min_free_entries_dent =debugfs_create_u32 ("min_free_entries" ,0444 , - dma_debug_dent, - &min_free_entries); -if (!min_free_entries_dent) - goto out_err; - - nr_total_entries_dent =debugfs_create_u32 ("nr_total_entries" ,0444 , - dma_debug_dent, - &nr_total_entries); -if (!nr_total_entries_dent) - goto out_err; - - filter_dent =debugfs_create_file ("driver_filter" ,0644 , - dma_debug_dent,NULL , &filter_fops); -if (!filter_dent) - goto out_err; - -return 0 ; -out_err: -debugfs_remove_recursive (dma_debug_dent); - -return -ENOMEM ; +debugfs_create_bool ("disabled" ,0444 , dma_debug_dent, &global_disable); +debugfs_create_u32 ("error_count" ,0444 , dma_debug_dent, &error_count); +debugfs_create_u32 ("all_errors" ,0644 , dma_debug_dent, &show_all_errors); +debugfs_create_u32 ("num_errors" ,0644 , dma_debug_dent, &show_num_errors); +debugfs_create_u32 ("num_free_entries" ,0444 , dma_debug_dent, &num_free_entries); +debugfs_create_u32 ("min_free_entries" ,0444 , dma_debug_dent, &min_free_entries); +debugfs_create_u32 ("nr_total_entries" ,0444 , dma_debug_dent, &nr_total_entries); +debugfs_create_file ("driver_filter" ,0644 , dma_debug_dent,NULL , &filter_fops); }static int device_dma_allocations (struct device *dev,struct dma_debug_entry **out_entry)@@ -985,12 +929,7 @@ static int dma_debug_init(void)spin_lock_init (&dma_entry_hash[i].lock); } -if (dma_debug_fs_init () !=0 ) { -pr_err ("error creating debugfs entries - disabling\n" ); - global_disable = true; - -return 0 ; - } +dma_debug_fs_init (); nr_pages =DIV_ROUND_UP (nr_prealloc_entries,DMA_DEBUG_DYNAMIC_ENTRIES );for (i =0 ; i < nr_pages; ++i)
Quoted 23 lines · Robin Murphy
Hi Greg,
Quoted 6 lines · Greg Kroah-Hartman
When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this.
Also delete the variables for the file dentries for the debugfs entries as they are never used at all once they are created.
Modulo one nit below, I certainly approve of the cleanup :)
Reviewed-by Robin Murphy <[email protected]>Quoted 9 lines
Cc Christoph Hellwig <[email protected]>Cc Marek Szyprowski <[email protected]>Cc Robin Murphy <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- kernel/dma/debug.c | 81 ++++++---------------------------------------- 1 file changed, 10 insertions(+), 71 deletions(-)
Quoted 10 lines
kernel/dma/debug.c static u32 nr_prealloc_entries = PREALLOC_DMA_DEBUG_ENTRIES; · line 137
Quoted 7 lines
kernel/dma/debug.c +0
-0@@ -136,14 +136,6 @@ static u32 nr_prealloc_entries = PREALLOC_DMA_DEBUG_ENTRIES;/* debugfs dentry's for the stuff above */ static struct dentry *dma_debug_dent__read_mostly ;Does this actually need to be at file scope, or could it be punted to a local in
dma_debug_fs_init()while we're here?
It can be moved to the function scope if you want me to, I was trying to do the least needed here :)
thanks,
greg k-h
Quoted 5 lines · Greg Kroah-Hartman
Quoted 2 lines
Does this actually need to be at file scope, or could it be punted to a local in
dma_debug_fs_init()while we're here?It can be moved to the function scope if you want me to, I was trying to do the least needed here :)
I've folded the scope move in when applying the patch to the dma-mapping for-next tree.
Thanks!
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Greg Kroah-Hartman
Quoted 2 lines
Does this actually need to be at file scope, or could it be punted to a local in
dma_debug_fs_init()while we're here?It can be moved to the function scope if you want me to, I was trying to do the least needed here :)
I've folded the scope move in when applying the patch to the dma-mapping for-next tree.
Wonderful, thanks!
greg k-h