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 | 6f3dcde9c6dcbbe781a2a98900552bcb989733e3 (patch) | |
tree | 9eb3891644057a011d24c10e8330299b647a490a /drivers | |
parent | 892514a6372d49ffe9749fb86cc587b4dce90733 (diff) |
hwmon: (w83795) Merge w83795_create_files and w83795_remove_files
Functions w83795_create_files and w83795_remove_files iterate over
the same set of files, just calling a different function. Merge them
into a single function which takes the action as a parameter. This
saves code, and also ensure that file creation and deletion are in
sync.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/hwmon/w83795.c | 55 |
1 files changed, 17 insertions, 38 deletions
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c index 309e2e5a187e..ca8b0aec53e6 100644 --- a/drivers/hwmon/w83795.c +++ b/drivers/hwmon/w83795.c | |||
@@ -1777,7 +1777,8 @@ static int w83795_detect(struct i2c_client *client, | |||
1777 | return 0; | 1777 | return 0; |
1778 | } | 1778 | } |
1779 | 1779 | ||
1780 | static int w83795_create_files(struct device *dev) | 1780 | static int w83795_handle_files(struct device *dev, int (*fn)(struct device *, |
1781 | const struct device_attribute *)) | ||
1781 | { | 1782 | { |
1782 | struct w83795_data *data = dev_get_drvdata(dev); | 1783 | struct w83795_data *data = dev_get_drvdata(dev); |
1783 | int err, i; | 1784 | int err, i; |
@@ -1785,7 +1786,7 @@ static int w83795_create_files(struct device *dev) | |||
1785 | for (i = 0; i < ARRAY_SIZE(w83795_in); i++) { | 1786 | for (i = 0; i < ARRAY_SIZE(w83795_in); i++) { |
1786 | if (!(data->has_in & (1 << (i / 6)))) | 1787 | if (!(data->has_in & (1 << (i / 6)))) |
1787 | continue; | 1788 | continue; |
1788 | err = device_create_file(dev, &w83795_in[i].dev_attr); | 1789 | err = fn(dev, &w83795_in[i].dev_attr); |
1789 | if (err) | 1790 | if (err) |
1790 | return err; | 1791 | return err; |
1791 | } | 1792 | } |
@@ -1793,21 +1794,20 @@ static int w83795_create_files(struct device *dev) | |||
1793 | for (i = 0; i < ARRAY_SIZE(w83795_fan); i++) { | 1794 | for (i = 0; i < ARRAY_SIZE(w83795_fan); i++) { |
1794 | if (!(data->has_fan & (1 << (i / 5)))) | 1795 | if (!(data->has_fan & (1 << (i / 5)))) |
1795 | continue; | 1796 | continue; |
1796 | err = device_create_file(dev, &w83795_fan[i].dev_attr); | 1797 | err = fn(dev, &w83795_fan[i].dev_attr); |
1797 | if (err) | 1798 | if (err) |
1798 | return err; | 1799 | return err; |
1799 | } | 1800 | } |
1800 | 1801 | ||
1801 | for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) { | 1802 | for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) { |
1802 | err = device_create_file(dev, &sda_single_files[i].dev_attr); | 1803 | err = fn(dev, &sda_single_files[i].dev_attr); |
1803 | if (err) | 1804 | if (err) |
1804 | return err; | 1805 | return err; |
1805 | } | 1806 | } |
1806 | 1807 | ||
1807 | if (data->chip_type == w83795g) { | 1808 | if (data->chip_type == w83795g) { |
1808 | for (i = 0; i < ARRAY_SIZE(w83795_left_reg); i++) { | 1809 | for (i = 0; i < ARRAY_SIZE(w83795_left_reg); i++) { |
1809 | err = device_create_file(dev, | 1810 | err = fn(dev, &w83795_left_reg[i].dev_attr); |
1810 | &w83795_left_reg[i].dev_attr); | ||
1811 | if (err) | 1811 | if (err) |
1812 | return err; | 1812 | return err; |
1813 | } | 1813 | } |
@@ -1816,7 +1816,7 @@ static int w83795_create_files(struct device *dev) | |||
1816 | for (i = 0; i < ARRAY_SIZE(w83795_temp); i++) { | 1816 | for (i = 0; i < ARRAY_SIZE(w83795_temp); i++) { |
1817 | if (!(data->has_temp & (1 << (i / 29)))) | 1817 | if (!(data->has_temp & (1 << (i / 29)))) |
1818 | continue; | 1818 | continue; |
1819 | err = device_create_file(dev, &w83795_temp[i].dev_attr); | 1819 | err = fn(dev, &w83795_temp[i].dev_attr); |
1820 | if (err) | 1820 | if (err) |
1821 | return err; | 1821 | return err; |
1822 | } | 1822 | } |
@@ -1825,14 +1825,14 @@ static int w83795_create_files(struct device *dev) | |||
1825 | for (i = 0; i < ARRAY_SIZE(w83795_dts); i++) { | 1825 | for (i = 0; i < ARRAY_SIZE(w83795_dts); i++) { |
1826 | if (!(data->has_dts & (1 << (i / 8)))) | 1826 | if (!(data->has_dts & (1 << (i / 8)))) |
1827 | continue; | 1827 | continue; |
1828 | err = device_create_file(dev, &w83795_dts[i].dev_attr); | 1828 | err = fn(dev, &w83795_dts[i].dev_attr); |
1829 | if (err) | 1829 | if (err) |
1830 | return err; | 1830 | return err; |
1831 | } | 1831 | } |
1832 | } | 1832 | } |
1833 | 1833 | ||
1834 | for (i = 0; i < ARRAY_SIZE(w83795_static); i++) { | 1834 | for (i = 0; i < ARRAY_SIZE(w83795_static); i++) { |
1835 | err = device_create_file(dev, &w83795_static[i].dev_attr); | 1835 | err = fn(dev, &w83795_static[i].dev_attr); |
1836 | if (err) | 1836 | if (err) |
1837 | return err; | 1837 | return err; |
1838 | } | 1838 | } |
@@ -1840,33 +1840,12 @@ static int w83795_create_files(struct device *dev) | |||
1840 | return 0; | 1840 | return 0; |
1841 | } | 1841 | } |
1842 | 1842 | ||
1843 | static void w83795_remove_files(struct device *dev) | 1843 | /* We need a wrapper that fits in w83795_handle_files */ |
1844 | static int device_remove_file_wrapper(struct device *dev, | ||
1845 | const struct device_attribute *attr) | ||
1844 | { | 1846 | { |
1845 | struct w83795_data *data = dev_get_drvdata(dev); | 1847 | device_remove_file(dev, attr); |
1846 | int i; | 1848 | return 0; |
1847 | |||
1848 | for (i = 0; i < ARRAY_SIZE(w83795_in); i++) | ||
1849 | device_remove_file(dev, &w83795_in[i].dev_attr); | ||
1850 | |||
1851 | for (i = 0; i < ARRAY_SIZE(w83795_fan); i++) | ||
1852 | device_remove_file(dev, &w83795_fan[i].dev_attr); | ||
1853 | |||
1854 | for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) | ||
1855 | device_remove_file(dev, &sda_single_files[i].dev_attr); | ||
1856 | |||
1857 | if (data->chip_type == w83795g) { | ||
1858 | for (i = 0; i < ARRAY_SIZE(w83795_left_reg); i++) | ||
1859 | device_remove_file(dev, &w83795_left_reg[i].dev_attr); | ||
1860 | } | ||
1861 | |||
1862 | for (i = 0; i < ARRAY_SIZE(w83795_temp); i++) | ||
1863 | device_remove_file(dev, &w83795_temp[i].dev_attr); | ||
1864 | |||
1865 | for (i = 0; i < ARRAY_SIZE(w83795_dts); i++) | ||
1866 | device_remove_file(dev, &w83795_dts[i].dev_attr); | ||
1867 | |||
1868 | for (i = 0; i < ARRAY_SIZE(w83795_static); i++) | ||
1869 | device_remove_file(dev, &w83795_static[i].dev_attr); | ||
1870 | } | 1849 | } |
1871 | 1850 | ||
1872 | static int w83795_probe(struct i2c_client *client, | 1851 | static int w83795_probe(struct i2c_client *client, |
@@ -2093,7 +2072,7 @@ static int w83795_probe(struct i2c_client *client, | |||
2093 | data->beep_enable = | 2072 | data->beep_enable = |
2094 | (w83795_read(client, W83795_REG_BEEP(5)) >> 7) & 0x01; | 2073 | (w83795_read(client, W83795_REG_BEEP(5)) >> 7) & 0x01; |
2095 | 2074 | ||
2096 | err = w83795_create_files(dev); | 2075 | err = w83795_handle_files(dev, device_create_file); |
2097 | if (err) | 2076 | if (err) |
2098 | goto exit_remove; | 2077 | goto exit_remove; |
2099 | 2078 | ||
@@ -2106,7 +2085,7 @@ static int w83795_probe(struct i2c_client *client, | |||
2106 | return 0; | 2085 | return 0; |
2107 | 2086 | ||
2108 | exit_remove: | 2087 | exit_remove: |
2109 | w83795_remove_files(dev); | 2088 | w83795_handle_files(dev, device_remove_file_wrapper); |
2110 | kfree(data); | 2089 | kfree(data); |
2111 | exit: | 2090 | exit: |
2112 | return err; | 2091 | return err; |
@@ -2117,7 +2096,7 @@ static int w83795_remove(struct i2c_client *client) | |||
2117 | struct w83795_data *data = i2c_get_clientdata(client); | 2096 | struct w83795_data *data = i2c_get_clientdata(client); |
2118 | 2097 | ||
2119 | hwmon_device_unregister(data->hwmon_dev); | 2098 | hwmon_device_unregister(data->hwmon_dev); |
2120 | w83795_remove_files(&client->dev); | 2099 | w83795_handle_files(&client->dev, device_remove_file_wrapper); |
2121 | kfree(data); | 2100 | kfree(data); |
2122 | 2101 | ||
2123 | return 0; | 2102 | return 0; |