Skip to contentSkip to conversation

drivers: wireless: ath5k: fix parameter check in ath5k_debug_init_device

PATCH In review Minjie Du 5 participants 5 messages Jul 12, 2023 – Jul 24, 2023 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Minjie Du

author
#0 lore raw

PATCH 1/1 drivers: wireless: ath5k: fix parameter check in ath5k_debug_init_device

Make IS_ERR() judge the debugfs_create_dir() function return in ath5k_debug_init_device().

---
 drivers/net/wireless/ath/ath5k/debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath5k/debug.c +1 -1
index 4b41160e5..08058b3f7 100644
@@ -982,7 +982,7 @@ ath5k_debug_init_device(struct ath5k_hw *ah)
 	ah->debug.level = ath5k_debug;
 
 	phydir = debugfs_create_dir("ath5k", ah->hw->wiphy->debugfsdir);
-	if (!phydir)
+	if (IS_ERR(phydir))
 		return;
 
 	debugfs_create_file("debug", 0600, phydir, ah, &fops_debug);
Signature · 1 line
2.39.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 13 lines · Minjie Du

Make IS_ERR() judge the debugfs_create_dir() function return in ath5k_debug_init_device().

---
 drivers/net/wireless/ath/ath5k/debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath5k/debug.c +0 -0
index 4b41160e5..08058b3f7 100644

drivers/net/wireless/ath/ath5k/debug.c ath5k_debug_init_device(struct ath5k_hw *ah) · line 985

Quoted 5 lines
drivers/net/wireless/ath/ath5k/debug.c +1 -1
@@ -982,7 +982,7 @@ ath5k_debug_init_device(struct ath5k_hw *ah)
 	ah->debug.level = ath5k_debug;
 
 	phydir = debugfs_create_dir("ath5k", ah->hw->wiphy->debugfsdir);
-	if (!phydir)
+	if (IS_ERR(phydir))

Please use IS_ERR_OR_NULL() instead.

With that change added:

Luis

A message that is not in the archive (sent off-list or not yet received): [email protected]

maintainer
#3 lore raw
Quoted 6 lines · Markus Elfring
Quoted 6 lines
Quoted 5 lines

+++ b/drivers/net/wireless/ath/ath5k/debug.c

drivers/net/wireless/ath/ath5k/debug.c +0 -0
@@ -982,7 +982,7 @@ ath5k_debug_init_device(struct ath5k_hw *ah)
  	ah->debug.level = ath5k_debug;
 
  	phydir = debugfs_create_dir("ath5k", ah->hw->wiphy->debugfsdir);
drivers/net/wireless/ath/ath5k/debug.c +0 -1
-	if (!phydir)
Quoted 7 lines
Quoted 3 lines

drivers/net/wireless/ath/ath5k/debug.c ath5k_debug_init_device(struct ath5k_hw *ah) · line 985

Quoted 1 line
drivers/net/wireless/ath/ath5k/debug.c +1 -0
+	if (IS_ERR(phydir))

Please use IS_ERR_OR_NULL() instead.

I find your support for consistent error detection interesting here. Contributors for other Linux software components provide different development views.

IS_ERR_OR_NULL() is almost never correct. It is used exceptionally in cases where one needs to distinct three states. It's not the case for sysfs/debugfs interfaces.

Quoted 2 lines

Would a subject like “[PATCH v2] ath5k: Fix an error check in ath5k_debug_init_device()” be more appropriate?

Yes (pointing out specifically "()" at the end). And add the "why" part to the message log too, please.

thanks,

Signature · 2 lines
js
suse labs
#4 lore raw
Quoted 10 lines · Jiri Slaby
Quoted 9 lines · Markus Elfring
Quoted 9 lines
Quoted 5 lines

+++ b/drivers/net/wireless/ath/ath5k/debug.c

drivers/net/wireless/ath/ath5k/debug.c +0 -0
@@ -982,7 +982,7 @@ ath5k_debug_init_device(struct ath5k_hw *ah)
  	ah->debug.level = ath5k_debug;
 
  	phydir = debugfs_create_dir("ath5k", ah->hw->wiphy->debugfsdir);
drivers/net/wireless/ath/ath5k/debug.c +0 -1
-	if (!phydir)

drivers/net/wireless/ath/ath5k/debug.c ath5k_debug_init_device(struct ath5k_hw *ah) · line 985

Quoted 1 line
drivers/net/wireless/ath/ath5k/debug.c +1 -0
+	if (IS_ERR(phydir))

Please use IS_ERR_OR_NULL() instead.

The correct thing for debugfs is to delete the error handling entirely. Checking for NULL is harmless but checking for IS_ERR() will break the driver if debugfs is turned off.

Debugfs is a special case where the error handling was deliberately written so that it's basically impossible to do it correctly. Because as I said at the start, the correct thing is to delete it.

regards,
dan carpenter

#5 lore raw
In reply to Minjie Du

subject prefix should be "wifi: ath5k: "

Quoted 21 lines · Minjie Du

Make IS_ERR() judge the debugfs_create_dir() function return in ath5k_debug_init_device().

---
  drivers/net/wireless/ath/ath5k/debug.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath5k/debug.c +1 -1
index 4b41160e5..08058b3f7 100644
@@ -982,7 +982,7 @@ ath5k_debug_init_device(struct ath5k_hw *ah)
  	ah->debug.level = ath5k_debug;
 
  	phydir = debugfs_create_dir("ath5k", ah->hw->wiphy->debugfsdir);
-	if (!phydir)
+	if (IS_ERR(phydir))
  		return;
 
  	debugfs_create_file("debug", 0600, phydir, ah, &fops_debug);