summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2010-10-28 20:31:45 +0200
committerJean Delvare <khali@endymion.delvare>2010-10-28 20:31:45 +0200
commit2fa09878ba1dc458b8cb6e9c8fbc8f2e5401d2b2 (patch)
tree60165028341195ff004c5dac0f9702c8e23aaace /drivers/hwmon
parent2be381de0f1e5e0324e8b373e7a84fc9d25d05d3 (diff)
downloadblackbird-op-linux-2fa09878ba1dc458b8cb6e9c8fbc8f2e5401d2b2.tar.gz
blackbird-op-linux-2fa09878ba1dc458b8cb6e9c8fbc8f2e5401d2b2.zip
hwmon: (w83795) Move files removal to a separate function
Sysfs files must be removed on device removal but also when device registration fails. Move the code to a separate function to avoid code redundancy. Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/w83795.c81
1 files changed, 31 insertions, 50 deletions
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c
index 6596303566e1..00d539a74d0c 100644
--- a/drivers/hwmon/w83795.c
+++ b/drivers/hwmon/w83795.c
@@ -1777,6 +1777,35 @@ static int w83795_detect(struct i2c_client *client,
return 0;
}
+static void w83795_remove_files(struct device *dev)
+{
+ struct w83795_data *data = dev_get_drvdata(dev);
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(w83795_in); i++)
+ device_remove_file(dev, &w83795_in[i].dev_attr);
+
+ for (i = 0; i < ARRAY_SIZE(w83795_fan); i++)
+ device_remove_file(dev, &w83795_fan[i].dev_attr);
+
+ for (i = 0; i < ARRAY_SIZE(sda_single_files); i++)
+ device_remove_file(dev, &sda_single_files[i].dev_attr);
+
+ if (data->chip_type == w83795g) {
+ for (i = 0; i < ARRAY_SIZE(w83795_left_reg); i++)
+ device_remove_file(dev, &w83795_left_reg[i].dev_attr);
+ }
+
+ for (i = 0; i < ARRAY_SIZE(w83795_temp); i++)
+ device_remove_file(dev, &w83795_temp[i].dev_attr);
+
+ for (i = 0; i < ARRAY_SIZE(w83795_dts); i++)
+ device_remove_file(dev, &w83795_dts[i].dev_attr);
+
+ for (i = 0; i < ARRAY_SIZE(w83795_static); i++)
+ device_remove_file(dev, &w83795_static[i].dev_attr);
+}
+
static int w83795_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@@ -2065,31 +2094,8 @@ static int w83795_probe(struct i2c_client *client,
return 0;
- /* Unregister sysfs hooks */
exit_remove:
- for (i = 0; i < ARRAY_SIZE(w83795_in); i++)
- device_remove_file(dev, &w83795_in[i].dev_attr);
-
- for (i = 0; i < ARRAY_SIZE(w83795_fan); i++)
- device_remove_file(dev, &w83795_fan[i].dev_attr);
-
- for (i = 0; i < ARRAY_SIZE(sda_single_files); i++)
- device_remove_file(dev, &sda_single_files[i].dev_attr);
-
- if (data->chip_type == w83795g) {
- for (i = 0; i < ARRAY_SIZE(w83795_left_reg); i++)
- device_remove_file(dev, &w83795_left_reg[i].dev_attr);
- }
-
- for (i = 0; i < ARRAY_SIZE(w83795_temp); i++)
- device_remove_file(dev, &w83795_temp[i].dev_attr);
-
- for (i = 0; i < ARRAY_SIZE(w83795_dts); i++)
- device_remove_file(dev, &w83795_dts[i].dev_attr);
-
- for (i = 0; i < ARRAY_SIZE(w83795_static); i++)
- device_remove_file(dev, &w83795_static[i].dev_attr);
-
+ w83795_remove_files(dev);
kfree(data);
exit:
return err;
@@ -2098,34 +2104,9 @@ exit:
static int w83795_remove(struct i2c_client *client)
{
struct w83795_data *data = i2c_get_clientdata(client);
- struct device *dev = &client->dev;
- int i;
hwmon_device_unregister(data->hwmon_dev);
-
- for (i = 0; i < ARRAY_SIZE(w83795_in); i++)
- device_remove_file(dev, &w83795_in[i].dev_attr);
-
- for (i = 0; i < ARRAY_SIZE(w83795_fan); i++)
- device_remove_file(dev, &w83795_fan[i].dev_attr);
-
- for (i = 0; i < ARRAY_SIZE(sda_single_files); i++)
- device_remove_file(dev, &sda_single_files[i].dev_attr);
-
- if (data->chip_type == w83795g) {
- for (i = 0; i < ARRAY_SIZE(w83795_left_reg); i++)
- device_remove_file(dev, &w83795_left_reg[i].dev_attr);
- }
-
- for (i = 0; i < ARRAY_SIZE(w83795_temp); i++)
- device_remove_file(dev, &w83795_temp[i].dev_attr);
-
- for (i = 0; i < ARRAY_SIZE(w83795_dts); i++)
- device_remove_file(dev, &w83795_dts[i].dev_attr);
-
- for (i = 0; i < ARRAY_SIZE(w83795_static); i++)
- device_remove_file(dev, &w83795_static[i].dev_attr);
-
+ w83795_remove_files(&client->dev);
kfree(data);
return 0;
OpenPOWER on IntegriCloud