Skip to contentSkip to conversation

cxl: no need to check return value of debugfs_create functions

PATCH Applied Greg Kroah-Hartman 5 participants 5 messages Jun 12, 2019 – Jun 30, 2019 Char and misc drivers

lore
Share & tools
lore

Greg Kroah-Hartman

author maintainer
#0 lore raw

PATCH v2 1/1 cxl: 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.

Because there's no need to check, also make the return value of the local debugfs_create_io_x64() call void, as no one ever did anything with the return value (as they did not need to.)

And make the cxl_debugfs_* calls return void as no one was even checking their return value at all.

Cc Frederic Barrat <[email protected]>
Cc Andrew Donnellan <[email protected]>
Cc Arnd Bergmann <[email protected]>

---
v2: make the return value of all of the cxl_debugfs_* calls void as no
one was checking the return values of them.

 drivers/misc/cxl/cxl.h     | 15 ++++++---------
 drivers/misc/cxl/debugfs.c | 36 +++++++++++-------------------------
 2 files changed, 17 insertions(+), 34 deletions(-)
drivers/misc/cxl/cxl.h +6 -9
index a73c9e669d78..5dc0f6093f9d 100644
@@ -908,11 +908,11 @@ void cxl_update_dedicated_ivtes_psl8(struct cxl_context *ctx);
 
 #ifdef CONFIG_DEBUG_FS
 
-int cxl_debugfs_init(void);
+void cxl_debugfs_init(void);
 void cxl_debugfs_exit(void);
-int cxl_debugfs_adapter_add(struct cxl *adapter);
+void cxl_debugfs_adapter_add(struct cxl *adapter);
 void cxl_debugfs_adapter_remove(struct cxl *adapter);
-int cxl_debugfs_afu_add(struct cxl_afu *afu);
+void cxl_debugfs_afu_add(struct cxl_afu *afu);
 void cxl_debugfs_afu_remove(struct cxl_afu *afu);
 void cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter, struct dentry *dir);
 void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir);
@@ -921,27 +921,24 @@ void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir);
 
 #else /* CONFIG_DEBUG_FS */
 
-static inline int __init cxl_debugfs_init(void)
+static inline void __init cxl_debugfs_init(void)
 {
-	return 0;
 }
 
 static inline void cxl_debugfs_exit(void)
 {
 }
 
-static inline int cxl_debugfs_adapter_add(struct cxl *adapter)
+static inline void cxl_debugfs_adapter_add(struct cxl *adapter)
 {
-	return 0;
 }
 
 static inline void cxl_debugfs_adapter_remove(struct cxl *adapter)
 {
 }
 
-static inline int cxl_debugfs_afu_add(struct cxl_afu *afu)
+static inline void cxl_debugfs_afu_add(struct cxl_afu *afu)
 {
-	return 0;
 }
 
 static inline void cxl_debugfs_afu_remove(struct cxl_afu *afu)
drivers/misc/cxl/debugfs.c +11 -25
index 1fda22c24c93..7b987bf498b5 100644
@@ -26,11 +26,11 @@ static int debugfs_io_u64_set(void *data, u64 val)
 DEFINE_DEBUGFS_ATTRIBUTE(fops_io_x64, debugfs_io_u64_get, debugfs_io_u64_set,
 			 "0x%016llx\n");
 
-static struct dentry *debugfs_create_io_x64(const char *name, umode_t mode,
-					    struct dentry *parent, u64 __iomem *value)
+static void debugfs_create_io_x64(const char *name, umode_t mode,
+				  struct dentry *parent, u64 __iomem *value)
 {
-	return debugfs_create_file_unsafe(name, mode, parent,
-					  (void __force *)value, &fops_io_x64);
+	debugfs_create_file_unsafe(name, mode, parent, (void __force *)value,
+				   &fops_io_x64);
 }
 
 void cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter, struct dentry *dir)
@@ -54,25 +54,22 @@ void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir)
 	debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_TRACE));
 }
 
