Skip to contentSkip to conversation

char: misc: Trivial cleanup

PATCH Superseded Zijun Hu 2 participants 5 messages Jun 20, 2025 – Jun 24, 2025 Char and misc drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Zijun Hu

author
#0 lore raw

cover char: misc: Trivial cleanup

This patch series is to do trivial cleanup for miscdevice driver.

---
Zijun Hu (3):
char: misc: Remove redundant forward declarations
char: misc: Rename a local variable in misc_init()
char: misc: Fix improper and inaccurate error code returned by misc_init()

 drivers/char/misc.c        | 10 +++++-----
 include/linux/miscdevice.h |  3 ---
 2 files changed, 5 insertions(+), 8 deletions(-)

---
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20250620-fix_mischar-794de4259592

Best regards,

Signature · 1 line
Zijun Hu <[email protected]>
author
#1 lore raw

PATCH 1/3 char: misc: Remove redundant forward declarations

From: Zijun Hu <[email protected]>

Header miscdevice.h includes linux/device.h which has definations for below two forward declarations directly or indirectly:

struct device;
struct attribute_group;

Remove these redundant forward declarations from miscdevice.h

---
 include/linux/miscdevice.h | 3 ---
 1 file changed, 3 deletions(-)
include/linux/miscdevice.h +0 -3
index 69e110c2b86a9b16c1637778a25e1eebb3fd0111..3e6deb00fc8535a7571f85489c74979e18385bad 100644
@@ -73,9 +73,6 @@
 #define RFKILL_MINOR		242
 #define MISC_DYNAMIC_MINOR	255
 
-struct device;
-struct attribute_group;
-
 struct miscdevice {
 	int minor;
 	const char *name;
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/3 char: misc: Rename a local variable in misc_init()

In reply to Zijun Hu

From: Zijun Hu <[email protected]>

Local variable @ret is not used for return value in misc_init().

Give it a different name @pde.

---
 drivers/char/misc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/char/misc.c +3 -3
index d5accc10a110098f7090dd0f900bc5fae5f75f74..f5ef8c175adb559e67dfe905d43d1404b249cc9e 100644
@@ -289,9 +289,9 @@ EXPORT_SYMBOL(misc_deregister);
 static int __init misc_init(void)
 {
 	int err;
-	struct proc_dir_entry *ret;
+	struct proc_dir_entry *pde;
 
-	ret = proc_create_seq("misc", 0, NULL, &misc_seq_ops);
+	pde = proc_create_seq("misc", 0, NULL, &misc_seq_ops);
 	err = class_register(&misc_class);
 	if (err)
 		goto fail_remove;
@@ -305,7 +305,7 @@ static int __init misc_init(void)
 	pr_err("unable to get major %d for misc devices\n", MISC_MAJOR);
 	class_unregister(&misc_class);
 fail_remove:
-	if (ret)
+	if (pde)
 		remove_proc_entry("misc", NULL);
 	return err;
 }
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH 2/3] char: misc: Rename a local variable in misc_init()

Quoted 16 lines · Zijun Hu

From: Zijun Hu <[email protected]>

Local variable @ret is not used for return value in misc_init().

Give it a different name @pde.

---
 drivers/char/misc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/char/misc.c +0 -0
index d5accc10a110098f7090dd0f900bc5fae5f75f74..f5ef8c175adb559e67dfe905d43d1404b249cc9e 100644

drivers/char/misc.c EXPORT_SYMBOL(misc_deregister); · line 292

Quoted 5 lines
drivers/char/misc.c +1 -1
@@ -289,9 +289,9 @@ EXPORT_SYMBOL(misc_deregister);
 static int __init misc_init(void)
 {
 	int err;
-	struct proc_dir_entry *ret;
+	struct proc_dir_entry *pde;

"pde" is an odd name.

drivers/char/misc.c EXPORT_SYMBOL(misc_deregister); · line 294

Quoted 2 lines
drivers/char/misc.c +1 -1
-	ret = proc_create_seq("misc", 0, NULL, &misc_seq_ops);
+	pde = proc_create_seq("misc", 0, NULL, &misc_seq_ops);

Why not "misc_proc_file" as a better name?

drivers/char/misc.c static int __init misc_init(void) · line 308

Quoted 9 lines
drivers/char/misc.c +1 -1
 	err = class_register(&misc_class);
 	if (err)
 		goto fail_remove;
@@ -305,7 +305,7 @@ static int __init misc_init(void)
 	pr_err("unable to get major %d for misc devices\n", MISC_MAJOR);
 	class_unregister(&misc_class);
 fail_remove:
-	if (ret)
+	if (pde)

Again, "pde" is a rough name, let's pick a better one please.

thanks,

greg k-h

author
#4 lore raw

PATCH 3/3 char: misc: Fix improper and inaccurate error code returned by misc_init()

In reply to Zijun Hu

From: Zijun Hu <[email protected]>

misc_init() returns -EIO for __register_chrdev() invocation failure, but:

- -EIO is for I/O error normally, but __register_chrdev() does not do I/O.
- -EIO can not cover various error codes returned by __register_chrdev().

Fix by returning error code of __register_chrdev().

---
 drivers/char/misc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/char/misc.c +2 -2
index f5ef8c175adb559e67dfe905d43d1404b249cc9e..e5ea36bbf6b3d1313eb35d3259617bf90c55727d 100644
@@ -296,8 +296,8 @@ static int __init misc_init(void)
 	if (err)
 		goto fail_remove;
 
-	err = -EIO;
-	if (__register_chrdev(MISC_MAJOR, 0, MINORMASK + 1, "misc", &misc_fops))
+	err = __register_chrdev(MISC_MAJOR, 0, MINORMASK + 1, "misc", &misc_fops);
+	if (err < 0)
 		goto fail_printk;
 	return 0;
 
Signature · 1 line
2.34.1