aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2010-10-28 14:31:45 -0400
committerJean Delvare <khali@endymion.delvare>2010-10-28 14:31:45 -0400
commit892514a6372d49ffe9749fb86cc587b4dce90733 (patch)
tree766bd801a21b585f78f5e6eed1ac7c681b826777
parent2fa09878ba1dc458b8cb6e9c8fbc8f2e5401d2b2 (diff)
hwmon: (w83795) Move file creation to a separate function too
Function w83795_probe() is way too big, move file creation to a separate function to make it more readable. Signed-off-by: Jean Delvare <khali@linux-fr.org>
-rw-r--r--drivers/hwmon/w83795.c121
1 files changed, 66 insertions, 55 deletions
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c
index 00d539a74d0c..309e2e5a187e 100644
--- a/drivers/hwmon/w83795.c
+++ b/drivers/hwmon/w83795.c
@@ -1777,6 +1777,69 @@ static int w83795_detect(struct i2c_client *client,
1777 return 0; 1777 return 0;
1778} 1778}
1779 1779
1780static int w83795_create_files(struct device *dev)
1781{
1782 struct w83795_data *data = dev_get_drvdata(dev);
1783 int err, i;
1784
1785 for (i = 0; i < ARRAY_SIZE(w83795_in); i++) {
1786 if (!(data->has_in & (1 << (i / 6))))
1787 continue;
1788 err = device_create_file(dev, &w83795_in[i].dev_attr);
1789 if (err)
1790 return err;
1791 }
1792
1793 for (i = 0; i < ARRAY_SIZE(w83795_fan); i++) {
1794 if (!(data->has_fan & (1 << (i / 5))))
1795 continue;
1796 err = device_create_file(dev, &w83795_fan[i].dev_attr);
1797 if (err)
1798 return err;
1799 }
1800
1801 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) {
1802 err = device_create_file(dev, &sda_single_files[i].dev_attr);
1803 if (err)
1804 return err;
1805 }
1806
1807 if (data->chip_type == w83795g) {
1808 for (i = 0; i < ARRAY_SIZE(w83795_left_reg); i++) {
1809 err = device_create_file(dev,
1810 &w83795_left_reg[i].dev_attr);
1811 if (err)
1812 return err;
1813 }
1814 }
1815
1816 for (i = 0; i < ARRAY_SIZE(w83795_temp); i++) {
1817 if (!(data->has_temp & (1 << (i / 29))))
1818 continue;
1819 err = device_create_file(dev, &w83795_temp[i].dev_attr);
1820 if (err)
1821 return err;
1822 }
1823
1824 if (data->enable_dts != 0) {
1825 for (i = 0; i < ARRAY_SIZE(w83795_dts); i++) {
1826 if (!(data->has_dts & (1 << (i / 8))))
1827 continue;
1828 err = device_create_file(dev, &w83795_dts[i].dev_attr);
1829 if (err)
1830 return err;
1831 }
1832 }
1833
1834 for (i = 0; i < ARRAY_SIZE(w83795_static); i++) {
1835 err = device_create_file(dev, &w83795_static[i].dev_attr);
1836 if (err)
1837 return err;
1838 }
1839
1840 return 0;
1841}
1842
1780static void w83795_remove_files(struct device *dev) 1843static void w83795_remove_files(struct device *dev)
1781{ 1844{
1782 struct w83795_data *data = dev_get_drvdata(dev); 1845 struct w83795_data *data = dev_get_drvdata(dev);
@@ -2030,61 +2093,9 @@ static int w83795_probe(struct i2c_client *client,
2030 data->beep_enable = 2093 data->beep_enable =
2031 (w83795_read(client, W83795_REG_BEEP(5)) >> 7) & 0x01; 2094 (w83795_read(client, W83795_REG_BEEP(5)) >> 7) & 0x01;
2032 2095
2033 /* Register sysfs hooks */ 2096 err = w83795_create_files(dev);
2034 for (i = 0; i < ARRAY_SIZE(w83795_in); i++) { 2097 if (err)
2035 if (!(data->has_in & (1 << (i / 6)))) 2098 goto exit_remove;
2036 continue;
2037 err = device_create_file(dev, &w83795_in[i].dev_attr);
2038 if (err)
2039 goto exit_remove;
2040 }
2041
2042 for (i = 0; i < ARRAY_SIZE(w83795_fan); i++) {
2043 if (!(data->has_fan & (1 << (i / 5))))
2044 continue;
2045 err = device_create_file(dev, &w83795_fan[i].dev_attr);
2046 if (err)
2047 goto exit_remove;
2048 }
2049
2050 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) {
2051 err = device_create_file(dev, &sda_single_files[i].dev_attr);
2052 if (err)
2053 goto exit_remove;
2054 }
2055
2056 for (i = 0; i < ARRAY_SIZE(w83795_temp); i++) {
2057 if (!(data->has_temp & (1 << (i / 29))))
2058 continue;
2059 err = device_create_file(dev, &w83795_temp[i].dev_attr);
2060 if (err)
2061 goto exit_remove;
2062 }
2063
2064 if (data->enable_dts != 0) {
2065 for (i = 0; i < ARRAY_SIZE(w83795_dts); i++) {
2066 if (!(data->has_dts & (1 << (i / 8))))
2067 continue;
2068 err = device_create_file(dev, &w83795_dts[i].dev_attr);
2069 if (err)
2070 goto exit_remove;
2071 }
2072 }
2073
2074 if (data->chip_type == w83795g) {
2075 for (i = 0; i < ARRAY_SIZE(w83795_left_reg); i++) {
2076 err = device_create_file(dev,
2077 &w83795_left_reg[i].dev_attr);
2078 if (err)
2079 goto exit_remove;
2080 }
2081 }
2082
2083 for (i = 0; i < ARRAY_SIZE(w83795_static); i++) {
2084 err = device_create_file(dev, &w83795_static[i].dev_attr);
2085 if (err)
2086 goto exit_remove;
2087 }
2088 2099
2089 data->hwmon_dev = hwmon_device_register(dev); 2100 data->hwmon_dev = hwmon_device_register(dev);
2090 if (IS_ERR(data->hwmon_dev)) { 2101 if (IS_ERR(data->hwmon_dev)) {