-int cxl_debugfs_adapter_add(struct cxl *adapter)
+void cxl_debugfs_adapter_add(struct cxl *adapter)
 {
 	struct dentry *dir;
 	char buf[32];
 
 	if (!cxl_debugfs)
-		return -ENODEV;
+		return;
 
 	snprintf(buf, 32, "card%i", adapter->adapter_num);
 	dir = debugfs_create_dir(buf, cxl_debugfs);
-	if (IS_ERR(dir))
-		return PTR_ERR(dir);
 	adapter->debugfs = dir;
 
 	debugfs_create_io_x64("err_ivte", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_ErrIVTE));
 
 	if (adapter->native->sl_ops->debugfs_add_adapter_regs)
 		adapter->native->sl_ops->debugfs_add_adapter_regs(adapter, dir);
-	return 0;
 }
 
 void cxl_debugfs_adapter_remove(struct cxl *adapter)
@@ -96,18 +93,16 @@ void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir)
 	debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SLICE_TRACE));
 }
 
-int cxl_debugfs_afu_add(struct cxl_afu *afu)
+void cxl_debugfs_afu_add(struct cxl_afu *afu)
 {
 	struct dentry *dir;
 	char buf[32];
 
 	if (!afu->adapter->debugfs)
-		return -ENODEV;
+		return;
 
 	snprintf(buf, 32, "psl%i.%i", afu->adapter->adapter_num, afu->slice);
 	dir = debugfs_create_dir(buf, afu->adapter->debugfs);
-	if (IS_ERR(dir))
-		return PTR_ERR(dir);
 	afu->debugfs = dir;
 
 	debugfs_create_io_x64("sr",         S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SR_An));
@@ -118,8 +113,6 @@ int cxl_debugfs_afu_add(struct cxl_afu *afu)
 
 	if (afu->adapter->native->sl_ops->debugfs_add_afu_regs)
 		afu->adapter->native->sl_ops->debugfs_add_afu_regs(afu, dir);
-
-	return 0;
 }
 
 void cxl_debugfs_afu_remove(struct cxl_afu *afu)
@@ -127,19 +120,12 @@ void cxl_debugfs_afu_remove(struct cxl_afu *afu)
 	debugfs_remove_recursive(afu->debugfs);
 }
 
-int __init cxl_debugfs_init(void)
+void __init cxl_debugfs_init(void)
 {
-	struct dentry *ent;
-
 	if (!cpu_has_feature(CPU_FTR_HVMODE))
-		return 0;
-
-	ent = debugfs_create_dir("cxl", NULL);
-	if (IS_ERR(ent))
-		return PTR_ERR(ent);
-	cxl_debugfs = ent;
+		return;
 
-	return 0;
+	cxl_debugfs = debugfs_create_dir("cxl", NULL);
 }
 
 void cxl_debugfs_exit(void)
Signature · 1 line
2.22.0
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 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.

Because there's no need to check, also make the return value of the local debugfs_create_io_x64() call void, as no one ever did anything with the return value (as they did not need to.)

Quoted 8 lines

And make the cxl_debugfs_* calls return void as no one was even checking their return value at all.

Cc Frederic Barrat <[email protected]>
Cc Andrew Donnellan <[email protected]>
Cc Arnd Bergmann <[email protected]>
Reviewed-by on v2 1/1
#2 lore raw
In reply to Greg Kroah-Hartman

Le 12/06/2019 à 17:54, Greg Kroah-Hartman a écrit :

Quoted 11 lines

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.

Because there's no need to check, also make the return value of the local debugfs_create_io_x64() call void, as no one ever did anything with the return value (as they did not need to.)

And make the cxl_debugfs_* calls return void as no one was even checking their return value at all.

Quoted 6 lines
Cc Frederic Barrat <[email protected]>
Cc Andrew Donnellan <[email protected]>
Cc Arnd Bergmann <[email protected]>

---

Thanks!

Quoted 159 lines

v2: make the return value of all of the cxl_debugfs_* calls void as no
one was checking the return values of them.

  drivers/misc/cxl/cxl.h     | 15 ++++++---------
  drivers/misc/cxl/debugfs.c | 36 +++++++++++-------------------------
  2 files changed, 17 insertions(+), 34 deletions(-)
drivers/misc/cxl/cxl.h +6 -9
index a73c9e669d78..5dc0f6093f9d 100644
@@ -908,11 +908,11 @@ void cxl_update_dedicated_ivtes_psl8(struct cxl_context *ctx);
 
  #ifdef CONFIG_DEBUG_FS
 
