Skip to contentSkip to conversation

mips: cleanup debugfs usage

PATCH In review Greg Kroah-Hartman 3 participants 11 messages Jan 22, 2019 – Jan 23, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover mips: cleanup debugfs usage

When calling debugfs code, there is no need to ever check the return value of the call, as no logic should ever change if a call works properly or not. Fix up a bunch of x86-specific code to not care about the results of debugfs.

Greg Kroah-Hartman (5):
mips: cavium: no need to check return value of debugfs_create
functions
mips: ralink: no need to check return value of debugfs_create
functions
mips: mm: no need to check return value of debugfs_create functions
mips: math-emu: no need to check return value of debugfs_create
functions
mips: kernel: no need to check return value of debugfs_create
functions

 arch/mips/cavium-octeon/oct_ilm.c     | 31 ++++-----------------------
 arch/mips/kernel/mips-r2-to-r6-emul.c | 21 ++++--------------
 arch/mips/kernel/segment.c            | 15 +++----------
 arch/mips/kernel/setup.c              |  7 +-----
 arch/mips/kernel/spinlock_test.c      | 21 ++++--------------
 arch/mips/kernel/unaligned.c          | 16 ++++----------
 arch/mips/math-emu/me-debugfs.c       | 23 ++++----------------
 arch/mips/mm/sc-debugfs.c             | 15 +++----------
 arch/mips/ralink/bootrom.c            |  8 +------
 9 files changed, 28 insertions(+), 129 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/5 mips: cavium: 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/mips/cavium-octeon/oct_ilm.c | 31 ++++---------------------------
 1 file changed, 4 insertions(+), 27 deletions(-)
arch/mips/cavium-octeon/oct_ilm.c +4 -27
index 2d68a39f1443..0b6ec4c17896 100644
@@ -63,31 +63,12 @@ static int reset_statistics(void *data, u64 value)
 
 DEFINE_SIMPLE_ATTRIBUTE(reset_statistics_ops, NULL, reset_statistics, "%llu\n");
 
-static int init_debufs(void)
+static void init_debugfs(void)
 {
-	struct dentry *show_dentry;
 	dir = debugfs_create_dir("oct_ilm", 0);
-	if (!dir) {
-		pr_err("oct_ilm: failed to create debugfs entry oct_ilm\n");
-		return -1;
-	}
-
-	show_dentry = debugfs_create_file("statistics", 0222, dir, NULL,
-					  &oct_ilm_ops);
-	if (!show_dentry) {
-		pr_err("oct_ilm: failed to create debugfs entry oct_ilm/statistics\n");
-		return -1;
-	}
-
-	show_dentry = debugfs_create_file("reset", 0222, dir, NULL,
-					  &reset_statistics_ops);
-	if (!show_dentry) {
-		pr_err("oct_ilm: failed to create debugfs entry oct_ilm/reset\n");
-		return -1;
-	}
-
+	debugfs_create_file("statistics", 0222, dir, NULL, &oct_ilm_ops);
+	debugfs_create_file("reset", 0222, dir, NULL, &reset_statistics_ops);
 	return 0;
-
 }
 
 static void init_latency_info(struct latency_info *li, int startup)
@@ -169,11 +150,7 @@ static __init int oct_ilm_module_init(void)
 	int rc;
 	int irq = OCTEON_IRQ_TIMER0 + TIMER_NUM;
 
-	rc = init_debufs();
-	if (rc) {
-		WARN(1, "Could not create debugfs entries");
-		return rc;
-	}
+	init_debugfs();
 
 	rc = request_irq(irq, cvm_oct_ciu_timer_interrupt, IRQF_NO_THREAD,
 			 "oct_ilm", 0);
Signature · 1 line
2.20.1
#6 lore raw

PATCH 2/5 mips: ralink: no need to check return value of debugfs_create functions

In reply to 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 John Crispin <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Paul Burton <[email protected]>
Cc James Hogan <[email protected]>
---
 arch/mips/ralink/bootrom.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
