char: misc: Trivial cleanup
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]>
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
@@ -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
PATCH 2/3 char: misc: Rename a local variable in misc_init()
In reply to Zijun HuFrom: 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
@@ -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
Greg Kroah-Hartman
maintainerRe: [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.
Signed-off-by Zijun Hu <[email protected]>--- drivers/char/misc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/char/misc.c +0
-0
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
-1err =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
PATCH 3/3 char: misc: Fix improper and inaccurate error code returned by misc_init()
In reply to Zijun HuFrom: 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
@@ -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