-int cxl_debugfs_init(void);
+void cxl_debugfs_init(void);
  void cxl_debugfs_exit(void);
-int cxl_debugfs_adapter_add(struct cxl *adapter);
+void cxl_debugfs_adapter_add(struct cxl *adapter);
  void cxl_debugfs_adapter_remove(struct cxl *adapter);
-int cxl_debugfs_afu_add(struct cxl_afu *afu);
+void cxl_debugfs_afu_add(struct cxl_afu *afu);
  void cxl_debugfs_afu_remove(struct cxl_afu *afu);
  void cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter, struct dentry *dir);
  void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir);
@@ -921,27 +921,24 @@ void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir);
 
  #else /* CONFIG_DEBUG_FS */
 
-static inline int __init cxl_debugfs_init(void)
+static inline void __init cxl_debugfs_init(void)
  {
-	return 0;
  }
 
  static inline void cxl_debugfs_exit(void)
  {
  }
 
-static inline int cxl_debugfs_adapter_add(struct cxl *adapter)
+static inline void cxl_debugfs_adapter_add(struct cxl *adapter)
  {
-	return 0;
  }
 
  static inline void cxl_debugfs_adapter_remove(struct cxl *adapter)
  {
  }
 
-static inline int cxl_debugfs_afu_add(struct cxl_afu *afu)
+static inline void cxl_debugfs_afu_add(struct cxl_afu *afu)
  {
-	return 0;
  }
 
  static inline void cxl_debugfs_afu_remove(struct cxl_afu *afu)
drivers/misc/cxl/debugfs.c +11 -25
index 1fda22c24c93..7b987bf498b5 100644
@@ -26,11 +26,11 @@ static int debugfs_io_u64_set(void *data, u64 val)
  DEFINE_DEBUGFS_ATTRIBUTE(fops_io_x64, debugfs_io_u64_get, debugfs_io_u64_set,
  			 "0x%016llx\n");
 
-static struct dentry *debugfs_create_io_x64(const char *name, umode_t mode,
-					    struct dentry *parent, u64 __iomem *value)
+static void debugfs_create_io_x64(const char *name, umode_t mode,
+				  struct dentry *parent, u64 __iomem *value)
  {
-	return debugfs_create_file_unsafe(name, mode, parent,
-					  (void __force *)value, &fops_io_x64);
+	debugfs_create_file_unsafe(name, mode, parent, (void __force *)value,
+				   &fops_io_x64);
  }
 
  void cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter, struct dentry *dir)
@@ -54,25 +54,22 @@ void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir)
  	debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_TRACE));
  }
 
-int cxl_debugfs_adapter_add(struct cxl *adapter)
+void cxl_debugfs_adapter_add(struct cxl *adapter)
  {
  	struct dentry *dir;
  	char buf[32];
 
  	if (!cxl_debugfs)
-		return -ENODEV;
+		return;
 
  	snprintf(buf, 32, "card%i", adapter->adapter_num);
  	dir = debugfs_create_dir(buf, cxl_debugfs);
-	if (IS_ERR(dir))
-		return PTR_ERR(dir);
  	adapter->debugfs = dir;
 
  	debugfs_create_io_x64("err_ivte", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_ErrIVTE));
 
  	if (adapter->native->sl_ops->debugfs_add_adapter_regs)
  		adapter->native->sl_ops->debugfs_add_adapter_regs(adapter, dir);
-	return 0;
  }
 
  void cxl_debugfs_adapter_remove(struct cxl *adapter)
@@ -96,18 +93,16 @@ void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir)
  	debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SLICE_TRACE));
  }
 
-int cxl_debugfs_afu_add(struct cxl_afu *afu)
+void cxl_debugfs_afu_add(struct cxl_afu *afu)
  {
  	struct dentry *dir;
  	char buf[32];
 
  	if (!afu->adapter->debugfs)
-		return -ENODEV;
+		return;
 
  	snprintf(buf, 32, "psl%i.%i", afu->adapter->adapter_num, afu->slice);
  	dir = debugfs_create_dir(buf, afu->adapter->debugfs);
-	if (IS_ERR(dir))
-		return PTR_ERR(dir);
  	afu->debugfs = dir;
 
  	debugfs_create_io_x64("sr",         S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SR_An));
