Commit f0c34c97 authored by Guenter Roeck's avatar Guenter Roeck Committed by Matthew Garrett

eeepc-laptop: Convert to use devm_hwmon_device_register_with_groups

Simplify the code and avoid race condition caused by creating sysfs attributes
after creating the hwmon device.

Also replace SENSOR_DEVICE_ATTR with DEVICE_ATTR since the extra argument
is not used and SENSOR_DEVICE_ATTR is not needed.
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarMatthew Garrett <matthew.garrett@nebula.com>
parent cf508f44
...@@ -166,7 +166,6 @@ struct eeepc_laptop { ...@@ -166,7 +166,6 @@ struct eeepc_laptop {
struct platform_device *platform_device; struct platform_device *platform_device;
struct acpi_device *device; /* the device we are in */ struct acpi_device *device; /* the device we are in */
struct device *hwmon_device;
struct backlight_device *backlight_device; struct backlight_device *backlight_device;
struct input_dev *inputdev; struct input_dev *inputdev;
...@@ -1067,7 +1066,7 @@ static ssize_t show_sys_hwmon(int (*get)(void), char *buf) ...@@ -1067,7 +1066,7 @@ static ssize_t show_sys_hwmon(int (*get)(void), char *buf)
{ \ { \
return store_sys_hwmon(_get, buf, count); \ return store_sys_hwmon(_get, buf, count); \
} \ } \
static SENSOR_DEVICE_ATTR(_name, _mode, show_##_name, store_##_name, 0); static DEVICE_ATTR(_name, _mode, show_##_name, store_##_name);
EEEPC_CREATE_SENSOR_ATTR(fan1_input, S_IRUGO, eeepc_get_fan_rpm, NULL); EEEPC_CREATE_SENSOR_ATTR(fan1_input, S_IRUGO, eeepc_get_fan_rpm, NULL);
EEEPC_CREATE_SENSOR_ATTR(pwm1, S_IRUGO | S_IWUSR, EEEPC_CREATE_SENSOR_ATTR(pwm1, S_IRUGO | S_IWUSR,
...@@ -1075,55 +1074,26 @@ EEEPC_CREATE_SENSOR_ATTR(pwm1, S_IRUGO | S_IWUSR, ...@@ -1075,55 +1074,26 @@ EEEPC_CREATE_SENSOR_ATTR(pwm1, S_IRUGO | S_IWUSR,
EEEPC_CREATE_SENSOR_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, EEEPC_CREATE_SENSOR_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
eeepc_get_fan_ctrl, eeepc_set_fan_ctrl); eeepc_get_fan_ctrl, eeepc_set_fan_ctrl);
static ssize_t static struct attribute *hwmon_attrs[] = {
show_name(struct device *dev, struct device_attribute *attr, char *buf) &dev_attr_pwm1.attr,
{ &dev_attr_fan1_input.attr,
return sprintf(buf, "eeepc\n"); &dev_attr_pwm1_enable.attr,
}
static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0);
static struct attribute *hwmon_attributes[] = {
&sensor_dev_attr_pwm1.dev_attr.attr,
&sensor_dev_attr_fan1_input.dev_attr.attr,
&sensor_dev_attr_pwm1_enable.dev_attr.attr,
&sensor_dev_attr_name.dev_attr.attr,
NULL NULL
}; };
ATTRIBUTE_GROUPS(hwmon);
static struct attribute_group hwmon_attribute_group = {
.attrs = hwmon_attributes
};
static void eeepc_hwmon_exit(struct eeepc_laptop *eeepc)
{
struct device *hwmon;
hwmon = eeepc->hwmon_device;
if (!hwmon)
return;
sysfs_remove_group(&hwmon->kobj,
&hwmon_attribute_group);
hwmon_device_unregister(hwmon);
eeepc->hwmon_device = NULL;
}
static int eeepc_hwmon_init(struct eeepc_laptop *eeepc) static int eeepc_hwmon_init(struct eeepc_laptop *eeepc)
{ {
struct device *dev = &eeepc->platform_device->dev;
struct device *hwmon; struct device *hwmon;
int result;
hwmon = hwmon_device_register(&eeepc->platform_device->dev); hwmon = devm_hwmon_device_register_with_groups(dev, "eeepc", NULL,
hwmon_groups);
if (IS_ERR(hwmon)) { if (IS_ERR(hwmon)) {
pr_err("Could not register eeepc hwmon device\n"); pr_err("Could not register eeepc hwmon device\n");
eeepc->hwmon_device = NULL;
return PTR_ERR(hwmon); return PTR_ERR(hwmon);
} }
eeepc->hwmon_device = hwmon; return 0;
result = sysfs_create_group(&hwmon->kobj,
&hwmon_attribute_group);
if (result)
eeepc_hwmon_exit(eeepc);
return result;
} }
/* /*
...@@ -1479,7 +1449,6 @@ static int eeepc_acpi_add(struct acpi_device *device) ...@@ -1479,7 +1449,6 @@ static int eeepc_acpi_add(struct acpi_device *device)
fail_rfkill: fail_rfkill:
eeepc_led_exit(eeepc); eeepc_led_exit(eeepc);
fail_led: fail_led:
eeepc_hwmon_exit(eeepc);
fail_hwmon: fail_hwmon:
eeepc_input_exit(eeepc); eeepc_input_exit(eeepc);
fail_input: fail_input:
...@@ -1499,7 +1468,6 @@ static int eeepc_acpi_remove(struct acpi_device *device) ...@@ -1499,7 +1468,6 @@ static int eeepc_acpi_remove(struct acpi_device *device)
eeepc_backlight_exit(eeepc); eeepc_backlight_exit(eeepc);
eeepc_rfkill_exit(eeepc); eeepc_rfkill_exit(eeepc);
eeepc_input_exit(eeepc); eeepc_input_exit(eeepc);
eeepc_hwmon_exit(eeepc);
eeepc_led_exit(eeepc); eeepc_led_exit(eeepc);
eeepc_platform_exit(eeepc); eeepc_platform_exit(eeepc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment