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);
int err, i;
for (i = 0; i < ARRAY_SIZE(w83795_in); i++) {
if (!(data->has_in & (1 << (i / 6))))
continue;
- err = device_create_file(dev, &w83795_in[i].dev_attr);
+ err = fn(dev, &w83795_in[i].dev_attr);
if (err)
return err;
}
for (i = 0; i < ARRAY_SIZE(w83795_fan); i++) {
if (!(data->has_fan & (1 << (i / 5))))
continue;
- err = device_create_file(dev, &w83795_fan[i].dev_attr);
+ err = fn(dev, &w83795_fan[i].dev_attr);
if (err)
return err;
}
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)
return err;
}
if (data->chip_type == w83795g) {
for (i = 0; i < ARRAY_SIZE(w83795_left_reg); i++) {
- err = device_create_file(dev,
- &w83795_left_reg[i].dev_attr);
+ err = fn(dev, &w83795_left_reg[i].dev_attr);
if (err)
return err;
}
for (i = 0; i < ARRAY_SIZE(w83795_temp); i++) {
if (!(data->has_temp & (1 << (i / 29))))
continue;
- err = device_create_file(dev, &w83795_temp[i].dev_attr);
+ err = fn(dev, &w83795_temp[i].dev_attr);
if (err)
return err;
}
for (i = 0; i < ARRAY_SIZE(w83795_dts); i++) {
if (!(data->has_dts & (1 << (i / 8))))
continue;
- err = device_create_file(dev, &w83795_dts[i].dev_attr);
+ err = fn(dev, &w83795_dts[i].dev_attr);
if (err)
return err;
}
}
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)
return err;
}
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);
- 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);
+ device_remove_file(dev, attr);
+ return 0;
}
static int w83795_probe(struct i2c_client *client,
data->beep_enable =
(w83795_read(client, W83795_REG_BEEP(5)) >> 7) & 0x01;
- err = w83795_create_files(dev);
+ err = w83795_handle_files(dev, device_create_file);
if (err)
goto exit_remove;
return 0;
exit_remove:
- w83795_remove_files(dev);
+ w83795_handle_files(dev, device_remove_file_wrapper);
kfree(data);
exit:
return err;
struct w83795_data *data = i2c_get_clientdata(client);
hwmon_device_unregister(data->hwmon_dev);
- w83795_remove_files(&client->dev);
+ w83795_handle_files(&client->dev, device_remove_file_wrapper);
kfree(data);
return 0;