diff options
author | Jean Delvare <khali@linux-fr.org> | 2010-10-28 14:31:45 -0400 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2010-10-28 14:31:45 -0400 |
commit | 2fa09878ba1dc458b8cb6e9c8fbc8f2e5401d2b2 (patch) | |
tree | 60165028341195ff004c5dac0f9702c8e23aaace | |
parent | 2be381de0f1e5e0324e8b373e7a84fc9d25d05d3 (diff) |
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>
-rw-r--r-- | drivers/hwmon/w83795.c | 81 |
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, | |||
1777 | return 0; | 1777 | return 0; |
1778 | } | 1778 | } |
1779 | 1779 | ||
1780 | static void w83795_remove_files(struct device *dev) | ||
1781 | { | ||
1782 | struct w83795_data *data = dev_get_drvdata(dev); | ||
1783 | int i; | ||
1784 | |||
1785 | for (i = 0; i < ARRAY_SIZE(w83795_in); i++) | ||
1786 | device_remove_file(dev, &w83795_in[i].dev_attr); | ||
1787 | |||
1788 | for (i = 0; i < ARRAY_SIZE(w83795_fan); i++) | ||
1789 | device_remove_file(dev, &w83795_fan[i].dev_attr); | ||
1790 | |||
1791 | for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) | ||
1792 | device_remove_file(dev, &sda_single_files[i].dev_attr); | ||
1793 | |||
1794 | if (data->chip_type == w83795g) { | ||
1795 | for (i = 0; i < ARRAY_SIZE(w83795_left_reg); i++) | ||
1796 | device_remove_file(dev, &w83795_left_reg[i].dev_attr); | ||
1797 | } | ||
1798 | |||
1799 | for (i = 0; i < ARRAY_SIZE(w83795_temp); i++) | ||
1800 | device_remove_file(dev, &w83795_temp[i].dev_attr); | ||
1801 | |||
1802 | for (i = 0; i < ARRAY_SIZE(w83795_dts); i++) | ||
1803 | device_remove_file(dev, &w83795_dts[i].dev_attr); | ||
1804 | |||
1805 | for (i = 0; i < ARRAY_SIZE(w83795_static); i++) | ||
1806 | device_remove_file(dev, &w83795_static[i].dev_attr); | ||
1807 | } | ||
1808 | |||
1780 | static int w83795_probe(struct i2c_client *client, | 1809 | static int w83795_probe(struct i2c_client *client, |
1781 | const struct i2c_device_id *id) | 1810 | const struct i2c_device_id *id) |
1782 | { | 1811 | { |
@@ -2065,31 +2094,8 @@ static int w83795_probe(struct i2c_client *client, | |||
2065 | 2094 | ||
2066 | return 0; | 2095 | return 0; |
2067 | 2096 | ||
2068 | /* Unregister sysfs hooks */ | ||
2069 | exit_remove: | 2097 | exit_remove: |
2070 | for (i = 0; i < ARRAY_SIZE(w83795_in); i++) | 2098 | w83795_remove_files(dev); |
2071 | device_remove_file(dev, &w83795_in[i].dev_attr); | ||
2072 | |||
2073 | for (i = 0; i < ARRAY_SIZE(w83795_fan); i++) | ||
2074 | device_remove_file(dev, &w83795_fan[i].dev_attr); | ||
2075 | |||
2076 | for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) | ||
2077 | device_remove_file(dev, &sda_single_files[i].dev_attr); | ||
2078 | |||
2079 | if (data->chip_type == w83795g) { | ||
2080 | for (i = 0; i < ARRAY_SIZE(w83795_left_reg); i++) | ||
2081 | device_remove_file(dev, &w83795_left_reg[i].dev_attr); | ||
2082 | } | ||
2083 | |||
2084 | for (i = 0; i < ARRAY_SIZE(w83795_temp); i++) | ||
2085 | device_remove_file(dev, &w83795_temp[i].dev_attr); | ||
2086 | |||
2087 | for (i = 0; i < ARRAY_SIZE(w83795_dts); i++) | ||
2088 | device_remove_file(dev, &w83795_dts[i].dev_attr); | ||
2089 | |||
2090 | for (i = 0; i < ARRAY_SIZE(w83795_static); i++) | ||
2091 | device_remove_file(dev, &w83795_static[i].dev_attr); | ||
2092 | |||
2093 | kfree(data); | 2099 | kfree(data); |
2094 | exit: | 2100 | exit: |
2095 | return err; | 2101 | return err; |
@@ -2098,34 +2104,9 @@ exit: | |||
2098 | static int w83795_remove(struct i2c_client *client) | 2104 | static int w83795_remove(struct i2c_client *client) |
2099 | { | 2105 | { |
2100 | struct w83795_data *data = i2c_get_clientdata(client); | 2106 | struct w83795_data *data = i2c_get_clientdata(client); |
2101 | struct device *dev = &client->dev; | ||
2102 | int i; | ||
2103 | 2107 | ||
2104 | hwmon_device_unregister(data->hwmon_dev); | 2108 | hwmon_device_unregister(data->hwmon_dev); |
2105 | 2109 | w83795_remove_files(&client->dev); | |
2106 | for (i = 0; i < ARRAY_SIZE(w83795_in); i++) | ||
2107 | device_remove_file(dev, &w83795_in[i].dev_attr); | ||
2108 | |||
2109 | for (i = 0; i < ARRAY_SIZE(w83795_fan); i++) | ||
2110 | device_remove_file(dev, &w83795_fan[i].dev_attr); | ||
2111 | |||
2112 | for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) | ||
2113 | device_remove_file(dev, &sda_single_files[i].dev_attr); | ||
2114 | |||
2115 | if (data->chip_type == w83795g) { | ||
2116 | for (i = 0; i < ARRAY_SIZE(w83795_left_reg); i++) | ||
2117 | device_remove_file(dev, &w83795_left_reg[i].dev_attr); | ||
2118 | } | ||
2119 | |||
2120 | for (i = 0; i < ARRAY_SIZE(w83795_temp); i++) | ||
2121 | device_remove_file(dev, &w83795_temp[i].dev_attr); | ||
2122 | |||
2123 | for (i = 0; i < ARRAY_SIZE(w83795_dts); i++) | ||
2124 | device_remove_file(dev, &w83795_dts[i].dev_attr); | ||
2125 | |||
2126 | for (i = 0; i < ARRAY_SIZE(w83795_static); i++) | ||
2127 | device_remove_file(dev, &w83795_static[i].dev_attr); | ||
2128 | |||
2129 | kfree(data); | 2110 | kfree(data); |
2130 | 2111 | ||
2131 | return 0; | 2112 | return 0; |