Skip to contentSkip to conversation

brcm80211: no need to check return value of debugfs_create functions

PATCH In review Greg Kroah-Hartman 3 participants 5 messages Jan 22, 2019 – Feb 1, 2019 Broadcom BRCM80211 IEEE802.11 wireless drivers

lore
Share & tools
lore
#0 lore raw

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

---
 .../broadcom/brcm80211/brcmsmac/debug.c       | 26 +++----------------
 .../broadcom/brcm80211/brcmsmac/debug.h       |  2 +-
 2 files changed, 5 insertions(+), 23 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmsmac/debug.c +4 -22
index 3bd54f125776..6d776ef6ff54 100644
@@ -37,27 +37,18 @@ static struct dentry *root_folder;
 void brcms_debugfs_init(void)
 {
 	root_folder = debugfs_create_dir(KBUILD_MODNAME, NULL);
-	if (IS_ERR(root_folder))
-		root_folder = NULL;
 }
 
 void brcms_debugfs_exit(void)
 {
-	if (!root_folder)
-		return;
-
 	debugfs_remove_recursive(root_folder);
 	root_folder = NULL;
 }
 
-int brcms_debugfs_attach(struct brcms_pub *drvr)
+void brcms_debugfs_attach(struct brcms_pub *drvr)
 {
-	if (!root_folder)
-		return -ENODEV;
-
 	drvr->dbgfs_dir = debugfs_create_dir(
 		 dev_name(&drvr->wlc->hw->d11core->dev), root_folder);
-	return PTR_ERR_OR_ZERO(drvr->dbgfs_dir);
 }
 
 void brcms_debugfs_detach(struct brcms_pub *drvr)
@@ -195,7 +186,7 @@ static const struct file_operations brcms_debugfs_def_ops = {
 	.llseek = seq_lseek
 };
 
-static int
+static void
 brcms_debugfs_add_entry(struct brcms_pub *drvr, const char *fn,
 			int (*read_fn)(struct seq_file *seq, void *data))
 {
@@ -203,27 +194,18 @@ brcms_debugfs_add_entry(struct brcms_pub *drvr, const char *fn,
 	struct dentry *dentry =  drvr->dbgfs_dir;
 	struct brcms_debugfs_entry *entry;
 
-	if (IS_ERR_OR_NULL(dentry))
-		return -ENOENT;
-
 	entry = devm_kzalloc(dev, sizeof(*entry), GFP_KERNEL);
 	if (!entry)
-		return -ENOMEM;
+		return;
 
 	entry->read = read_fn;
 	entry->drvr = drvr;
 
-	dentry = debugfs_create_file(fn, 0444, dentry, entry,
-				     &brcms_debugfs_def_ops);
-
-	return PTR_ERR_OR_ZERO(dentry);
+	debugfs_create_file(fn, 0444, dentry, entry, &brcms_debugfs_def_ops);
 }
 
 void brcms_debugfs_create_files(struct brcms_pub *drvr)
 {
-	if (IS_ERR_OR_NULL(drvr->dbgfs_dir))
-		return;
-
 	brcms_debugfs_add_entry(drvr, "hardware", brcms_debugfs_hardware_read);
 	brcms_debugfs_add_entry(drvr, "macstat", brcms_debugfs_macstat_read);
 }
drivers/net/wireless/broadcom/brcm80211/brcmsmac/debug.h +1 -1
index 822781cf15d4..56898e6d789d 100644
@@ -68,7 +68,7 @@ void __brcms_dbg(struct device *dev, u32 level, const char *func,
 struct brcms_pub;
 void brcms_debugfs_init(void);
 void brcms_debugfs_exit(void);
-int brcms_debugfs_attach(struct brcms_pub *drvr);
+void brcms_debugfs_attach(struct brcms_pub *drvr);
 void brcms_debugfs_detach(struct brcms_pub *drvr);
 struct dentry *brcms_debugfs_get_devdir(struct brcms_pub *drvr);
 void brcms_debugfs_create_files(struct brcms_pub *drvr);
Signature · 1 line
2.20.1
maintainer Acked-by on v1 1/1
#1 lore raw

The prefix should be 'brcmsmac'.

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.

I could argue that if above is true it would be better to make the debugfs function return void, but I won't ;-p

In start_creating() the parent dentry is indeed checked for IS_ERR() so...

Acked-by Arend van Spriel
Quoted 14 lines
---
  .../broadcom/brcm80211/brcmsmac/debug.c       | 26 +++----------------
  .../broadcom/brcm80211/brcmsmac/debug.h       |  2 +-
  2 files changed, 5 insertions(+), 23 deletions(-)
#2 lore raw
Quoted 9 lines · Arend Van Spriel

The prefix should be 'brcmsmac'.

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.

I could argue that if above is true it would be better to make the debugfs function return void, but I won't ;-p

I would really want to do that, but sometimes you need that return value to pass to other debugfs functions :(

Quoted 3 lines

In start_creating() the parent dentry is indeed checked for IS_ERR() so...

Acked-by Arend van Spriel

thanks for the review!

greg k-h

#4 lore raw

Re: [PATCH] brcmsmac: no need to check return value of debugfs_create functions

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

Quoted 11 lines
Cc Arend van Spriel <[email protected]>
Cc Franky Lin <[email protected]>
Cc Hante Meuleman <[email protected]>
Cc Chi-Hsien Lin <[email protected]>
Cc Wright Feng <[email protected]>
Cc Kalle Valo <[email protected]>
Acked-by Arend van Spriel

Patch applied to wireless-drivers-next.git, thanks.

9ae49980bdca brcmsmac: no need to check return value of debugfs_create functions

Signature · 3 lines
https://patchwork.kernel.org/patch/10775745/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches