Commit 0559a538 authored by Henrik Rydberg's avatar Henrik Rydberg Committed by Jean Delvare

hwmon: (applesmc) Correct sysfs fan error handling

The current code will not remove the sysfs files for fan numbers three
and up. Also, upon exit, fans one and two are removed regardless of
their existence.  This patch cleans up the sysfs error handling for
the fans.
Signed-off-by: default avatarHenrik Rydberg <rydberg@euromail.se>
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
parent d1bf8cf6
...@@ -195,6 +195,9 @@ static unsigned int applesmc_accelerometer; ...@@ -195,6 +195,9 @@ static unsigned int applesmc_accelerometer;
/* Indicates whether this computer has light sensors and keyboard backlight. */ /* Indicates whether this computer has light sensors and keyboard backlight. */
static unsigned int applesmc_light; static unsigned int applesmc_light;
/* The number of fans handled by the driver */
static unsigned int fans_handled;
/* Indicates which temperature sensors set to use. */ /* Indicates which temperature sensors set to use. */
static unsigned int applesmc_temperature_set; static unsigned int applesmc_temperature_set;
...@@ -1492,39 +1495,24 @@ static int __init applesmc_init(void) ...@@ -1492,39 +1495,24 @@ static int __init applesmc_init(void)
/* create fan files */ /* create fan files */
count = applesmc_get_fan_count(); count = applesmc_get_fan_count();
if (count < 0) { if (count < 0)
printk(KERN_ERR "applesmc: Cannot get the number of fans.\n"); printk(KERN_ERR "applesmc: Cannot get the number of fans.\n");
} else { else
printk(KERN_INFO "applesmc: %d fans found.\n", count); printk(KERN_INFO "applesmc: %d fans found.\n", count);
switch (count) { if (count > 4) {
default: count = 4;
printk(KERN_WARNING "applesmc: More than 4 fans found," printk(KERN_WARNING "applesmc: More than 4 fans found,"
" but at most 4 fans are supported" " but at most 4 fans are supported"
" by the driver.\n"); " by the driver.\n");
case 4: }
ret = sysfs_create_group(&pdev->dev.kobj,
&fan_attribute_groups[3]); while (fans_handled < count) {
if (ret)
goto out_key_enumeration;
case 3:
ret = sysfs_create_group(&pdev->dev.kobj,
&fan_attribute_groups[2]);
if (ret)
goto out_key_enumeration;
case 2:
ret = sysfs_create_group(&pdev->dev.kobj,
&fan_attribute_groups[1]);
if (ret)
goto out_key_enumeration;
case 1:
ret = sysfs_create_group(&pdev->dev.kobj, ret = sysfs_create_group(&pdev->dev.kobj,
&fan_attribute_groups[0]); &fan_attribute_groups[fans_handled]);
if (ret) if (ret)
goto out_fan_1; goto out_fans;
case 0: fans_handled++;
;
}
} }
for (i = 0; for (i = 0;
...@@ -1593,10 +1581,10 @@ static int __init applesmc_init(void) ...@@ -1593,10 +1581,10 @@ static int __init applesmc_init(void)
applesmc_release_accelerometer(); applesmc_release_accelerometer();
out_temperature: out_temperature:
sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group); sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group);
sysfs_remove_group(&pdev->dev.kobj, &fan_attribute_groups[0]); out_fans:
out_fan_1: while (fans_handled)
sysfs_remove_group(&pdev->dev.kobj, &fan_attribute_groups[1]); sysfs_remove_group(&pdev->dev.kobj,
out_key_enumeration: &fan_attribute_groups[--fans_handled]);
sysfs_remove_group(&pdev->dev.kobj, &key_enumeration_group); sysfs_remove_group(&pdev->dev.kobj, &key_enumeration_group);
out_name: out_name:
sysfs_remove_file(&pdev->dev.kobj, &dev_attr_name.attr); sysfs_remove_file(&pdev->dev.kobj, &dev_attr_name.attr);
...@@ -1622,8 +1610,9 @@ static void __exit applesmc_exit(void) ...@@ -1622,8 +1610,9 @@ static void __exit applesmc_exit(void)
if (applesmc_accelerometer) if (applesmc_accelerometer)
applesmc_release_accelerometer(); applesmc_release_accelerometer();
sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group); sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group);
sysfs_remove_group(&pdev->dev.kobj, &fan_attribute_groups[0]); while (fans_handled)
sysfs_remove_group(&pdev->dev.kobj, &fan_attribute_groups[1]); sysfs_remove_group(&pdev->dev.kobj,
&fan_attribute_groups[--fans_handled]);
sysfs_remove_group(&pdev->dev.kobj, &key_enumeration_group); sysfs_remove_group(&pdev->dev.kobj, &key_enumeration_group);
sysfs_remove_file(&pdev->dev.kobj, &dev_attr_name.attr); sysfs_remove_file(&pdev->dev.kobj, &dev_attr_name.attr);
platform_device_unregister(pdev); platform_device_unregister(pdev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment