aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2013-11-23 14:03:17 -0500
committerMatthew Garrett <matthew.garrett@nebula.com>2014-01-21 08:44:03 -0500
commit50a639fb158c6aafe86ba7d6104de69518a9d09a (patch)
tree6a6899f5c654c8749737410ad75828b19ca8ad12
parentc2be45f09bb0b37ba1f87f39fbb04886f94e3e58 (diff)
asus-wmi: Convert to use devm_hwmon_device_register_with_groups
Simplify the code and avoid race conditions due to late sysfs attribute registration. Also replace SENSOR_DEVICE_ATTR with DEVICE_ATTR; the additional parameter is not used and thus unnecessary. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
-rw-r--r--drivers/platform/x86/asus-wmi.c48
1 files changed, 11 insertions, 37 deletions
diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index 19c313b056c3..e9e22a51e703 100644
--- a/drivers/platform/x86/asus-wmi.c
+++ b/drivers/platform/x86/asus-wmi.c
@@ -184,7 +184,6 @@ struct asus_wmi {
184 184
185 struct input_dev *inputdev; 185 struct input_dev *inputdev;
186 struct backlight_device *backlight_device; 186 struct backlight_device *backlight_device;
187 struct device *hwmon_device;
188 struct platform_device *platform_device; 187 struct platform_device *platform_device;
189 188
190 struct led_classdev wlan_led; 189 struct led_classdev wlan_led;
@@ -1071,20 +1070,12 @@ static ssize_t asus_hwmon_temp1(struct device *dev,
1071 return sprintf(buf, "%d\n", value); 1070 return sprintf(buf, "%d\n", value);
1072} 1071}
1073 1072
1074static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO, asus_hwmon_pwm1, NULL, 0); 1073static DEVICE_ATTR(pwm1, S_IRUGO, asus_hwmon_pwm1, NULL);
1075static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, asus_hwmon_temp1, NULL, 0); 1074static DEVICE_ATTR(temp1_input, S_IRUGO, asus_hwmon_temp1, NULL);
1076
1077static ssize_t
1078show_name(struct device *dev, struct device_attribute *attr, char *buf)
1079{
1080 return sprintf(buf, "asus\n");
1081}
1082static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0);
1083 1075
1084static struct attribute *hwmon_attributes[] = { 1076static struct attribute *hwmon_attributes[] = {
1085 &sensor_dev_attr_pwm1.dev_attr.attr, 1077 &dev_attr_pwm1.attr,
1086 &sensor_dev_attr_temp1_input.dev_attr.attr, 1078 &dev_attr_temp1_input.attr,
1087 &sensor_dev_attr_name.dev_attr.attr,
1088 NULL 1079 NULL
1089}; 1080};
1090 1081
@@ -1098,9 +1089,9 @@ static umode_t asus_hwmon_sysfs_is_visible(struct kobject *kobj,
1098 int dev_id = -1; 1089 int dev_id = -1;
1099 u32 value = ASUS_WMI_UNSUPPORTED_METHOD; 1090 u32 value = ASUS_WMI_UNSUPPORTED_METHOD;
1100 1091
1101 if (attr == &sensor_dev_attr_pwm1.dev_attr.attr) 1092 if (attr == &dev_attr_pwm1.attr)
1102 dev_id = ASUS_WMI_DEVID_FAN_CTRL; 1093 dev_id = ASUS_WMI_DEVID_FAN_CTRL;
1103 else if (attr == &sensor_dev_attr_temp1_input.dev_attr.attr) 1094 else if (attr == &dev_attr_temp1_input.attr)
1104 dev_id = ASUS_WMI_DEVID_THERMAL_CTRL; 1095 dev_id = ASUS_WMI_DEVID_THERMAL_CTRL;
1105 1096
1106 if (dev_id != -1) { 1097 if (dev_id != -1) {
@@ -1135,35 +1126,20 @@ static struct attribute_group hwmon_attribute_group = {
1135 .is_visible = asus_hwmon_sysfs_is_visible, 1126 .is_visible = asus_hwmon_sysfs_is_visible,
1136 .attrs = hwmon_attributes 1127 .attrs = hwmon_attributes
1137}; 1128};
1138 1129__ATTRIBUTE_GROUPS(hwmon_attribute);
1139static void asus_wmi_hwmon_exit(struct asus_wmi *asus)
1140{
1141 struct device *hwmon;
1142
1143 hwmon = asus->hwmon_device;
1144 if (!hwmon)
1145 return;
1146 sysfs_remove_group(&hwmon->kobj, &hwmon_attribute_group);
1147 hwmon_device_unregister(hwmon);
1148 asus->hwmon_device = NULL;
1149}
1150 1130
1151static int asus_wmi_hwmon_init(struct asus_wmi *asus) 1131static int asus_wmi_hwmon_init(struct asus_wmi *asus)
1152{ 1132{
1153 struct device *hwmon; 1133 struct device *hwmon;
1154 int result;
1155 1134
1156 hwmon = hwmon_device_register(&asus->platform_device->dev); 1135 hwmon = hwmon_device_register_with_groups(&asus->platform_device->dev,
1136 "asus", asus,
1137 hwmon_attribute_groups);
1157 if (IS_ERR(hwmon)) { 1138 if (IS_ERR(hwmon)) {
1158 pr_err("Could not register asus hwmon device\n"); 1139 pr_err("Could not register asus hwmon device\n");
1159 return PTR_ERR(hwmon); 1140 return PTR_ERR(hwmon);
1160 } 1141 }
1161 dev_set_drvdata(hwmon, asus); 1142 return 0;
1162 asus->hwmon_device = hwmon;
1163 result = sysfs_create_group(&hwmon->kobj, &hwmon_attribute_group);
1164 if (result)
1165 asus_wmi_hwmon_exit(asus);
1166 return result;
1167} 1143}
1168 1144
1169/* 1145/*
@@ -1834,7 +1810,6 @@ fail_backlight:
1834fail_rfkill: 1810fail_rfkill:
1835 asus_wmi_led_exit(asus); 1811 asus_wmi_led_exit(asus);
1836fail_leds: 1812fail_leds:
1837 asus_wmi_hwmon_exit(asus);
1838fail_hwmon: 1813fail_hwmon:
1839 asus_wmi_input_exit(asus); 1814 asus_wmi_input_exit(asus);
1840fail_input: 1815fail_input:
@@ -1852,7 +1827,6 @@ static int asus_wmi_remove(struct platform_device *device)
1852 wmi_remove_notify_handler(asus->driver->event_guid); 1827 wmi_remove_notify_handler(asus->driver->event_guid);
1853 asus_wmi_backlight_exit(asus); 1828 asus_wmi_backlight_exit(asus);
1854 asus_wmi_input_exit(asus); 1829 asus_wmi_input_exit(asus);
1855 asus_wmi_hwmon_exit(asus);
1856 asus_wmi_led_exit(asus); 1830 asus_wmi_led_exit(asus);
1857 asus_wmi_rfkill_exit(asus); 1831 asus_wmi_rfkill_exit(asus);
1858 asus_wmi_debugfs_exit(asus); 1832 asus_wmi_debugfs_exit(asus);