Skip to contentSkip to conversation

char: misc: remove redundant ifdef

PATCH New Sudip Mukherjee 1 participant 2 messages Jul 13, 2015 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 char: misc: remove redundant ifdef

The check for CONFIG_PROC_FS is not required as the check is being done in proc_fs.h and incase CONFIG_PROC_FS is not defined then proc_create() is defined as NULL.

---
 drivers/char/misc.c | 2 --
 1 file changed, 2 deletions(-)
drivers/char/misc.c +0 -2
index fdb0f9b..3b95795 100644
@@ -282,9 +282,7 @@ static int __init misc_init(void)
 {
 	int err;
 
-#ifdef CONFIG_PROC_FS
 	proc_create("misc", 0, NULL, &misc_proc_fops);
-#endif
 	misc_class = class_create(THIS_MODULE, "misc");
 	err = PTR_ERR(misc_class);
 	if (IS_ERR(misc_class))
Signature · 1 line
1.8.1.2
#1 lore raw

PATCH 2/2 char: misc: fix error path

Lets call remove_proc_entry() in the error path only if we have successfully created "misc" in procfs.

---
 drivers/char/misc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/char/misc.c +4 -2
index 3b95795..acedbaf 100644
@@ -281,8 +281,9 @@ static char *misc_devnode(struct device *dev, umode_t *mode)
 static int __init misc_init(void)
 {
 	int err;
+	struct proc_dir_entry *ret;
 
-	proc_create("misc", 0, NULL, &misc_proc_fops);
+	ret = proc_create("misc", 0, NULL, &misc_proc_fops);
 	misc_class = class_create(THIS_MODULE, "misc");
 	err = PTR_ERR(misc_class);
 	if (IS_ERR(misc_class))
@@ -298,7 +299,8 @@ fail_printk:
 	printk("unable to get major %d for misc devices\n", MISC_MAJOR);
 	class_destroy(misc_class);
 fail_remove:
-	remove_proc_entry("misc", NULL);
+	if (ret)
+		remove_proc_entry("misc", NULL);
 	return err;
 }
 subsys_initcall(misc_init);
Signature · 1 line
1.8.1.2