Skip to contentSkip to conversation

ppc4xx: ocm: fix errnous "failed to create file" errors

PATCH Superseded Christian Lamparter 2 participants 3 messages Oct 28, 2018 – Nov 4, 2018 PowerPC

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ppc4xx: ocm: fix errnous "failed to create file" errors

Previously, the kernel would complain:

| debugfs ppc4xx ocm: failed to create file

But the "info" file was still created and working. This is because debugfs_create_file() returns a pointer to a struct *dentry on success or -ENODEV when debugfs isn't available. This patch fixes both the debugfs_create_dir() and debugfs_create_file() check, so this will work as expected.

---
 arch/powerpc/platforms/4xx/ocm.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/powerpc/platforms/4xx/ocm.c +4 -3
index 69d9f60d9fe5..e616c8636303 100644
@@ -293,13 +293,14 @@ static int ocm_debugfs_init(void)
 {
 	struct dentry *junk;
 
-	junk = debugfs_create_dir("ppc4xx_ocm", 0);
-	if (!junk) {
+	junk = debugfs_create_dir("ppc4xx_ocm", NULL);
+	if (IS_ERR_OR_NULL(junk)) {
 		printk(KERN_ALERT "debugfs ppc4xx ocm: failed to create dir\n");
 		return -1;
 	}
 
-	if (debugfs_create_file("info", 0644, junk, NULL, &ocm_debugfs_fops)) {
+	if (IS_ERR_OR_NULL(debugfs_create_file("info", 0644, junk, NULL,
+					       &ocm_debugfs_fops))) {
 		printk(KERN_ALERT "debugfs ppc4xx ocm: failed to create file\n");
 		return -1;
 	}
Signature · 1 line
2.19.1
#1 lore raw

Hi Christian,

Quoted 25 lines · Christian Lamparter

Previously, the kernel would complain:

| debugfs ppc4xx ocm: failed to create file

But the "info" file was still created and working. This is because debugfs_create_file() returns a pointer to a struct *dentry on success or -ENODEV when debugfs isn't available. This patch fixes both the debugfs_create_dir() and debugfs_create_file() check, so this will work as expected.

arch/powerpc/platforms/4xx/ocm.c +2 -2
index 69d9f60d9fe5..e616c8636303 100644
@@ -293,13 +293,14 @@ static int ocm_debugfs_init(void)
 {
 	struct dentry *junk;
 
-	junk = debugfs_create_dir("ppc4xx_ocm", 0);
-	if (!junk) {
+	junk = debugfs_create_dir("ppc4xx_ocm", NULL);
+	if (IS_ERR_OR_NULL(junk)) {

arch/powerpc/platforms/4xx/ocm.c static int ocm_debugfs_init(void) · line 306

Quoted 10 lines
arch/powerpc/platforms/4xx/ocm.c +2 -1
 		printk(KERN_ALERT "debugfs ppc4xx ocm: failed to create dir\n");
 		return -1;
 	}
 
-	if (debugfs_create_file("info", 0644, junk, NULL, &ocm_debugfs_fops)) {
+	if (IS_ERR_OR_NULL(debugfs_create_file("info", 0644, junk, NULL,
+					       &ocm_debugfs_fops))) {
 		printk(KERN_ALERT "debugfs ppc4xx ocm: failed to create file\n");
 		return -1;
 	}

Typically we would just make the whole function not compile when DEBUG_FS is disabled, eg:

arch/powerpc/platforms/4xx/ocm.c +4 -0
index f5bbd4563342..c5293a28545c 100644
@@ -286,6 +286,7 @@ static const struct file_operations ocm_debugfs_fops = {
 	.release = single_release,
 };
 
+#ifdef CONFIG_DEBUG_FS
 static int ocm_debugfs_init(void)
 {
 	struct dentry *junk;
@@ -303,6 +304,9 @@ static int ocm_debugfs_init(void)
 
 	return 0;
 }
+#else
+static int ocm_debugfs_init(void) { return 0; }
+#endif
 
 void *ppc4xx_ocm_alloc(phys_addr_t *phys, int size, int align,
 			int flags, const char *owner)

I don't really mind, but I think the #ifdef approach is simpler to reason about.

cheers

#2 lore raw
Quoted 65 lines · CET Michael Ellerman

Hi Christian,

Quoted 25 lines · Christian Lamparter

Previously, the kernel would complain:

| debugfs ppc4xx ocm: failed to create file

But the "info" file was still created and working. This is because debugfs_create_file() returns a pointer to a struct *dentry on success or -ENODEV when debugfs isn't available. This patch fixes both the debugfs_create_dir() and debugfs_create_file() check, so this will work as expected.

arch/powerpc/platforms/4xx/ocm.c +2 -2
index 69d9f60d9fe5..e616c8636303 100644
@@ -293,13 +293,14 @@ static int ocm_debugfs_init(void)
 {
 	struct dentry *junk;
 
-	junk = debugfs_create_dir("ppc4xx_ocm", 0);
-	if (!junk) {
+	junk = debugfs_create_dir("ppc4xx_ocm", NULL);
+	if (IS_ERR_OR_NULL(junk)) {

arch/powerpc/platforms/4xx/ocm.c static int ocm_debugfs_init(void) · line 306

Quoted 10 lines
arch/powerpc/platforms/4xx/ocm.c +2 -1
 		printk(KERN_ALERT "debugfs ppc4xx ocm: failed to create dir\n");
 		return -1;
 	}
 
-	if (debugfs_create_file("info", 0644, junk, NULL, &ocm_debugfs_fops)) {
+	if (IS_ERR_OR_NULL(debugfs_create_file("info", 0644, junk, NULL,
+					       &ocm_debugfs_fops))) {
 		printk(KERN_ALERT "debugfs ppc4xx ocm: failed to create file\n");
 		return -1;
 	}

Typically we would just make the whole function not compile when DEBUG_FS is disabled, eg:

arch/powerpc/platforms/4xx/ocm.c +4 -0
index f5bbd4563342..c5293a28545c 100644
@@ -286,6 +286,7 @@ static const struct file_operations ocm_debugfs_fops = {
 	.release = single_release,
 };
 
+#ifdef CONFIG_DEBUG_FS
 static int ocm_debugfs_init(void)
 {
 	struct dentry *junk;
@@ -303,6 +304,9 @@ static int ocm_debugfs_init(void)
 
 	return 0;
 }
+#else
+static int ocm_debugfs_init(void) { return 0; }
+#endif
 
 void *ppc4xx_ocm_alloc(phys_addr_t *phys, int size, int align,
 			int flags, const char *owner)
Quoted 4 lines

I don't really mind, but I think the #ifdef approach is simpler to reason about.

cheers

Thank you. I'll post a v2 right away.