提交 6f3dcde9 编写于 作者: J Jean Delvare 提交者: Jean Delvare

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: NJean Delvare <khali@linux-fr.org>
上级 892514a6
...@@ -1777,7 +1777,8 @@ static int w83795_detect(struct i2c_client *client, ...@@ -1777,7 +1777,8 @@ static int w83795_detect(struct i2c_client *client,
return 0; return 0;
} }
static int w83795_create_files(struct device *dev) static int w83795_handle_files(struct device *dev, int (*fn)(struct device *,
const struct device_attribute *))
{ {
struct w83795_data *data = dev_get_drvdata(dev); struct w83795_data *data = dev_get_drvdata(dev);
int err, i; int err, i;
...@@ -1785,7 +1786,7 @@ static int w83795_create_files(struct device *dev) ...@@ -1785,7 +1786,7 @@ static int w83795_create_files(struct device *dev)
for (i = 0; i < ARRAY_SIZE(w83795_in); i++) { for (i = 0; i < ARRAY_SIZE(w83795_in); i++) {
if (!(data->has_in & (1 << (i / 6)))) if (!(data->has_in & (1 << (i / 6))))
continue; continue;
err = device_create_file(dev, &w83795_in[i].dev_attr); err = fn(dev, &w83795_in[i].dev_attr);
if (err) if (err)
return err; return err;
} }
...@@ -1793,21 +1794,20 @@ static int w83795_create_files(struct device *dev) ...@@ -1793,21 +1794,20 @@ static int w83795_create_files(struct device *dev)
for (i = 0; i < ARRAY_SIZE(w83795_fan); i++) { for (i = 0; i < ARRAY_SIZE(w83795_fan); i++) {
if (!(data->has_fan & (1 << (i / 5)))) if (!(data->has_fan & (1 << (i / 5))))
continue; continue;
err = device_create_file(dev, &w83795_fan[i].dev_attr); err = fn(dev, &w83795_fan[i].dev_attr);
if (err) if (err)
return err; return err;
} }
for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) { for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) {
err = device_create_file(dev, &sda_single_files[i].dev_attr); err = fn(dev, &sda_single_files[i].dev_attr);
if (err) if (err)
return err; return err;
} }
if (data->chip_type == w83795g) { if (data->chip_type == w83795g) {
for (i = 0; i < ARRAY_SIZE(w83795_left_reg); i++) { for (i = 0; i < ARRAY_SIZE(w83795_left_reg); i++) {
err = device_create_file(dev, err = fn(dev, &w83795_left_reg[i].dev_attr);
&w83795_left_reg[i].dev_attr);
if (err) if (err)
return err; return err;
} }
...@@ -1816,7 +1816,7 @@ static int w83795_create_files(struct device *dev) ...@@ -1816,7 +1816,7 @@ static int w83795_create_files(struct device *dev)
for (i = 0; i < ARRAY_SIZE(w83795_temp); i++) { for (i = 0; i < ARRAY_SIZE(w83795_temp); i++) {
if (!(data->has_temp & (1 << (i / 29)))) if (!(data->has_temp & (1 << (i / 29))))
continue; continue;
err = device_create_file(dev, &w83795_temp[i].dev_attr); err = fn(dev, &w83795_temp[i].dev_attr);
if (err) if (err)
return err; return err;
} }
...@@ -1825,14 +1825,14 @@ static int w83795_create_files(struct device *dev) ...@@ -1825,14 +1825,14 @@ static int w83795_create_files(struct device *dev)
for (i = 0; i < ARRAY_SIZE(w83795_dts); i++) { for (i = 0; i < ARRAY_SIZE(w83795_dts); i++) {
if (!(data->has_dts & (1 << (i / 8)))) if (!(data->has_dts & (1 << (i / 8))))
continue; continue;
err = device_create_file(dev, &w83795_dts[i].dev_attr); err = fn(dev, &w83795_dts[i].dev_attr);
if (err) if (err)
return err; return err;
} }
} }
for (i = 0; i < ARRAY_SIZE(w83795_static); i++) { for (i = 0; i < ARRAY_SIZE(w83795_static); i++) {
err = device_create_file(dev, &w83795_static[i].dev_attr); err = fn(dev, &w83795_static[i].dev_attr);
if (err) if (err)
return err; return err;
} }
...@@ -1840,33 +1840,12 @@ static int w83795_create_files(struct device *dev) ...@@ -1840,33 +1840,12 @@ static int w83795_create_files(struct device *dev)
return 0; return 0;
} }
static void w83795_remove_files(struct device *dev) /* We need a wrapper that fits in w83795_handle_files */
static int device_remove_file_wrapper(struct device *dev,
const struct device_attribute *attr)
{ {
struct w83795_data *data = dev_get_drvdata(dev); device_remove_file(dev, attr);
int i; return 0;
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, static int w83795_probe(struct i2c_client *client,
...@@ -2093,7 +2072,7 @@ static int w83795_probe(struct i2c_client *client, ...@@ -2093,7 +2072,7 @@ static int w83795_probe(struct i2c_client *client,
data->beep_enable = data->beep_enable =
(w83795_read(client, W83795_REG_BEEP(5)) >> 7) & 0x01; (w83795_read(client, W83795_REG_BEEP(5)) >> 7) & 0x01;
err = w83795_create_files(dev); err = w83795_handle_files(dev, device_create_file);
if (err) if (err)
goto exit_remove; goto exit_remove;
...@@ -2106,7 +2085,7 @@ static int w83795_probe(struct i2c_client *client, ...@@ -2106,7 +2085,7 @@ static int w83795_probe(struct i2c_client *client,
return 0; return 0;
exit_remove: exit_remove:
w83795_remove_files(dev); w83795_handle_files(dev, device_remove_file_wrapper);
kfree(data); kfree(data);
exit: exit:
return err; return err;
...@@ -2117,7 +2096,7 @@ static int w83795_remove(struct i2c_client *client) ...@@ -2117,7 +2096,7 @@ static int w83795_remove(struct i2c_client *client)
struct w83795_data *data = i2c_get_clientdata(client); struct w83795_data *data = i2c_get_clientdata(client);
hwmon_device_unregister(data->hwmon_dev); hwmon_device_unregister(data->hwmon_dev);
w83795_remove_files(&client->dev); w83795_handle_files(&client->dev, device_remove_file_wrapper);
kfree(data); kfree(data);
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册