@@ -118,8 +113,6 @@ int cxl_debugfs_afu_add(struct cxl_afu *afu)
 
  	if (afu->adapter->native->sl_ops->debugfs_add_afu_regs)
  		afu->adapter->native->sl_ops->debugfs_add_afu_regs(afu, dir);
-
-	return 0;
  }
 
  void cxl_debugfs_afu_remove(struct cxl_afu *afu)
@@ -127,19 +120,12 @@ void cxl_debugfs_afu_remove(struct cxl_afu *afu)
  	debugfs_remove_recursive(afu->debugfs);
  }
 
-int __init cxl_debugfs_init(void)
+void __init cxl_debugfs_init(void)
  {
-	struct dentry *ent;
-
  	if (!cpu_has_feature(CPU_FTR_HVMODE))
-		return 0;
-
-	ent = debugfs_create_dir("cxl", NULL);
-	if (IS_ERR(ent))
-		return PTR_ERR(ent);
-	cxl_debugfs = ent;
+		return;
 
-	return 0;
+	cxl_debugfs = debugfs_create_dir("cxl", NULL);
  }
 
  void cxl_debugfs_exit(void)
Acked-by on v2 1/1
#3 lore raw
In reply to Greg Kroah-Hartman
Quoted 8 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.

Because there's no need to check, also make the return value of the local debugfs_create_io_x64() call void, as no one ever did anything with the return value (as they did not need to.)

Quoted 8 lines

And make the cxl_debugfs_* calls return void as no one was even checking their return value at all.

Cc Frederic Barrat <[email protected]>
Cc Andrew Donnellan <[email protected]>
Cc Arnd Bergmann <[email protected]>
Quoted 160 lines

---
v2: make the return value of all of the cxl_debugfs_* calls void as no
one was checking the return values of them.

  drivers/misc/cxl/cxl.h     | 15 ++++++---------
  drivers/misc/cxl/debugfs.c | 36 +++++++++++-------------------------
  2 files changed, 17 insertions(+), 34 deletions(-)
drivers/misc/cxl/cxl.h +6 -9
index a73c9e669d78..5dc0f6093f9d 100644
@@ -908,11 +908,11 @@ void cxl_update_dedicated_ivtes_psl8(struct cxl_context *ctx);
 
  #ifdef CONFIG_DEBUG_FS
 
-int cxl_debugfs_init(void);
+void cxl_debugfs_init(void);
  void cxl_debugfs_exit(void);
-int cxl_debugfs_adapter_add(struct cxl *adapter);
+void cxl_debugfs_adapter_add(struct cxl *adapter);
  void cxl_debugfs_adapter_remove(struct cxl *adapter);
-int cxl_debugfs_afu_add(struct cxl_afu *afu);
+void cxl_debugfs_afu_add(struct cxl_afu *afu);
  void cxl_debugfs_afu_remove(struct cxl_afu *afu);
  void cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter, struct dentry *dir);
  void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir);
@@ -921,27 +921,24 @@ void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir);
 
  #else /* CONFIG_DEBUG_FS */
 
-static inline int __init cxl_debugfs_init(void)
+static inline void __init cxl_debugfs_init(void)
  {
-	return 0;
  }
 
  static inline void cxl_debugfs_exit(void)
  {
  }
 
-static inline int cxl_debugfs_adapter_add(struct cxl *adapter)
+static inline void cxl_debugfs_adapter_add(struct cxl *adapter)
  {
-	return 0;
  }
 
  static inline void cxl_debugfs_adapter_remove(struct cxl *adapter)
  {
  }
 
-static inline int cxl_debugfs_afu_add(struct cxl_afu *afu)
+static inline void cxl_debugfs_afu_add(struct cxl_afu *afu)
  {
-	return 0;
  }
 
  static inline void cxl_debugfs_afu_remove(struct cxl_afu *afu)
drivers/misc/cxl/debugfs.c +11 -25
index 1fda22c24c93..7b987bf498b5 100644
@@ -26,11 +26,11 @@ static int debugfs_io_u64_set(void *data, u64 val)
  DEFINE_DEBUGFS_ATTRIBUTE(fops_io_x64, debugfs_io_u64_get, debugfs_io_u64_set,
  			 "0x%016llx\n");
 
