hwmon: (dell-smm) Fix warning on /proc/i8k creation error
authorArmin Wolf <W_Armin@gmx.de>
Fri, 12 Nov 2021 17:14:40 +0000 (18:14 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Dec 2021 08:17:58 +0000 (09:17 +0100)
commit dbd3e6eaf3d813939b28e8a66e29d81cdc836445 upstream.

The removal function is called regardless of whether
/proc/i8k was created successfully or not, the later
causing a WARN() on module removal.
Fix that by only registering the removal function
if /proc/i8k was created successfully.

Tested on a Inspiron 3505.

Fixes: 039ae58503f3 ("hwmon: Allow to compile dell-smm-hwmon driver without /proc/i8k")
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
Acked-by: Pali Rohár <pali@kernel.org>
Link: https://lore.kernel.org/r/20211112171440.59006-1-W_Armin@gmx.de
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/hwmon/dell-smm-hwmon.c

index c7c9e95e58a83298e57b38c80cccb639ab9e17b3..123b870728fbcb0cb421b3f7f3d247d2daf58fd3 100644 (file)
@@ -578,15 +578,18 @@ static const struct file_operations i8k_fops = {
        .unlocked_ioctl = i8k_ioctl,
 };
 
+static struct proc_dir_entry *entry;
+
 static void __init i8k_init_procfs(void)
 {
        /* Register the proc entry */
-       proc_create("i8k", 0, NULL, &i8k_fops);
+       entry = proc_create("i8k", 0, NULL, &i8k_fops);
 }
 
 static void __exit i8k_exit_procfs(void)
 {
-       remove_proc_entry("i8k", NULL);
+       if (entry)
+               remove_proc_entry("i8k", NULL);
 }
 
 #else