powerpc: kernel: no need to check return value of debugfs_create functions
Subsystems (3)
PATCH 2/6 powerpc: kvm: no need to check return value of debugfs_create functions
In reply to Greg Kroah-HartmanWhen 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.
Because of this cleanup, we get to remove a few fields in struct kvm_arch that are now unused.
--- arch/powerpc/include/asm/kvm_host.h | 3 --- arch/powerpc/kvm/book3s_64_mmu_hv.c | 5 ++--- arch/powerpc/kvm/book3s_64_mmu_radix.c | 5 ++--- arch/powerpc/kvm/book3s_hv.c | 9 ++------- arch/powerpc/kvm/timing.c | 13 +++---------- 5 files changed, 9 insertions(+), 26 deletions(-)
arch/powerpc/include/asm/kvm_host.h +0 -3
@@ -308,8 +308,6 @@ struct kvm_arch {pgd_t *pgtable;u64 process_table;struct dentry *debugfs_dir; -struct dentry *htab_dentry; -struct dentry *radix_dentry;struct kvm_resize_hpt *resize_hpt;/* protected by kvm->lock */ #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
@@ -830,7 +828,6 @@ struct kvm_vcpu_arch {struct kvmhv_tb_accumulator cede_time;/* time napping inside guest */ struct dentry *debugfs_dir; -struct dentry *debugfs_timings;#endif /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */ };
arch/powerpc/kvm/book3s_64_mmu_hv.c +2 -3
@@ -2138,9 +2138,8 @@ static const struct file_operations debugfs_htab_fops = {void kvmppc_mmu_debugfs_init (struct kvm *kvm) { - kvm->arch.htab_dentry =debugfs_create_file ("htab" ,0400 , - kvm->arch.debugfs_dir, kvm, - &debugfs_htab_fops); +debugfs_create_file ("htab" ,0400 , kvm->arch.debugfs_dir, kvm, + &debugfs_htab_fops); }void kvmppc_mmu_book3s_hv_init (struct kvm_vcpu *vcpu)
arch/powerpc/kvm/book3s_64_mmu_radix.c +2 -3
@@ -1376,9 +1376,8 @@ static const struct file_operations debugfs_radix_fops = {void kvmhv_radix_debugfs_init (struct kvm *kvm) { - kvm->arch.radix_dentry =debugfs_create_file ("radix" ,0400 , - kvm->arch.debugfs_dir, kvm, - &debugfs_radix_fops); +debugfs_create_file ("radix" ,0400 , kvm->arch.debugfs_dir, kvm, + &debugfs_radix_fops); }int kvmppc_radix_init (void )
arch/powerpc/kvm/book3s_hv.c +2 -6
@@ -2258,14 +2258,9 @@ static void debugfs_vcpu_init(struct kvm_vcpu *vcpu, unsigned int id)struct kvm *kvm = vcpu->kvm;snprintf (buf,sizeof (buf),"vcpu%u" , id); -if (IS_ERR_OR_NULL (kvm->arch.debugfs_dir)) -return ; vcpu->arch.debugfs_dir =debugfs_create_dir (buf, kvm->arch.debugfs_dir); -if (IS_ERR_OR_NULL (vcpu->arch.debugfs_dir)) -return ; - vcpu->arch.debugfs_timings -debugfs_create_file ("timings" ,0444 , vcpu->arch.debugfs_dir, - vcpu, &debugfs_timings_ops); +debugfs_create_file ("timings" ,0444 , vcpu->arch.debugfs_dir, vcpu, + &debugfs_timings_ops); }#else /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */
arch/powerpc/kvm/timing.c +3 -10
@@ -207,19 +207,12 @@ static const struct file_operations kvmppc_exit_timing_fops = {void kvmppc_create_vcpu_debugfs (struct kvm_vcpu *vcpu,unsigned int id) {static char dbg_fname[50 ]; -struct dentry *debugfs_file;snprintf (dbg_fname,sizeof (dbg_fname),"vm%u_vcpu%u_timing" , current->pid, id); - debugfs_file =debugfs_create_file (dbg_fname,0666 , - kvm_debugfs_dir, vcpu, - &kvmppc_exit_timing_fops); - -if (!debugfs_file) { -printk (KERN_ERR "%s: error creating debugfs file %s\n" , - __func__, dbg_fname); -return ; - } +debugfs_create_file (dbg_fname,0666 , kvm_debugfs_dir, vcpu, + &kvmppc_exit_timing_fops); + vcpu->arch.debugfs_exit_timing = debugfs_file; }
Signature · 1 line
2.25.0
PATCH 3/6 powerpc: mm: book3s64: hash_utils: no need to check return value of debugfs_create functions
In reply to Greg Kroah-HartmanWhen 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.
--- arch/powerpc/mm/book3s64/hash_utils.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
arch/powerpc/mm/book3s64/hash_utils.c +2 -5
@@ -2018,11 +2018,8 @@ DEFINE_DEBUGFS_ATTRIBUTE(fops_hpt_order, hpt_order_get, hpt_order_set, "%llu\n")static int __init hash64_debugfs (void ) { -if (!debugfs_create_file_unsafe ("hpt_order" ,0600 , powerpc_debugfs_root, -NULL , &fops_hpt_order)) { -pr_err ("lpar: unable to create hpt_order debugsfs file\n" ); - } - +debugfs_create_file ("hpt_order" ,0600 , powerpc_debugfs_root,NULL , + &fops_hpt_order);return 0 ; }machine_device_initcall (pseries, hash64_debugfs);
Signature · 1 line
2.25.0
PATCH 4/6 powerpc: mm: ptdump: no need to check return value of debugfs_create functions
In reply to Greg Kroah-HartmanWhen 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.
--- arch/powerpc/mm/ptdump/bats.c | 8 +++----- arch/powerpc/mm/ptdump/hashpagetable.c | 7 ++----- arch/powerpc/mm/ptdump/ptdump.c | 8 +++----- arch/powerpc/mm/ptdump/segment_regs.c | 8 +++----- 4 files changed, 11 insertions(+), 20 deletions(-)
arch/powerpc/mm/ptdump/bats.c +3 -5
@@ -164,10 +164,8 @@ static const struct file_operations bats_fops = {static int __init bats_init (void ) { -struct dentry *debugfs_file; - - debugfs_file =debugfs_create_file ("block_address_translation" ,0400 , - powerpc_debugfs_root,NULL , &bats_fops); -return debugfs_file ?0 : -ENOMEM ; +debugfs_create_file ("block_address_translation" ,0400 , + powerpc_debugfs_root,NULL , &bats_fops); +return 0 ; }device_initcall (bats_init);
arch/powerpc/mm/ptdump/hashpagetable.c +2 -5
@@ -527,13 +527,10 @@ static const struct file_operations ptdump_fops = {static int ptdump_init (void ) { -struct dentry *debugfs_file; -if (!radix_enabled ()) {populate_markers (); - debugfs_file =debugfs_create_file ("kernel_hash_pagetable" , -0400 ,NULL ,NULL , &ptdump_fops); -return debugfs_file ?0 : -ENOMEM ; +debugfs_create_file ("kernel_hash_pagetable" ,0400 ,NULL ,NULL , + &ptdump_fops); }return 0 ; }
arch/powerpc/mm/ptdump/ptdump.c +3 -5
@@ -417,12 +417,10 @@ void ptdump_check_wx(void)static int ptdump_init (void ) { -struct dentry *debugfs_file; -populate_markers ();build_pgtable_complete_mask (); - debugfs_file =debugfs_create_file ("kernel_page_tables" ,0400 ,NULL , -NULL , &ptdump_fops); -return debugfs_file ?0 : -ENOMEM ; +debugfs_create_file ("kernel_page_tables" ,0400 ,NULL ,NULL , + &ptdump_fops); +return 0 ; }device_initcall (ptdump_init);
arch/powerpc/mm/ptdump/segment_regs.c +3 -5
@@ -55,10 +55,8 @@ static const struct file_operations sr_fops = {static int __init sr_init (void ) { -struct dentry *debugfs_file; - - debugfs_file =debugfs_create_file ("segment_registers" ,0400 , - powerpc_debugfs_root,NULL , &sr_fops); -return debugfs_file ?0 : -ENOMEM ; +debugfs_create_file ("segment_registers" ,0400 , powerpc_debugfs_root, +NULL , &sr_fops); +return 0 ; }device_initcall (sr_init);
Signature · 1 line
2.25.0
PATCH 5/6 powerpc: cell: axon_msi: no need to check return value of debugfs_create functions
In reply to Greg Kroah-HartmanWhen 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.
--- arch/powerpc/platforms/cell/axon_msi.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
arch/powerpc/platforms/cell/axon_msi.c +1 -5
@@ -480,10 +480,6 @@ void axon_msi_debug_setup(struct device_node *dn, struct axon_msic *msic)snprintf (name,sizeof (name),"msic_%d" ,of_node_to_nid (dn)); -if (!debugfs_create_file (name,0600 , powerpc_debugfs_root, - msic, &fops_msic)) { -pr_devel ("axon_msi: debugfs_create_file failed!\n" ); -return ; - } + debugfs_create_file(name, 0600, powerpc_debugfs_root, msic, &fops_msic); }#endif /* DEBUG */
Signature · 1 line
2.25.0
PATCH 6/6 powerpc: powernv: no need to check return value of debugfs_create functions
In reply to Greg Kroah-HartmanWhen 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.
--- arch/powerpc/platforms/powernv/memtrace.c | 7 ---- arch/powerpc/platforms/powernv/opal-imc.c | 24 ++++---------- arch/powerpc/platforms/powernv/pci-ioda.c | 5 --- arch/powerpc/platforms/powernv/vas-debug.c | 37 ++-------------------- 4 files changed, 10 insertions(+), 63 deletions(-)
arch/powerpc/platforms/powernv/memtrace.c +0 -7
@@ -187,11 +187,6 @@ static int memtrace_init_debugfs(void)snprintf (ent->name,16 ,"%08x" , ent->nid); dir =debugfs_create_dir (ent->name, memtrace_debugfs_dir); -if (!dir) { -pr_err ("Failed to create debugfs directory for node %d\n" , - ent->nid); -return -1 ; - } ent->dir = dir;debugfs_create_file ("trace" ,0400 , dir, ent, &memtrace_fops);
@@ -314,8 +309,6 @@ static int memtrace_init(void) { memtrace_debugfs_dir =debugfs_create_dir ("memtrace" , powerpc_debugfs_root); -if (!memtrace_debugfs_dir) -return -1 ;debugfs_create_file ("enable" ,0600 , memtrace_debugfs_dir,NULL , &memtrace_init_fops);
arch/powerpc/platforms/powernv/opal-imc.c +7 -17
@@ -35,11 +35,10 @@ static int imc_mem_set(void *data, u64 val) }DEFINE_DEBUGFS_ATTRIBUTE (fops_imc_x64, imc_mem_get, imc_mem_set,"0x%016llx\n" ); -static struct dentry *imc_debugfs_create_x64 (const char *name,umode_t mode, -struct dentry *parent,u64 *value) +static void imc_debugfs_create_x64 (const char *name,umode_t mode, +struct dentry *parent,u64 *value) { -return debugfs_create_file_unsafe (name, mode, parent, - value, &fops_imc_x64); +debugfs_create_file_unsafe (name, mode, parent, value, &fops_imc_x64); }/*
@@ -59,9 +58,6 @@ static void export_imc_mode_and_cmd(struct device_node *node, imc_debugfs_parent =debugfs_create_dir ("imc" , powerpc_debugfs_root); -if (!imc_debugfs_parent) -return ; -if (of_property_read_u32 (node,"cb_offset" , &cb_offset)) cb_offset =IMC_CNTL_BLK_OFFSET ;
@@ -69,21 +65,15 @@ static void export_imc_mode_and_cmd(struct device_node *node, loc = (u64)(ptr->vbase) + cb_offset; imc_mode_addr = (u64 *)(loc +IMC_CNTL_BLK_MODE_OFFSET );sprintf (mode,"imc_mode_%d" , (u32)(ptr->id)); -if (!imc_debugfs_create_x64 (mode,0600 , imc_debugfs_parent, - imc_mode_addr)) - goto err; +imc_debugfs_create_x64 (mode,0600 , imc_debugfs_parent, + imc_mode_addr); imc_cmd_addr = (u64 *)(loc +IMC_CNTL_BLK_CMD_OFFSET );sprintf (cmd,"imc_cmd_%d" , (u32)(ptr->id)); -if (!imc_debugfs_create_x64 (cmd,0600 , imc_debugfs_parent, - imc_cmd_addr)) - goto err; +imc_debugfs_create_x64 (cmd,0600 , imc_debugfs_parent, + imc_cmd_addr); ptr++; } -return ; - -err: -debugfs_remove_recursive (imc_debugfs_parent); }/*
arch/powerpc/platforms/powernv/pci-ioda.c +0 -5
@@ -3174,11 +3174,6 @@ static void pnv_pci_ioda_create_dbgfs(void)sprintf (name,"PCI%04x" , hose->global_number); phb->dbgfs =debugfs_create_dir (name, powerpc_debugfs_root); -if (!phb->dbgfs) { -pr_warn ("%s: Error on creating debugfs on PHB#%x\n" , - __func__, hose->global_number); -continue ; - }debugfs_create_file_unsafe ("dump_diag_regs" ,0200 , phb->dbgfs, phb, &pnv_pci_diag_data_fops);
arch/powerpc/platforms/powernv/vas-debug.c +3 -34
@@ -115,7 +115,7 @@ void vas_window_free_dbgdir(struct vas_window *window)void vas_window_init_dbgdir (struct vas_window *window) { -struct dentry *f, *d; +struct dentry *d;if (!window->vinst->dbgdir)return ;
@@ -127,28 +127,10 @@ void vas_window_init_dbgdir(struct vas_window *window)snprintf (window->dbgname,16 ,"w%d" , window->winid); d =debugfs_create_dir (window->dbgname, window->vinst->dbgdir); -if (IS_ERR (d)) - goto free_name; - window->dbgdir = d; - f =debugfs_create_file ("info" ,0444 , d, window, &info_fops); -if (IS_ERR (f)) - goto remove_dir; - - f =debugfs_create_file ("hvwc" ,0444 , d, window, &hvwc_fops); -if (IS_ERR (f)) - goto remove_dir; - -return ; - -remove_dir: -debugfs_remove_recursive (window->dbgdir); - window->dbgdir =NULL ; - -free_name: -kfree (window->dbgname); - window->dbgname =NULL ; +debugfs_create_file ("info" ,0444 , d, window, &info_fops); +debugfs_create_file ("hvwc" ,0444 , d, window, &hvwc_fops); }void vas_instance_init_dbgdir (struct vas_instance *vinst)
@@ -156,8 +138,6 @@ void vas_instance_init_dbgdir(struct vas_instance *vinst)struct dentry *d;vas_init_dbgdir (); -if (!vas_debugfs) -return ; vinst->dbgname =kzalloc (16 ,GFP_KERNEL );if (!vinst->dbgname)
@@ -166,16 +146,7 @@ void vas_instance_init_dbgdir(struct vas_instance *vinst)snprintf (vinst->dbgname,16 ,"v%d" , vinst->vas_id); d =debugfs_create_dir (vinst->dbgname, vas_debugfs); -if (IS_ERR (d)) - goto free_name; - vinst->dbgdir = d; -return ; - -free_name: -kfree (vinst->dbgname); - vinst->dbgname =NULL ; - vinst->dbgdir =NULL ; }/*
@@ -191,6 +162,4 @@ void vas_init_dbgdir(void) first_time = false; vas_debugfs =debugfs_create_dir ("vas" ,NULL ); -if (IS_ERR (vas_debugfs)) - vas_debugfs =NULL ; }
Signature · 1 line
2.25.0
PATCH 1/6 powerpc: kernel: 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.
--- arch/powerpc/kernel/fadump.c | 9 ++------- arch/powerpc/kernel/setup-common.c | 3 +-- arch/powerpc/kernel/traps.c | 25 +++++-------------------- 3 files changed, 8 insertions(+), 29 deletions(-)
arch/powerpc/kernel/fadump.c +2 -7
@@ -1432,7 +1432,6 @@ DEFINE_SHOW_ATTRIBUTE(fadump_region);static void fadump_init_files (void ) { -struct dentry *debugfs_file;int rc =0 ; rc =sysfs_create_file (kernel_kobj, &fadump_attr.attr);
@@ -1445,12 +1444,8 @@ static void fadump_init_files(void)printk (KERN_ERR "fadump: unable to create sysfs file" " fadump_registered (%d)\n" , rc); - debugfs_file =debugfs_create_file ("fadump_region" ,0444 , - powerpc_debugfs_root,NULL , - &fadump_region_fops); -if (!debugfs_file) -printk (KERN_ERR "fadump: unable to create debugfs file" -" fadump_region\n" ); +debugfs_create_file ("fadump_region" ,0444 , powerpc_debugfs_root,NULL , + &fadump_region_fops);if (fw_dump.dump_active) { rc =sysfs_create_file (kernel_kobj, &fadump_release_attr.attr);
arch/powerpc/kernel/setup-common.c +1 -2
@@ -787,8 +787,7 @@ EXPORT_SYMBOL(powerpc_debugfs_root);static int powerpc_debugfs_init (void ) { powerpc_debugfs_root =debugfs_create_dir ("powerpc" ,NULL ); - -return powerpc_debugfs_root ==NULL ; +return 0 ; }arch_initcall (powerpc_debugfs_init);#endif
arch/powerpc/kernel/traps.c +5 -20
@@ -2278,35 +2278,20 @@ void ppc_warn_emulated_print(const char *type)static int __init ppc_warn_emulated_init (void ) { -struct dentry *dir, *d; +struct dentry *dir;unsigned int i;struct ppc_emulated_entry *entries = (void *)&ppc_emulated; -if (!powerpc_debugfs_root) -return -ENODEV ; - dir =debugfs_create_dir ("emulated_instructions" , powerpc_debugfs_root); -if (!dir) -return -ENOMEM ; - d =debugfs_create_u32 ("do_warn" ,0644 , dir, - &ppc_warn_emulated); -if (!d) - goto fail; +debugfs_create_u32 ("do_warn" ,0644 , dir, &ppc_warn_emulated); -for (i =0 ; i <sizeof (ppc_emulated)/sizeof (*entries); i++) { - d =debugfs_create_u32 (entries[i].name,0644 , dir, - (u32 *)&entries[i].val.counter); -if (!d) - goto fail; - } +for (i =0 ; i <sizeof (ppc_emulated)/sizeof (*entries); i++) +debugfs_create_u32 (entries[i].name,0644 , dir, + (u32 *)&entries[i].val.counter);return 0 ; - -fail: -debugfs_remove_recursive (dir); -return -ENOMEM ; }device_initcall (ppc_warn_emulated_init);
Signature · 1 line
2.25.0
Re: [PATCH 6/6] powerpc: powernv: no need to check return value of debugfs_create functions
In reply to Greg Kroah-HartmanQuoted 4 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.
For memtrace debugfs is the only way to actually use the feature. It'd be nice if it still printed out *something* if it failed to create the files rather than just being mysteriously absent, but maybe debugfs itself does that. Looks fine otherwise.
Quoted 189 lines
Cc Benjamin Herrenschmidt <[email protected]>Cc Paul Mackerras <[email protected]>Cc Michael Ellerman <[email protected]>Cc Sukadev Bhattiprolu <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- arch/powerpc/platforms/powernv/memtrace.c | 7 ---- arch/powerpc/platforms/powernv/opal-imc.c | 24 ++++---------- arch/powerpc/platforms/powernv/pci-ioda.c | 5 --- arch/powerpc/platforms/powernv/vas-debug.c | 37 ++-------------------- 4 files changed, 10 insertions(+), 63 deletions(-)arch/powerpc/platforms/powernv/memtrace.c +0
-7@@ -187,11 +187,6 @@ static int memtrace_init_debugfs(void)snprintf (ent->name,16 ,"%08x" , ent->nid); dir =debugfs_create_dir (ent->name, memtrace_debugfs_dir); -if (!dir) { -pr_err ("Failed to create debugfs directory for node %d\n" , - ent->nid); -return -1 ; - } ent->dir = dir;debugfs_create_file ("trace" ,0400 , dir, ent, &memtrace_fops);@@ -314,8 +309,6 @@ static int memtrace_init(void) { memtrace_debugfs_dir =debugfs_create_dir ("memtrace" , powerpc_debugfs_root); -if (!memtrace_debugfs_dir) -return -1 ;debugfs_create_file ("enable" ,0600 , memtrace_debugfs_dir,NULL , &memtrace_init_fops);arch/powerpc/platforms/powernv/opal-imc.c +7
-17@@ -35,11 +35,10 @@ static int imc_mem_set(void *data, u64 val) }DEFINE_DEBUGFS_ATTRIBUTE (fops_imc_x64, imc_mem_get, imc_mem_set,"0x%016llx\n" ); -static struct dentry *imc_debugfs_create_x64 (const char *name,umode_t mode, -struct dentry *parent,u64 *value) +static void imc_debugfs_create_x64 (const char *name,umode_t mode, +struct dentry *parent,u64 *value) { -return debugfs_create_file_unsafe (name, mode, parent, - value, &fops_imc_x64); +debugfs_create_file_unsafe (name, mode, parent, value, &fops_imc_x64); }/* @@ -59,9 +58,6 @@ static void export_imc_mode_and_cmd(struct device_node *node, imc_debugfs_parent =debugfs_create_dir ("imc" , powerpc_debugfs_root); -if (!imc_debugfs_parent) -return ; -if (of_property_read_u32 (node,"cb_offset" , &cb_offset)) cb_offset =IMC_CNTL_BLK_OFFSET ;@@ -69,21 +65,15 @@ static void export_imc_mode_and_cmd(struct device_node *node, loc = (u64)(ptr->vbase) + cb_offset; imc_mode_addr = (u64 *)(loc +IMC_CNTL_BLK_MODE_OFFSET );sprintf (mode,"imc_mode_%d" , (u32)(ptr->id)); -if (!imc_debugfs_create_x64 (mode,0600 , imc_debugfs_parent, - imc_mode_addr)) - goto err; +imc_debugfs_create_x64 (mode,0600 , imc_debugfs_parent, + imc_mode_addr); imc_cmd_addr = (u64 *)(loc +IMC_CNTL_BLK_CMD_OFFSET );sprintf (cmd,"imc_cmd_%d" , (u32)(ptr->id)); -if (!imc_debugfs_create_x64 (cmd,0600 , imc_debugfs_parent, - imc_cmd_addr)) - goto err; +imc_debugfs_create_x64 (cmd,0600 , imc_debugfs_parent, + imc_cmd_addr); ptr++; } -return ; - -err: -debugfs_remove_recursive (imc_debugfs_parent); }/* arch/powerpc/platforms/powernv/pci-ioda.c +0
-5@@ -3174,11 +3174,6 @@ static void pnv_pci_ioda_create_dbgfs(void)sprintf (name,"PCI%04x" , hose->global_number); phb->dbgfs =debugfs_create_dir (name, powerpc_debugfs_root); -if (!phb->dbgfs) { -pr_warn ("%s: Error on creating debugfs on PHB#%x\n" , - __func__, hose->global_number); -continue ; - }debugfs_create_file_unsafe ("dump_diag_regs" ,0200 , phb->dbgfs, phb, &pnv_pci_diag_data_fops);arch/powerpc/platforms/powernv/vas-debug.c +3
-35@@ -115,7 +115,7 @@ void vas_window_free_dbgdir(struct vas_window *window)void vas_window_init_dbgdir (struct vas_window *window) { -struct dentry *f, *d; +struct dentry *d;if (!window->vinst->dbgdir)return ;@@ -127,28 +127,10 @@ void vas_window_init_dbgdir(struct vas_window *window)snprintf (window->dbgname,16 ,"w%d" , window->winid); d =debugfs_create_dir (window->dbgname, window->vinst->dbgdir); -if (IS_ERR (d)) - goto free_name; - window->dbgdir = d; - f =debugfs_create_file ("info" ,0444 , d, window, &info_fops); -if (IS_ERR (f)) - goto remove_dir; - - f =debugfs_create_file ("hvwc" ,0444 , d, window, &hvwc_fops); -if (IS_ERR (f)) - goto remove_dir; - -return ; - -remove_dir: -debugfs_remove_recursive (window->dbgdir); - window->dbgdir =NULL ; - -free_name: -kfree (window->dbgname); - window->dbgname =NULL ; +debugfs_create_file ("info" ,0444 , d, window, &info_fops); +debugfs_create_file ("hvwc" ,0444 , d, window, &hvwc_fops); }void vas_instance_init_dbgdir (struct vas_instance *vinst)@@ -156,8 +138,6 @@ void vas_instance_init_dbgdir(struct vas_instance *vinst)struct dentry *d;vas_init_dbgdir (); -if (!vas_debugfs) -return ; vinst->dbgname =kzalloc (16 ,GFP_KERNEL );if (!vinst->dbgname)@@ -166,16 +146,7 @@ void vas_instance_init_dbgdir(struct vas_instance *vinst)snprintf (vinst->dbgname,16 ,"v%d" , vinst->vas_id); d =debugfs_create_dir (vinst->dbgname, vas_debugfs); -if (IS_ERR (d)) - goto free_name; - vinst->dbgdir = d; -return ; - -free_name: -kfree (vinst->dbgname); - vinst->dbgname =NULL ; - vinst->dbgdir =NULL ; }/* @@ -191,6 +162,4 @@ void vas_init_dbgdir(void) first_time = false; vas_debugfs =debugfs_create_dir ("vas" ,NULL ); -if (IS_ERR (vas_debugfs)) - vas_debugfs =NULL ; } --2.25.0
Re: [PATCH 6/6] powerpc: powernv: no need to check return value of debugfs_create functions
Quoted 11 lines · Oliver O'Halloran
Quoted 4 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.
For memtrace debugfs is the only way to actually use the feature. It'd be nice if it still printed out *something* if it failed to create the files rather than just being mysteriously absent, but maybe debugfs itself does that. Looks fine otherwise.
No, debugfs will only spit out an error message to the log if a file/directory is attempted to be created for an already present file/directory.
For other failures, no error will be printed, other than the normal lower-level "out of memory" issues that might rarely happen.
thanks,
greg k-h
Michael Ellerman
reviewerRe: [PATCH 2/6] powerpc: kvm: no need to check return value of debugfs_create functions
In reply to Greg Kroah-HartmanQuoted 3 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.
Except it does need to do something different, if the file was created it needs to be removed in the remove path.
Quoted 17 lines
arch/powerpc/kvm/timing.c +0
-6@@ -207,19 +207,12 @@ static const struct file_operations kvmppc_exit_timing_fops = {void kvmppc_create_vcpu_debugfs (struct kvm_vcpu *vcpu,unsigned int id) {static char dbg_fname[50 ]; -struct dentry *debugfs_file;snprintf (dbg_fname,sizeof (dbg_fname),"vm%u_vcpu%u_timing" , current->pid, id); - debugfs_file =debugfs_create_file (dbg_fname,0666 , - kvm_debugfs_dir, vcpu, - &kvmppc_exit_timing_fops); - -if (!debugfs_file) {
arch/powerpc/kvm/timing.c static const struct file_operations kvmppc_exit_timing_fops = { · line 218
Quoted 10 lines
arch/powerpc/kvm/timing.c +3
-4-printk (KERN_ERR "%s: error creating debugfs file %s\n" , - __func__, dbg_fname); -return ; - } +debugfs_create_file (dbg_fname,0666 , kvm_debugfs_dir, vcpu, + &kvmppc_exit_timing_fops); + vcpu->arch.debugfs_exit_timing = debugfs_file; }
This doesn't build:
arch/powerpc/kvm/timing.c:217:35: error: 'debugfs_file' undeclared (first use in this function); did you mean 'debugfs_file_put'?
We can't just drop the assignment, we need the dentry to do the removal:
void kvmppc_remove_vcpu_debugfs(struct kvm_vcpu *vcpu)
{
if (vcpu->arch.debugfs_exit_timing) {
debugfs_remove(vcpu->arch.debugfs_exit_timing);
vcpu->arch.debugfs_exit_timing = NULL;
}
}I squashed this in, which seems to work:
arch/powerpc/kvm/timing.c +4 -4
@@ -207,19 +207,19 @@ static const struct file_operations kvmppc_exit_timing_fops = {void kvmppc_create_vcpu_debugfs (struct kvm_vcpu *vcpu,unsigned int id) {static char dbg_fname[50 ]; +struct dentry *debugfs_file;snprintf (dbg_fname,sizeof (dbg_fname),"vm%u_vcpu%u_timing" , current->pid, id); -debugfs_create_file (dbg_fname,0666 , kvm_debugfs_dir, vcpu, - &kvmppc_exit_timing_fops); - + debugfs_file =debugfs_create_file (dbg_fname,0666 , kvm_debugfs_dir, + vcpu, &kvmppc_exit_timing_fops); vcpu->arch.debugfs_exit_timing = debugfs_file; }void kvmppc_remove_vcpu_debugfs (struct kvm_vcpu *vcpu) { -if (vcpu->arch.debugfs_exit_timing) { +if (!IS_ERR_OR_NULL (vcpu->arch.debugfs_exit_timing)) {debugfs_remove (vcpu->arch.debugfs_exit_timing); vcpu->arch.debugfs_exit_timing =NULL ; }
cheers
Re: [PATCH 2/6] powerpc: kvm: no need to check return value of debugfs_create functions
Quoted 33 lines · Michael Ellerman
Quoted 3 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.
Except it does need to do something different, if the file was created it needs to be removed in the remove path.
Quoted 25 lines
arch/powerpc/kvm/timing.c +3
-10@@ -207,19 +207,12 @@ static const struct file_operations kvmppc_exit_timing_fops = {void kvmppc_create_vcpu_debugfs (struct kvm_vcpu *vcpu,unsigned int id) {static char dbg_fname[50 ]; -struct dentry *debugfs_file;snprintf (dbg_fname,sizeof (dbg_fname),"vm%u_vcpu%u_timing" , current->pid, id); - debugfs_file =debugfs_create_file (dbg_fname,0666 , - kvm_debugfs_dir, vcpu, - &kvmppc_exit_timing_fops); - -if (!debugfs_file) { -printk (KERN_ERR "%s: error creating debugfs file %s\n" , - __func__, dbg_fname); -return ; - } +debugfs_create_file (dbg_fname,0666 , kvm_debugfs_dir, vcpu, + &kvmppc_exit_timing_fops); +
Quoted 1 line
arch/powerpc/kvm/timing.c static const struct file_operations kvmppc_exit_timing_fops = { · line 217
Quoted 1 line
arch/powerpc/kvm/timing.c +0
-0vcpu->arch.debugfs_exit_timing = debugfs_file;
Ugh, you are right, how did I miss that? How is 0-day missing this? It's been in my tree for a long time, odd.
Quoted 28 lines
arch/powerpc/kvm/timing.c static const struct file_operations kvmppc_exit_timing_fops = { · line 218
Quoted 1 line
arch/powerpc/kvm/timing.c +0
-0}This doesn't build:
arch/powerpc/kvm/timing.c:217:35: error: 'debugfs_file' undeclared (first use in this function); did you mean 'debugfs_file_put'?We can't just drop the assignment, we need the dentry to do the removal:
void
kvmppc_remove_vcpu_debugfs(struct kvm_vcpu *vcpu){ if (vcpu->arch.debugfs_exit_timing) { debugfs_remove(vcpu->arch.debugfs_exit_timing); vcpu->arch.debugfs_exit_timing = NULL; } }I squashed this in, which seems to work:
arch/powerpc/kvm/timing.c +1
-0@@ -207,19 +207,19 @@ static const struct file_operations kvmppc_exit_timing_fops = {void kvmppc_create_vcpu_debugfs (struct kvm_vcpu *vcpu,unsigned int id) {static char dbg_fname[50 ]; +struct dentry *debugfs_file;
arch/powerpc/kvm/timing.c static const struct file_operations kvmppc_exit_timing_fops = { · line 217
Quoted 10 lines
arch/powerpc/kvm/timing.c +2
-3snprintf (dbg_fname,sizeof (dbg_fname),"vm%u_vcpu%u_timing" , current->pid, id); -debugfs_create_file (dbg_fname,0666 , kvm_debugfs_dir, vcpu, - &kvmppc_exit_timing_fops); - + debugfs_file =debugfs_create_file (dbg_fname,0666 , kvm_debugfs_dir, + vcpu, &kvmppc_exit_timing_fops); vcpu->arch.debugfs_exit_timing = debugfs_file;
That works, yes.
arch/powerpc/kvm/timing.c static const struct file_operations kvmppc_exit_timing_fops = { · line 225
Quoted 9 lines
arch/powerpc/kvm/timing.c +1
-1}void kvmppc_remove_vcpu_debugfs (struct kvm_vcpu *vcpu) { -if (vcpu->arch.debugfs_exit_timing) { +if (!IS_ERR_OR_NULL (vcpu->arch.debugfs_exit_timing)) {debugfs_remove (vcpu->arch.debugfs_exit_timing); vcpu->arch.debugfs_exit_timing =NULL ; }
No, this can just be:
debugfs_remove(vcpu->arch.debugfs_exit_timing);
No need to check anything, just call it and the debugfs code can handle it just fine.
thanks,
greg k-h
Michael Ellerman
reviewerRe: [PATCH 2/6] powerpc: kvm: no need to check return value of debugfs_create functions
Quoted 34 lines · Greg Kroah-Hartman
Quoted 33 lines · Michael Ellerman
Quoted 3 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.
Except it does need to do something different, if the file was created it needs to be removed in the remove path.
Quoted 25 lines
arch/powerpc/kvm/timing.c +3
-10@@ -207,19 +207,12 @@ static const struct file_operations kvmppc_exit_timing_fops = {void kvmppc_create_vcpu_debugfs (struct kvm_vcpu *vcpu,unsigned int id) {static char dbg_fname[50 ]; -struct dentry *debugfs_file;snprintf (dbg_fname,sizeof (dbg_fname),"vm%u_vcpu%u_timing" , current->pid, id); - debugfs_file =debugfs_create_file (dbg_fname,0666 , - kvm_debugfs_dir, vcpu, - &kvmppc_exit_timing_fops); - -if (!debugfs_file) { -printk (KERN_ERR "%s: error creating debugfs file %s\n" , - __func__, dbg_fname); -return ; - } +debugfs_create_file (dbg_fname,0666 , kvm_debugfs_dir, vcpu, + &kvmppc_exit_timing_fops); +
Quoted 4 lines
Quoted 1 line
arch/powerpc/kvm/timing.c static const struct file_operations kvmppc_exit_timing_fops = { · line 217
Quoted 1 line
arch/powerpc/kvm/timing.c +0
-0vcpu->arch.debugfs_exit_timing = debugfs_file;Ugh, you are right, how did I miss that? How is 0-day missing this? It's been in my tree for a long time, odd.
This code isn't enabled by default, or in any defconfig. So it's only allmodconfig that would trip it, I guess 0-day isn't doing powerpc allmodconfig builds.
Quoted 1 line
Quoted 1 line
I squashed this in, which seems to work:
...
Quoted 9 lines
arch/powerpc/kvm/timing.c static const struct file_operations kvmppc_exit_timing_fops = { · line 225
Quoted 8 lines
void
kvmppc_remove_vcpu_debugfs(struct kvm_vcpu *vcpu){arch/powerpc/kvm/timing.c +1
-1-if (vcpu->arch.debugfs_exit_timing) { +if (!IS_ERR_OR_NULL (vcpu->arch.debugfs_exit_timing)) {debugfs_remove (vcpu->arch.debugfs_exit_timing); vcpu->arch.debugfs_exit_timing =NULL ; }
Quoted 5 lines
No, this can just be:
debugfs_remove(vcpu->arch.debugfs_exit_timing);No need to check anything, just call it and the debugfs code can handle it just fine.
Oh duh, of course, I should have checked.
I'd still like to NULL out the debugfs_exit_timing member, so I'll do:
void kvmppc_remove_vcpu_debugfs(struct kvm_vcpu *vcpu)
{
debugfs_remove(vcpu->arch.debugfs_exit_timing);
vcpu->arch.debugfs_exit_timing = NULL;
}cheers
Michael Ellerman
reviewerRe: [PATCH 6/6] powerpc: powernv: no need to check return value of debugfs_create functions
In reply to Oliver O'HalloranQuoted 10 lines · Oliver O'Halloran
Quoted 4 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.
For memtrace debugfs is the only way to actually use the feature. It'd be nice if it still printed out *something* if it failed to create the files rather than just being mysteriously absent
That's true, but the current code doesn't actually do that anyway.
Quoted 6 lines
Quoted 6 lines
arch/powerpc/platforms/powernv/memtrace.c +0
-0@@ -187,11 +187,6 @@ static int memtrace_init_debugfs(void)
Quoted 7 lines
arch/powerpc/platforms/powernv/memtrace.c static int memtrace_init_debugfs(void) · line 194
Quoted 7 lines
arch/powerpc/platforms/powernv/memtrace.c +0
-5snprintf (ent->name,16 ,"%08x" , ent->nid); dir =debugfs_create_dir (ent->name, memtrace_debugfs_dir); -if (!dir) { -pr_err ("Failed to create debugfs directory for node %d\n" , - ent->nid); -return -1 ; - }
debugfs_create_dir() doesn't return NULL on error, it returns ERR_PTR(-ENOMEM), which will not trigger that pr_err().
So I've merged this and if someone wants to they can send a follow-up to do proper error checking in memtrace.c
cheers
Re: [PATCH 2/6] powerpc: kvm: no need to check return value of debugfs_create functions
In reply to Michael EllermanQuoted 63 lines · Michael Ellerman
Quoted 34 lines · Greg Kroah-Hartman
Quoted 33 lines · Michael Ellerman
Quoted 3 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.
Except it does need to do something different, if the file was created it needs to be removed in the remove path.
Quoted 25 lines
arch/powerpc/kvm/timing.c +3
-10@@ -207,19 +207,12 @@ static const struct file_operations kvmppc_exit_timing_fops = {void kvmppc_create_vcpu_debugfs (struct kvm_vcpu *vcpu,unsigned int id) {static char dbg_fname[50 ]; -struct dentry *debugfs_file;snprintf (dbg_fname,sizeof (dbg_fname),"vm%u_vcpu%u_timing" , current->pid, id); - debugfs_file =debugfs_create_file (dbg_fname,0666 , - kvm_debugfs_dir, vcpu, - &kvmppc_exit_timing_fops); - -if (!debugfs_file) { -printk (KERN_ERR "%s: error creating debugfs file %s\n" , - __func__, dbg_fname); -return ; - } +debugfs_create_file (dbg_fname,0666 , kvm_debugfs_dir, vcpu, + &kvmppc_exit_timing_fops); +Quoted 4 lines
Quoted 1 line
arch/powerpc/kvm/timing.c static const struct file_operations kvmppc_exit_timing_fops = { · line 217
Quoted 1 line
arch/powerpc/kvm/timing.c +0
-0vcpu->arch.debugfs_exit_timing = debugfs_file;Ugh, you are right, how did I miss that? How is 0-day missing this? It's been in my tree for a long time, odd.
This code isn't enabled by default, or in any defconfig. So it's only allmodconfig that would trip it, I guess 0-day isn't doing powerpc allmodconfig builds.
Quoted 1 line
Quoted 1 line
I squashed this in, which seems to work:
...
Quoted 9 lines
arch/powerpc/kvm/timing.c static const struct file_operations kvmppc_exit_timing_fops = { · line 225
Quoted 8 lines
void
kvmppc_remove_vcpu_debugfs(struct kvm_vcpu *vcpu){arch/powerpc/kvm/timing.c +1
-1-if (vcpu->arch.debugfs_exit_timing) { +if (!IS_ERR_OR_NULL (vcpu->arch.debugfs_exit_timing)) {debugfs_remove (vcpu->arch.debugfs_exit_timing); vcpu->arch.debugfs_exit_timing =NULL ; }Quoted 5 lines
No, this can just be:
debugfs_remove(vcpu->arch.debugfs_exit_timing);No need to check anything, just call it and the debugfs code can handle it just fine.
Oh duh, of course, I should have checked.
Quoted 7 lines
I'd still like to NULL out the
debugfs_exit_timingmember, so I'll do:void
kvmppc_remove_vcpu_debugfs(struct kvm_vcpu *vcpu){ debugfs_remove(vcpu->arch.debugfs_exit_timing); vcpu->arch.debugfs_exit_timing = NULL; }
Fair enough, but I doubt it ever matters :)
Thanks for the fixups, sorry for sending a broken patch, my fault.
greg k-h
Michael Ellerman
reviewerRe: [PATCH 2/6] powerpc: kvm: no need to check return value of debugfs_create functions
Quoted 66 lines · Greg Kroah-Hartman
Quoted 65 lines · Michael Ellerman
Quoted 34 lines · Greg Kroah-Hartman
Quoted 33 lines · Michael Ellerman
Quoted 3 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.
Except it does need to do something different, if the file was created it needs to be removed in the remove path.
Quoted 25 lines
arch/powerpc/kvm/timing.c +3
-10@@ -207,19 +207,12 @@ static const struct file_operations kvmppc_exit_timing_fops = {void kvmppc_create_vcpu_debugfs (struct kvm_vcpu *vcpu,unsigned int id) {static char dbg_fname[50 ]; -struct dentry *debugfs_file;snprintf (dbg_fname,sizeof (dbg_fname),"vm%u_vcpu%u_timing" , current->pid, id); - debugfs_file =debugfs_create_file (dbg_fname,0666 , - kvm_debugfs_dir, vcpu, - &kvmppc_exit_timing_fops); - -if (!debugfs_file) { -printk (KERN_ERR "%s: error creating debugfs file %s\n" , - __func__, dbg_fname); -return ; - } +debugfs_create_file (dbg_fname,0666 , kvm_debugfs_dir, vcpu, + &kvmppc_exit_timing_fops); +Quoted 4 lines
Quoted 1 line
arch/powerpc/kvm/timing.c static const struct file_operations kvmppc_exit_timing_fops = { · line 217
Quoted 1 line
arch/powerpc/kvm/timing.c +0
-0vcpu->arch.debugfs_exit_timing = debugfs_file;Ugh, you are right, how did I miss that? How is 0-day missing this? It's been in my tree for a long time, odd.
This code isn't enabled by default, or in any defconfig. So it's only allmodconfig that would trip it, I guess 0-day isn't doing powerpc allmodconfig builds.
Quoted 1 line
Quoted 1 line
I squashed this in, which seems to work:
...
Quoted 9 lines
arch/powerpc/kvm/timing.c static const struct file_operations kvmppc_exit_timing_fops = { · line 225
Quoted 8 lines
void
kvmppc_remove_vcpu_debugfs(struct kvm_vcpu *vcpu){arch/powerpc/kvm/timing.c +1
-1-if (vcpu->arch.debugfs_exit_timing) { +if (!IS_ERR_OR_NULL (vcpu->arch.debugfs_exit_timing)) {debugfs_remove (vcpu->arch.debugfs_exit_timing); vcpu->arch.debugfs_exit_timing =NULL ; }Quoted 5 lines
No, this can just be:
debugfs_remove(vcpu->arch.debugfs_exit_timing);No need to check anything, just call it and the debugfs code can handle it just fine.
Oh duh, of course, I should have checked.
I'd still like to NULL out the
debugfs_exit_timingmember, so I'll do:
Quoted 7 lines
Quoted 5 lines
void
kvmppc_remove_vcpu_debugfs(struct kvm_vcpu *vcpu){ debugfs_remove(vcpu->arch.debugfs_exit_timing); vcpu->arch.debugfs_exit_timing = NULL; }Fair enough, but I doubt it ever matters :)
Yeah, but I'm paranoid and I have no way to test this code :)
Quoted 1 line
Thanks for the fixups, sorry for sending a broken patch, my fault.
No worries, we have too many CONFIG options.
cheers
Quoted 10 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.
Cc Benjamin Herrenschmidt <[email protected]>Cc Paul Mackerras <[email protected]>Cc Michael Ellerman <[email protected]>Cc Hari Bathini <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
Series applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/860286cf33963fa8a0fe542995bdec2df5cb3abb
cheers