Skip to contentSkip to conversation

xen/debugfs: Check debugfs initialization before using it

PATCH Superseded Ethan Zhao 2 participants 5 messages Dec 9, 2013

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Ethan Zhao

author
#0 lore raw

PATCH v3 1/1 xen/debugfs: Check debugfs initialization before using it

From: "ethan.zhao" <[email protected]>

Should check debugfs initialization with debugfs_initialized() before using it, Because if it isn't initialized, the return value of fake debugfs_create_dir() etc functions would be ERR_PTR(-ENODEV), checking with NULL will not work.

V3: add warning message when debugfs not configured or disabled.

---
 arch/x86/xen/debugfs.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/x86/xen/debugfs.c +6 -0
index c8377fb..85c0e0e 100644
@@ -9,12 +9,18 @@ static struct dentry *d_xen_debug;
 
 struct dentry * __init xen_init_debugfs(void)
 {
+	if (!debugfs_initialized()) {
+		d_xen_debug = NULL;
+		goto nodebugfs;
+	}
+
 	if (!d_xen_debug) {
 		d_xen_debug = debugfs_create_dir("xen", NULL);
 
 		if (!d_xen_debug)
 			pr_warning("Could not create 'xen' debugfs directory\n");
 	}
+nodebugfs:
 
 	return d_xen_debug;
 }
Signature · 1 line
1.8.3.4 (Apple Git-47)
author
#1 lore raw

Greg,

How about the V3 ?

Thanks,
Ethan

Quoted 39 lines · Ethan Zhao

From: "ethan.zhao" <[email protected]>

Should check debugfs initialization with debugfs_initialized() before using it, Because if it isn't initialized, the return value of fake debugfs_create_dir() etc functions would be ERR_PTR(-ENODEV), checking with NULL will not work.

V3: add warning message when debugfs not configured or disabled.

---
 arch/x86/xen/debugfs.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/x86/xen/debugfs.c +6 -1
index c8377fb..85c0e0e 100644
@@ -9,12 +9,18 @@ static struct dentry *d_xen_debug;
 
 struct dentry * __init xen_init_debugfs(void)
 {
+       if (!debugfs_initialized()) {
+               d_xen_debug = NULL;
+               goto nodebugfs;
+       }
+
        if (!d_xen_debug) {
                d_xen_debug = debugfs_create_dir("xen", NULL);
 
                if (!d_xen_debug)
                        pr_warning("Could not create 'xen' debugfs directory\n");
        }
+nodebugfs:
 
        return d_xen_debug;
 }
--

1.8.3.4 (Apple Git-47)

#2 lore raw
In reply to Ethan Zhao
Quoted 7 lines · Ethan Zhao

From: "ethan.zhao" <[email protected]>

Should check debugfs initialization with debugfs_initialized() before using it, Because if it isn't initialized, the return value of fake debugfs_create_dir() etc functions would be ERR_PTR(-ENODEV), checking with NULL will not work.

V3: add warning message when debugfs not configured or disabled.

That's not what this patch does...

Quoted 10 lines
---
 arch/x86/xen/debugfs.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/x86/xen/debugfs.c +0 -0
index c8377fb..85c0e0e 100644

arch/x86/xen/debugfs.c static struct dentry *d_xen_debug; · line 15

Quoted 7 lines
arch/x86/xen/debugfs.c +4 -0
@@ -9,12 +9,18 @@ static struct dentry *d_xen_debug;
 
 struct dentry * __init xen_init_debugfs(void)
 {
+	if (!debugfs_initialized()) {
+		d_xen_debug = NULL;
+		goto nodebugfs;
+	}

Again, why is this even needed?

What problem in the existing code are you trying to solve?

author
#3 lore raw
Quoted 31 lines · Greg KH
Quoted 7 lines · Ethan Zhao

From: "ethan.zhao" <[email protected]>

Should check debugfs initialization with debugfs_initialized() before using it, Because if it isn't initialized, the return value of fake debugfs_create_dir() etc functions would be ERR_PTR(-ENODEV), checking with NULL will not work.

V3: add warning message when debugfs not configured or disabled.

That's not what this patch does...

Quoted 10 lines
---
 arch/x86/xen/debugfs.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/x86/xen/debugfs.c +0 -0
index c8377fb..85c0e0e 100644

arch/x86/xen/debugfs.c static struct dentry *d_xen_debug; · line 15

Quoted 7 lines
arch/x86/xen/debugfs.c +4 -0
@@ -9,12 +9,18 @@ static struct dentry *d_xen_debug;
 
 struct dentry * __init xen_init_debugfs(void)
 {
+     if (!debugfs_initialized()) {
+             d_xen_debug = NULL;
+             goto nodebugfs;
+     }

Again, why is this even needed?

Quoted 2 lines

What problem in the existing code are you trying to solve?

What I want to ask who is so smart and fake some many functions when CONFIG_DEBUG_FS is not configured/defined and the build could pass without any error ? What is the motive make him wrote some many fake function and why he wrote the debugfs_initialized() function seem 'useless' at all ?

Thanks,
Ethan

#4 lore raw
Quoted 32 lines · Ethan Zhao
Quoted 31 lines · Greg KH
Quoted 7 lines · Ethan Zhao

From: "ethan.zhao" <[email protected]>

Should check debugfs initialization with debugfs_initialized() before using it, Because if it isn't initialized, the return value of fake debugfs_create_dir() etc functions would be ERR_PTR(-ENODEV), checking with NULL will not work.

V3: add warning message when debugfs not configured or disabled.

That's not what this patch does...

Quoted 10 lines
---
 arch/x86/xen/debugfs.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/x86/xen/debugfs.c +0 -0
index c8377fb..85c0e0e 100644

arch/x86/xen/debugfs.c static struct dentry *d_xen_debug; · line 15

Quoted 7 lines
arch/x86/xen/debugfs.c +4 -0
@@ -9,12 +9,18 @@ static struct dentry *d_xen_debug;
 
 struct dentry * __init xen_init_debugfs(void)
 {
+     if (!debugfs_initialized()) {
+             d_xen_debug = NULL;
+             goto nodebugfs;
+     }

Again, why is this even needed?

Quoted 5 lines
Quoted 2 lines

What problem in the existing code are you trying to solve?

What I want to ask who is so smart and fake some many functions when CONFIG_DEBUG_FS is not configured/defined and the build could pass without any error ?

That's the way this has always worked.

Quoted 2 lines

What is the motive make him wrote some many fake function and why he wrote the debugfs_initialized() function seem 'useless' at all ?

To make the caller code easier, and smaller, and to not care if debugfs is enabled in the kernel build or not at all.

Ok, I answered your questions, now care to answer mine?

greg k-h