aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2013-11-23 14:03:21 -0500
committerMatthew Garrett <matthew.garrett@nebula.com>2014-01-21 08:44:03 -0500
commitf0c34c97b3193fee87a3942047c415d476615db1 (patch)
tree7c4eabb96a4263fa402eebeb7a01c80ce4cc10fe
parentcf508f4496f7dc7c162a8ac4440165d466f68d4b (diff)
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: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
-rw-r--r--drivers/platform/x86/eeepc-laptop.c52
1 files changed, 10 insertions, 42 deletions
diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
index dec68e7a99c7..b2ef152297c9 100644
--- a/drivers/platform/x86/eeepc-laptop.c
+++ b/drivers/platform/x86/eeepc-laptop.c
@@ -166,7 +166,6 @@ struct eeepc_laptop {
166 166
167 struct platform_device *platform_device; 167 struct platform_device *platform_device;
168 struct acpi_device *device; /* the device we are in */ 168 struct acpi_device *device; /* the device we are in */
169 struct device *hwmon_device;
170 struct backlight_device *backlight_device; 169 struct backlight_device *backlight_device;
171 170
172 struct input_dev *inputdev; 171 struct input_dev *inputdev;
@@ -1067,7 +1066,7 @@ static ssize_t show_sys_hwmon(int (*get)(void), char *buf)
1067 { \ 1066 { \
1068 return store_sys_hwmon(_get, buf, count); \ 1067 return store_sys_hwmon(_get, buf, count); \
1069 } \ 1068 } \
1070 static SENSOR_DEVICE_ATTR(_name, _mode, show_##_name, store_##_name, 0); 1069 static DEVICE_ATTR(_name, _mode, show_##_name, store_##_name);
1071 1070
1072EEEPC_CREATE_SENSOR_ATTR(fan1_input, S_IRUGO, eeepc_get_fan_rpm, NULL); 1071EEEPC_CREATE_SENSOR_ATTR(fan1_input, S_IRUGO, eeepc_get_fan_rpm, NULL);
1073EEEPC_CREATE_SENSOR_ATTR(pwm1, S_IRUGO | S_IWUSR, 1072EEEPC_CREATE_SENSOR_ATTR(pwm1, S_IRUGO | S_IWUSR,
@@ -1075,55 +1074,26 @@ EEEPC_CREATE_SENSOR_ATTR(pwm1, S_IRUGO | S_IWUSR,
1075EEEPC_CREATE_SENSOR_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, 1074EEEPC_CREATE_SENSOR_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
1076 eeepc_get_fan_ctrl, eeepc_set_fan_ctrl); 1075 eeepc_get_fan_ctrl, eeepc_set_fan_ctrl);
1077 1076
1078static ssize_t 1077static struct attribute *hwmon_attrs[] = {
1079show_name(struct device *dev, struct device_attribute *attr, char *buf) 1078 &dev_attr_pwm1.attr,
1080{ 1079 &dev_attr_fan1_input.attr,
1081 return sprintf(buf, "eeepc\n"); 1080 &dev_attr_pwm1_enable.attr,
1082}
1083static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0);
1084
1085static struct attribute *hwmon_attributes[] = {
1086 &sensor_dev_attr_pwm1.dev_attr.attr,
1087 &sensor_dev_attr_fan1_input.dev_attr.attr,
1088 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
1089 &sensor_dev_attr_name.dev_attr.attr,
1090 NULL 1081 NULL
1091}; 1082};
1092 1083ATTRIBUTE_GROUPS(hwmon);
1093static struct attribute_group hwmon_attribute_group = {
1094 .attrs = hwmon_attributes
1095};
1096
1097static void eeepc_hwmon_exit(struct eeepc_laptop *eeepc)
1098{
1099 struct device *hwmon;
1100
1101 hwmon = eeepc->hwmon_device;
1102 if (!hwmon)
1103 return;
1104 sysfs_remove_group(&hwmon->kobj,
1105 &hwmon_attribute_group);
1106 hwmon_device_unregister(hwmon);
1107 eeepc->hwmon_device = NULL;
1108}
1109 1084
1110static int eeepc_hwmon_init(struct eeepc_laptop *eeepc) 1085static int eeepc_hwmon_init(struct eeepc_laptop *eeepc)
1111{ 1086{
1087 struct device *dev = &eeepc->platform_device->dev;
1112 struct device *hwmon; 1088 struct device *hwmon;
1113 int result;
1114 1089
1115 hwmon = hwmon_device_register(&eeepc->platform_device->dev); 1090 hwmon = devm_hwmon_device_register_with_groups(dev, "eeepc", NULL,
1091 hwmon_groups);
1116 if (IS_ERR(hwmon)) { 1092 if (IS_ERR(hwmon)) {
1117 pr_err("Could not register eeepc hwmon device\n"); 1093 pr_err("Could not register eeepc hwmon device\n");
1118 eeepc->hwmon_device = NULL;
1119 return PTR_ERR(hwmon); 1094 return PTR_ERR(hwmon);
1120 } 1095 }
1121 eeepc->hwmon_device = hwmon; 1096 return 0;
1122 result = sysfs_create_group(&hwmon->kobj,
1123 &hwmon_attribute_group);
1124 if (result)
1125 eeepc_hwmon_exit(eeepc);
1126 return result;
1127} 1097}
1128 1098
1129/* 1099/*
@@ -1479,7 +1449,6 @@ static int eeepc_acpi_add(struct acpi_device *device)
1479fail_rfkill: 1449fail_rfkill:
1480 eeepc_led_exit(eeepc); 1450 eeepc_led_exit(eeepc);
1481fail_led: 1451fail_led:
1482 eeepc_hwmon_exit(eeepc);
1483fail_hwmon: 1452fail_hwmon:
1484 eeepc_input_exit(eeepc); 1453 eeepc_input_exit(eeepc);
1485fail_input: 1454fail_input:
@@ -1499,7 +1468,6 @@ static int eeepc_acpi_remove(struct acpi_device *device)
1499 eeepc_backlight_exit(eeepc); 1468 eeepc_backlight_exit(eeepc);
1500 eeepc_rfkill_exit(eeepc); 1469 eeepc_rfkill_exit(eeepc);
1501 eeepc_input_exit(eeepc); 1470 eeepc_input_exit(eeepc);
1502 eeepc_hwmon_exit(eeepc);
1503 eeepc_led_exit(eeepc); 1471 eeepc_led_exit(eeepc);
1504 eeepc_platform_exit(eeepc); 1472 eeepc_platform_exit(eeepc);
1505 1473