-static struct dentry *debugfs_create_io_x64(const char *name, umode_t mode,
-					    struct dentry *parent, u64 __iomem *value)
+static void debugfs_create_io_x64(const char *name, umode_t mode,
+				  struct dentry *parent, u64 __iomem *value)
  {
-	return debugfs_create_file_unsafe(name, mode, parent,
-					  (void __force *)value, &fops_io_x64);
+	debugfs_create_file_unsafe(name, mode, parent, (void __force *)value,
+				   &fops_io_x64);
  }
 
  void cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter, struct dentry *dir)
@@ -54,25 +54,22 @@ void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir)
  	debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_TRACE));
  }
 
-int cxl_debugfs_adapter_add(struct cxl *adapter)
+void cxl_debugfs_adapter_add(struct cxl *adapter)
  {
  	struct dentry *dir;
  	char buf[32];
 
  	if (!cxl_debugfs)
-		return -ENODEV;
+		return;
 
  	snprintf(buf, 32, "card%i", adapter->adapter_num);
  	dir = debugfs_create_dir(buf, cxl_debugfs);
-	if (IS_ERR(dir))
-		return PTR_ERR(dir);
  	adapter->debugfs = dir;
 
  	debugfs_create_io_x64("err_ivte", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_ErrIVTE));
 
  	if (adapter->native->sl_ops->debugfs_add_adapter_regs)
  		adapter->native->sl_ops->debugfs_add_adapter_regs(adapter, dir);
-	return 0;
  }
 
  void cxl_debugfs_adapter_remove(struct cxl *adapter)
@@ -96,18 +93,16 @@ void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir)
  	debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SLICE_TRACE));
  }
 
-int cxl_debugfs_afu_add(struct cxl_afu *afu)
+void cxl_debugfs_afu_add(struct cxl_afu *afu)
  {
  	struct dentry *dir;
  	char buf[32];
 
  	if (!afu->adapter->debugfs)
-		return -ENODEV;
+		return;
 
  	snprintf(buf, 32, "psl%i.%i", afu->adapter->adapter_num, afu->slice);
  	dir = debugfs_create_dir(buf, afu->adapter->debugfs);
-	if (IS_ERR(dir))
-		return PTR_ERR(dir);
  	afu->debugfs = dir;
 
  	debugfs_create_io_x64("sr",         S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SR_An));
@@ -118,8 +113,6 @@ int cxl_debugfs_afu_add(struct cxl_afu *afu)
 
  	if (afu->adapter->native->sl_ops->debugfs_add_afu_regs)
  		afu->adapter->native->sl_ops->debugfs_add_afu_regs(afu, dir);
-
-	return 0;
  }
 
  void cxl_debugfs_afu_remove(struct cxl_afu *afu)
@@ -127,19 +120,12 @@ void cxl_debugfs_afu_remove(struct cxl_afu *afu)
  	debugfs_remove_recursive(afu->debugfs);
  }
 
-int __init cxl_debugfs_init(void)
+void __init cxl_debugfs_init(void)
  {
-	struct dentry *ent;
-
  	if (!cpu_has_feature(CPU_FTR_HVMODE))
-		return 0;
-
-	ent = debugfs_create_dir("cxl", NULL);
-	if (IS_ERR(ent))
-		return PTR_ERR(ent);
-	cxl_debugfs = ent;
+		return;
 
-	return 0;
+	cxl_debugfs = debugfs_create_dir("cxl", NULL);
  }
 
  void cxl_debugfs_exit(void)
Signature · 2 lines
Andrew Donnellan              OzLabs, ADL Canberra
[email protected]             IBM Australia Limited
#4 lore raw
In reply to Greg Kroah-Hartman
Quoted 11 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.

Because there's no need to check, also make the return value of the local debugfs_create_io_x64() call void, as no one ever did anything with the return value (as they did not need to.)

And make the cxl_debugfs_* calls return void as no one was even checking their return value at all.

Quoted 8 lines

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/1b7de1df997a57e3e144bdb31ceaee9c16d6d284

cheers