arch/mips/ralink/bootrom.c +1 -7
index e1fa5972a81d..648f5eb2ba68 100644
@@ -35,13 +35,7 @@ static const struct file_operations bootrom_file_ops = {
 
 static int bootrom_setup(void)
 {
-	if (!debugfs_create_file("bootrom", 0444,
-			NULL, NULL, &bootrom_file_ops)) {
-		pr_err("Failed to create bootrom debugfs file\n");
-
-		return -EINVAL;
-	}
-
+	debugfs_create_file("bootrom", 0444, NULL, NULL, &bootrom_file_ops);
 	return 0;
 }
 
Signature · 1 line
2.20.1
#7 lore raw

PATCH 3/5 mips: mm: no need to check return value of debugfs_create functions

In reply to 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 Ralf Baechle <[email protected]>
Cc Paul Burton <[email protected]>
Cc James Hogan <[email protected]>
Cc Andy Shevchenko <[email protected]>
---
 arch/mips/mm/sc-debugfs.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
arch/mips/mm/sc-debugfs.c +3 -12
index 2a116084216f..9507421de335 100644
@@ -55,20 +55,11 @@ static const struct file_operations sc_prefetch_fops = {
 
 static int __init sc_debugfs_init(void)
 {
-	struct dentry *dir, *file;
-
-	if (!mips_debugfs_dir)
-		return -ENODEV;
+	struct dentry *dir;
 
 	dir = debugfs_create_dir("l2cache", mips_debugfs_dir);
-	if (IS_ERR(dir))
-		return PTR_ERR(dir);
-
-	file = debugfs_create_file("prefetch", S_IRUGO | S_IWUSR, dir,
-				   NULL, &sc_prefetch_fops);
-	if (!file)
-		return -ENOMEM;
-
+	debugfs_create_file("prefetch", S_IRUGO | S_IWUSR, dir, NULL,
+			    &sc_prefetch_fops);
 	return 0;
 }
 late_initcall(sc_debugfs_init);
Signature · 1 line
2.20.1
#9 lore raw

PATCH 5/5 mips: kernel: no need to check return value of debugfs_create functions

In reply to 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 Ralf Baechle <[email protected]>
Cc Paul Burton <[email protected]>
Cc James Hogan <[email protected]>
Cc Yangtao Li <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Mathieu Malaterre <[email protected]>
Cc Huacai Chen <[email protected]>
Cc Marcin Nowakowski <[email protected]>
Cc Yasha Cherikovsky <[email protected]>
---
 arch/mips/kernel/mips-r2-to-r6-emul.c | 21 ++++-----------------
 arch/mips/kernel/segment.c            | 15 +++------------
 arch/mips/kernel/setup.c              |  7 +------
 arch/mips/kernel/spinlock_test.c      | 21 ++++-----------------
 arch/mips/kernel/unaligned.c          | 16 ++++------------
 5 files changed, 16 insertions(+), 64 deletions(-)
arch/mips/kernel/mips-r2-to-r6-emul.c +4 -17
index c50c89a978f1..b4d210bfcdae 100644
@@ -2351,23 +2351,10 @@ DEFINE_SHOW_ATTRIBUTE(mipsr2_clear);
 
 static int __init mipsr2_init_debugfs(void)
 {
-	struct dentry		*mipsr2_emul;
-
-	if (!mips_debugfs_dir)
-		return -ENODEV;
-
-	mipsr2_emul = debugfs_create_file("r2_emul_stats", S_IRUGO,
-					  mips_debugfs_dir, NULL,
-					  &mipsr2_emul_fops);
-	if (!mipsr2_emul)
-		return -ENOMEM;
-
-	mipsr2_emul = debugfs_create_file("r2_emul_stats_clear", S_IRUGO,
-					  mips_debugfs_dir, NULL,
-					  &mipsr2_clear_fops);
-	if (!mipsr2_emul)
-		return -ENOMEM;
-
+	debugfs_create_file("r2_emul_stats", S_IRUGO, mips_debugfs_dir, NULL,
+			    &mipsr2_emul_fops);
+	debugfs_create_file("r2_emul_stats_clear", S_IRUGO, mips_debugfs_dir,
+			    NULL, &mipsr2_clear_fops);
 	return 0;
 }
 
arch/mips/kernel/segment.c +3 -12
index 2703f218202e..0a9bd7b0983b 100644
@@ -95,18 +95,9 @@ static const struct file_operations segments_fops = {
 
 static int __init segments_info(void)
 {
-	struct dentry *segments;
-
-	if (cpu_has_segments) {
-		if (!mips_debugfs_dir)
-			return -ENODEV;
-
-		segments = debugfs_create_file("segments", S_IRUGO,
-					       mips_debugfs_dir, NULL,
-					       &segments_fops);
-		if (!segments)
-			return -ENOMEM;
-	}
+	if (cpu_has_segments)
+		debugfs_create_file("segments", S_IRUGO, mips_debugfs_dir, NULL,
+				    &segments_fops);
 	return 0;
 }
 
arch/mips/kernel/setup.c +1 -6
index 8c6c48ed786a..44434e50a355 100644
@@ -1010,12 +1010,7 @@ unsigned long fw_passed_dtb;
 struct dentry *mips_debugfs_dir;
 static int __init debugfs_mips(void)
 {
-	struct dentry *d;
-
-	d = debugfs_create_dir("mips", NULL);
-	if (!d)
-		return -ENOMEM;
-	mips_debugfs_dir = d;
+	mips_debugfs_dir = debugfs_create_dir("mips", NULL);
 	return 0;
 }
 arch_initcall(debugfs_mips);
arch/mips/kernel/spinlock_test.c +4 -17
index eaed550e79a2..ab4e3e1b138d 100644
@@ -118,23 +118,10 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_multi, multi_get, NULL, "%llu\n");
 
 static int __init spinlock_test(void)
 {
-	struct dentry *d;
-
-	if (!mips_debugfs_dir)
-		return -ENODEV;
-
-	d = debugfs_create_file("spin_single", S_IRUGO,
-				mips_debugfs_dir, NULL,
-				&fops_ss);
-	if (!d)
-		return -ENOMEM;
-
-	d = debugfs_create_file("spin_multi", S_IRUGO,
-				mips_debugfs_dir, NULL,
-				&fops_multi);
-	if (!d)
-		return -ENOMEM;
-
+	debugfs_create_file("spin_single", S_IRUGO, mips_debugfs_dir, NULL,
+			    &fops_ss);
+	debugfs_create_file("spin_multi", S_IRUGO, mips_debugfs_dir, NULL,
+			    &fops_multi);
 	return 0;
 }
 device_initcall(spinlock_test);
arch/mips/kernel/unaligned.c +4 -12
index 595ca9c85111..0ed20a64b285 100644
@@ -2374,18 +2374,10 @@ asmlinkage void do_ade(struct pt_regs *regs)
 #ifdef CONFIG_DEBUG_FS
 static int __init debugfs_unaligned(void)
 {
-	struct dentry *d;
-
-	if (!mips_debugfs_dir)
-		return -ENODEV;
-	d = debugfs_create_u32("unaligned_instructions", S_IRUGO,
-			       mips_debugfs_dir, &unaligned_instructions);
-	if (!d)
-		return -ENOMEM;
-	d = debugfs_create_u32("unaligned_action", S_IRUGO | S_IWUSR,
-			       mips_debugfs_dir, &unaligned_action);
-	if (!d)
-		return -ENOMEM;
+	debugfs_create_u32("unaligned_instructions", S_IRUGO, mips_debugfs_dir,
+			   &unaligned_instructions);
+	debugfs_create_u32("unaligned_action", S_IRUGO | S_IWUSR,
+			   mips_debugfs_dir, &unaligned_action);
 	return 0;
 }
 arch_initcall(debugfs_unaligned);
Signature · 1 line
2.20.1
#8 lore raw

PATCH 4/5 mips: math-emu: no need to check return value of debugfs_create functions

In reply to 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.

---
 arch/mips/math-emu/me-debugfs.c | 23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)
arch/mips/math-emu/me-debugfs.c +4 -19
index 58798f527356..387724860fa6 100644
@@ -189,32 +189,21 @@ static int __init debugfs_fpuemu(void)
 {
 	struct dentry *fpuemu_debugfs_base_dir;
 	struct dentry *fpuemu_debugfs_inst_dir;
-	struct dentry *d, *reset_file;
-
-	if (!mips_debugfs_dir)
-		return -ENODEV;
 
 	fpuemu_debugfs_base_dir = debugfs_create_dir("fpuemustats",
 						     mips_debugfs_dir);
-	if (!fpuemu_debugfs_base_dir)
-		return -ENOMEM;
 
-	reset_file = debugfs_create_file("fpuemustats_clear", 0444,
-					 mips_debugfs_dir, NULL,
-					 &fpuemustats_clear_fops);
-	if (!reset_file)
-		return -ENOMEM;
+	debugfs_create_file("fpuemustats_clear", 0444, mips_debugfs_dir, NULL,
+			    &fpuemustats_clear_fops);
 
 #define FPU_EMU_STAT_OFFSET(m)						\
 	offsetof(struct mips_fpu_emulator_stats, m)
 
 #define FPU_STAT_CREATE(m)						\
 do {									\
-	d = debugfs_create_file(#m, 0444, fpuemu_debugfs_base_dir,	\
+	debugfs_create_file(#m, 0444, fpuemu_debugfs_base_dir,		\
 				(void *)FPU_EMU_STAT_OFFSET(m),		\
 				&fops_fpuemu_stat);			\
-	if (!d)								\
-		return -ENOMEM;						\
 } while (0)
 
 	FPU_STAT_CREATE(emulated);
@@ -233,8 +222,6 @@ do {									\
 
 	fpuemu_debugfs_inst_dir = debugfs_create_dir("instructions",
 						     fpuemu_debugfs_base_dir);
-	if (!fpuemu_debugfs_inst_dir)
-		return -ENOMEM;
 
 #define FPU_STAT_CREATE_EX(m)						\
 do {									\
@@ -242,11 +229,9 @@ do {									\
 									\
 	adjust_instruction_counter_name(name, #m);			\
 									\
-	d = debugfs_create_file(name, 0444, fpuemu_debugfs_inst_dir,	\
+	debugfs_create_file(name, 0444, fpuemu_debugfs_inst_dir,	\
 				(void *)FPU_EMU_STAT_OFFSET(m),		\
 				&fops_fpuemu_stat);			\
-	if (!d)								\
-		return -ENOMEM;						\
 } while (0)
 
 	FPU_STAT_CREATE_EX(abs_s);
Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH 1/5] mips: cavium: no need to check return value of debugfs_create functions

In reply to Greg Kroah-Hartman

Hi,

Quoted 17 lines · Greg Kroah-Hartman
arch/mips/cavium-octeon/oct_ilm.c +1 -14
-static int init_debufs(void)
+static void init_debugfs(void)
 {
-	struct dentry *show_dentry;
 	dir = debugfs_create_dir("oct_ilm", 0);
-	if (!dir) {
-		pr_err("oct_ilm: failed to create debugfs entry oct_ilm\n");
-		return -1;
-	}
-
-	show_dentry = debugfs_create_file("statistics", 0222, dir, NULL,
-					  &oct_ilm_ops);
-	if (!show_dentry) {
-		pr_err("oct_ilm: failed to create debugfs entry oct_ilm/statistics\n");
-		return -1;
-	}
-

arch/mips/cavium-octeon/oct_ilm.c static int reset_statistics(void *data, u64 value) · line 71

Quoted 10 lines
arch/mips/cavium-octeon/oct_ilm.c +2 -7
-	show_dentry = debugfs_create_file("reset", 0222, dir, NULL,
-					  &reset_statistics_ops);
-	if (!show_dentry) {
-		pr_err("oct_ilm: failed to create debugfs entry oct_ilm/reset\n");
-		return -1;
-	}
-
+	debugfs_create_file("statistics", 0222, dir, NULL, &oct_ilm_ops);
+	debugfs_create_file("reset", 0222, dir, NULL, &reset_statistics_ops);
 	return 0;

The return needs to be deleted now that the function is void.

A.

#3 lore raw

Re: [PATCH 1/5] mips: cavium: no need to check return value of debugfs_create functions

Hello,

Quoted 22 lines · Aaro Koskinen
Quoted 21 lines · Greg Kroah-Hartman
arch/mips/cavium-octeon/oct_ilm.c +1 -18
-static int init_debufs(void)
+static void init_debugfs(void)
 {
-	struct dentry *show_dentry;
 	dir = debugfs_create_dir("oct_ilm", 0);
-	if (!dir) {
-		pr_err("oct_ilm: failed to create debugfs entry oct_ilm\n");
-		return -1;
-	}
-
-	show_dentry = debugfs_create_file("statistics", 0222, dir, NULL,
-					  &oct_ilm_ops);
-	if (!show_dentry) {
-		pr_err("oct_ilm: failed to create debugfs entry oct_ilm/statistics\n");
-		return -1;
-	}
-
-	show_dentry = debugfs_create_file("reset", 0222, dir, NULL,
-					  &reset_statistics_ops);
-	if (!show_dentry) {
-		pr_err("oct_ilm: failed to create debugfs entry oct_ilm/reset\n");
Quoted 8 lines

arch/mips/cavium-octeon/oct_ilm.c static int reset_statistics(void *data, u64 value) · line 71

Quoted 6 lines
arch/mips/cavium-octeon/oct_ilm.c +2 -3
-		return -1;
-	}
-
+	debugfs_create_file("statistics", 0222, dir, NULL, &oct_ilm_ops);
+	debugfs_create_file("reset", 0222, dir, NULL, &reset_statistics_ops);
 	return 0;

The return needs to be deleted now that the function is void.

Well spotted - I'm happy to fix this up whilst applying the patch.

Thanks,
Paul

#4 lore raw

Re: [PATCH 1/5] mips: cavium: no need to check return value of debugfs_create functions

Quoted 34 lines · Paul Burton

Hello,

Quoted 22 lines · Aaro Koskinen
Quoted 21 lines · Greg Kroah-Hartman
arch/mips/cavium-octeon/oct_ilm.c +1 -18
-static int init_debufs(void)
+static void init_debugfs(void)
 {
-	struct dentry *show_dentry;
 	dir = debugfs_create_dir("oct_ilm", 0);
-	if (!dir) {
-		pr_err("oct_ilm: failed to create debugfs entry oct_ilm\n");
-		return -1;
-	}
-
-	show_dentry = debugfs_create_file("statistics", 0222, dir, NULL,
-					  &oct_ilm_ops);
-	if (!show_dentry) {
-		pr_err("oct_ilm: failed to create debugfs entry oct_ilm/statistics\n");
-		return -1;
-	}
-
-	show_dentry = debugfs_create_file("reset", 0222, dir, NULL,
-					  &reset_statistics_ops);
-	if (!show_dentry) {
-		pr_err("oct_ilm: failed to create debugfs entry oct_ilm/reset\n");
Quoted 8 lines

arch/mips/cavium-octeon/oct_ilm.c static int reset_statistics(void *data, u64 value) · line 71

Quoted 6 lines
arch/mips/cavium-octeon/oct_ilm.c +2 -3
-		return -1;
-	}
-
+	debugfs_create_file("statistics", 0222, dir, NULL, &oct_ilm_ops);
+	debugfs_create_file("reset", 0222, dir, NULL, &reset_statistics_ops);
 	return 0;

The return needs to be deleted now that the function is void.

Quoted 1 line

Well spotted - I'm happy to fix this up whilst applying the patch.

The fact that 0-day didn't catch this makes me worried, is this platform/driver not being built there?

Thanks for catching this, sorry for the mistake.

greg k-h

#5 lore raw

Re: [PATCH 1/5] mips: cavium: no need to check return value of debugfs_create functions

Hi Greg,

Quoted 33 lines · Greg Kroah-Hartman
Quoted 32 lines · Paul Burton
Quoted 30 lines · Aaro Koskinen
Quoted 17 lines · Greg Kroah-Hartman
arch/mips/cavium-octeon/oct_ilm.c +1 -14
-static int init_debufs(void)
+static void init_debugfs(void)
 {
-	struct dentry *show_dentry;
 	dir = debugfs_create_dir("oct_ilm", 0);
-	if (!dir) {
-		pr_err("oct_ilm: failed to create debugfs entry oct_ilm\n");
-		return -1;
-	}
-
-	show_dentry = debugfs_create_file("statistics", 0222, dir, NULL,
-					  &oct_ilm_ops);
-	if (!show_dentry) {
-		pr_err("oct_ilm: failed to create debugfs entry oct_ilm/statistics\n");
-		return -1;
-	}
-

arch/mips/cavium-octeon/oct_ilm.c static int reset_statistics(void *data, u64 value) · line 71

Quoted 10 lines
arch/mips/cavium-octeon/oct_ilm.c +2 -7
-	show_dentry = debugfs_create_file("reset", 0222, dir, NULL,
-					  &reset_statistics_ops);
-	if (!show_dentry) {
-		pr_err("oct_ilm: failed to create debugfs entry oct_ilm/reset\n");
-		return -1;
-	}
-
+	debugfs_create_file("statistics", 0222, dir, NULL, &oct_ilm_ops);
+	debugfs_create_file("reset", 0222, dir, NULL, &reset_statistics_ops);
 	return 0;

The return needs to be deleted now that the function is void.

Quoted 4 lines
Quoted 1 line

Well spotted - I'm happy to fix this up whilst applying the patch.

The fact that 0-day didn't catch this makes me worried, is this platform/driver not being built there?

It looks like this code ought to be built as a module for cavium_octeon_defconfig:

  $ grep oct_ilm arch/mips/cavium-octeon/Makefile
  obj-$(CONFIG_OCTEON_ILM)              += oct_ilm.o
  $ grep OCTEON_ILM arch/mips/configs/cavium_octeon_defconfig
  CONFIG_OCTEON_ILM=m

Fengguang or others - does 0-day build cavium_octeon_defconfig? If so, does it build modules?

Thanks,
Paul

#10 lore raw
In reply to Greg Kroah-Hartman

Hello,

Quoted 16 lines · Greg Kroah-Hartman

When calling debugfs code, there is no need to ever check the return value of the call, as no logic should ever change if a call works properly or not. Fix up a bunch of x86-specific code to not care about the results of debugfs.

Greg Kroah-Hartman (5):
mips: cavium: no need to check return value of debugfs_create functions
mips: ralink: no need to check return value of debugfs_create functions
mips: mm: no need to check return value of debugfs_create functions
mips: math-emu: no need to check return value of debugfs_create functions
mips: kernel: no need to check return value of debugfs_create functions

Quoted 10 lines
arch/mips/cavium-octeon/oct_ilm.c     | 31 ++++-----------------------
arch/mips/kernel/mips-r2-to-r6-emul.c | 21 ++++--------------
arch/mips/kernel/segment.c            | 15 +++----------
arch/mips/kernel/setup.c              |  7 +-----
arch/mips/kernel/spinlock_test.c      | 21 ++++--------------
arch/mips/kernel/unaligned.c          | 16 ++++----------
arch/mips/math-emu/me-debugfs.c       | 23 ++++----------------
arch/mips/mm/sc-debugfs.c             | 15 +++----------
arch/mips/ralink/bootrom.c            |  8 +------
9 files changed, 28 insertions(+), 129 deletions(-)

Series applied to mips-next.

Thanks,
Paul

[ This message was auto-generated; if you believe anything is incorrect
then please email [email protected] to report it. ]