Skip to contentSkip to conversation

thinkpad_acpi: revert unintentional device attribute renaming

PATCH Superseded Bjørn Mork 3 participants 4 messages May 19, 2015 1 message not in the archive x86 platform drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thinkpad_acpi: revert unintentional device attribute renaming

The conversion to DEVICE_ATTR_* macros failed to fixup a few cases where the old attribute names didn't match the show/store function names. Instead of renaming the functions, the attributes were renamed. This caused an unintentional API change. The hwmon required 'name' attribute were among the renamed attribute, causing libsensors to fail to detect the hwmon device at all.

Fixes b4dd04ac6ef8 ("thinkpad_acpi: use DEVICE_ATTR_* macros")
Cc Bastien Nocera <[email protected]>
Cc Henrique de Moraes Holschuh <[email protected]>
---
 drivers/platform/x86/thinkpad_acpi.c | 84 ++++++++++++++++++------------------
 1 file changed, 41 insertions(+), 43 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +41 -43
index 9bb9ad6d4a1b..6db64531d8b4 100644
@@ -2890,14 +2890,14 @@ static void hotkey_tablet_mode_notify_change(void)
 }
 
 /* sysfs wakeup reason (pollable) -------------------------------------- */
-static ssize_t hotkey_wakeup_reason_show(struct device *dev,
+static ssize_t wakeup_reason_show(struct device *dev,
 			   struct device_attribute *attr,
 			   char *buf)
 {
 	return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason);
 }
 
-static DEVICE_ATTR_RO(hotkey_wakeup_reason);
+static DEVICE_ATTR_RO(wakeup_reason);
 
 static void hotkey_wakeup_reason_notify_change(void)
 {
@@ -2906,14 +2906,14 @@ static void hotkey_wakeup_reason_notify_change(void)
 }
 
 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
-static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev,
+static ssize_t wakeup_hotunplug_complete_show(struct device *dev,
 			   struct device_attribute *attr,
 			   char *buf)
 {
 	return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack);
 }
 
-static DEVICE_ATTR_RO(hotkey_wakeup_hotunplug_complete);
+static DEVICE_ATTR_RO(wakeup_hotunplug_complete);
 
 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
 {
@@ -2978,8 +2978,8 @@ static struct attribute *hotkey_attributes[] __initdata = {
 	&dev_attr_hotkey_enable.attr,
 	&dev_attr_hotkey_bios_enabled.attr,
 	&dev_attr_hotkey_bios_mask.attr,
-	&dev_attr_hotkey_wakeup_reason.attr,
-	&dev_attr_hotkey_wakeup_hotunplug_complete.attr,
+	&dev_attr_wakeup_reason.attr,
+	&dev_attr_wakeup_hotunplug_complete.attr,
 	&dev_attr_hotkey_mask.attr,
 	&dev_attr_hotkey_all_mask.attr,
 	&dev_attr_hotkey_recommended_mask.attr,
@@ -4377,7 +4377,7 @@ static int wan_set_status(enum tpacpi_rfkill_state state)
 }
 
 /* sysfs wan enable ---------------------------------------------------- */
-static ssize_t wan_enable_show(struct device *dev,
+static ssize_t wwan_enable_show(struct device *dev,
 			   struct device_attribute *attr,
 			   char *buf)
 {
@@ -4385,7 +4385,7 @@ static ssize_t wan_enable_show(struct device *dev,
 			attr, buf);
 }
 
-static ssize_t wan_enable_store(struct device *dev,
+static ssize_t wwan_enable_store(struct device *dev,
 			    struct device_attribute *attr,
 			    const char *buf, size_t count)
 {
@@ -4393,12 +4393,12 @@ static ssize_t wan_enable_store(struct device *dev,
 			attr, buf, count);
 }
 
-static DEVICE_ATTR_RW(wan_enable);
+static DEVICE_ATTR_RW(wwan_enable);
 
 /* --------------------------------------------------------------------- */
 
 static struct attribute *wan_attributes[] = {
-	&dev_attr_wan_enable.attr,
+	&dev_attr_wwan_enable.attr,
 	NULL
 };
 
@@ -8076,9 +8076,9 @@ static void fan_watchdog_fire(struct work_struct *ignored)
  */
 
 /* sysfs fan pwm1_enable ----------------------------------------------- */
-static ssize_t fan_pwm1_enable_show(struct device *dev,
-				    struct device_attribute *attr,
-				    char *buf)
+static ssize_t pwm1_enable_show(struct device *dev,
+				struct device_attribute *attr,
+				char *buf)
 {
 	int res, mode;
 	u8 status;
@@ -8097,9 +8097,9 @@ static ssize_t fan_pwm1_enable_show(struct device *dev,
 	return snprintf(buf, PAGE_SIZE, "%d\n", mode);
 }
 
-static ssize_t fan_pwm1_enable_store(struct device *dev,
-				     struct device_attribute *attr,
-				     const char *buf, size_t count)
+static ssize_t pwm1_enable_store(struct device *dev,
+				 struct device_attribute *attr,
+				 const char *buf, size_t count)
 {
 	unsigned long t;
 	int res, level;
@@ -8138,12 +8138,12 @@ static ssize_t fan_pwm1_enable_store(struct device *dev,
 	return count;
 }
 
-static DEVICE_ATTR_RW(fan_pwm1_enable);
+static DEVICE_ATTR_RW(pwm1_enable);
 
 /* sysfs fan pwm1 ------------------------------------------------------ */
-static ssize_t fan_pwm1_show(struct device *dev,
-			     struct device_attribute *attr,
-			     char *buf)
+static ssize_t pwm1_show(struct device *dev,
+			 struct device_attribute *attr,
+			 char *buf)
 {
 	int res;
 	u8 status;
@@ -8162,9 +8162,9 @@ static ssize_t fan_pwm1_show(struct device *dev,
 	return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7);
 }
 
-static ssize_t fan_pwm1_store(struct device *dev,
-			      struct device_attribute *attr,
-			      const char *buf, size_t count)
+static ssize_t pwm1_store(struct device *dev,
+			  struct device_attribute *attr,
+			  const char *buf, size_t count)
 {
 	unsigned long s;
 	int rc;
@@ -8198,12 +8198,12 @@ static ssize_t fan_pwm1_store(struct device *dev,
 	return (rc) ? rc : count;
 }
 
-static DEVICE_ATTR_RW(fan_pwm1);
+static DEVICE_ATTR_RW(pwm1);
 
 /* sysfs fan fan1_input ------------------------------------------------ */
-static ssize_t fan_fan1_input_show(struct device *dev,
-			   struct device_attribute *attr,
-			   char *buf)
+static ssize_t fan1_input_show(struct device *dev,
+			       struct device_attribute *attr,
+			       char *buf)
 {
 	int res;
 	unsigned int speed;
@@ -8215,12 +8215,12 @@ static ssize_t fan_fan1_input_show(struct device *dev,
 	return snprintf(buf, PAGE_SIZE, "%u\n", speed);
 }
 
-static DEVICE_ATTR_RO(fan_fan1_input);
+static DEVICE_ATTR_RO(fan1_input);
 
 /* sysfs fan fan2_input ------------------------------------------------ */
-static ssize_t fan_fan2_input_show(struct device *dev,
-			   struct device_attribute *attr,
-			   char *buf)
+static ssize_t fan2_input_show(struct device *dev,
+			       struct device_attribute *attr,
+			       char *buf)
 {
 	int res;
 	unsigned int speed;
@@ -8232,7 +8232,7 @@ static ssize_t fan_fan2_input_show(struct device *dev,
 	return snprintf(buf, PAGE_SIZE, "%u\n", speed);
 }
 
-static DEVICE_ATTR_RO(fan_fan2_input);
+static DEVICE_ATTR_RO(fan2_input);
 
 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
 static ssize_t fan_fan_watchdog_show(struct device_driver *drv,
@@ -8265,8 +8265,8 @@ static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO,
 
 /* --------------------------------------------------------------------- */
 static struct attribute *fan_attributes[] = {
-	&dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr,
-	&dev_attr_fan_fan1_input.attr,
+	&dev_attr_pwm1_enable.attr, &dev_attr_pwm1.attr,
+	&dev_attr_fan1_input.attr,
 	NULL, /* for fan2_input */
 	NULL
 };
@@ -8400,7 +8400,7 @@ static int __init fan_init(struct ibm_init_struct *iibm)
 		if (tp_features.second_fan) {
 			/* attach second fan tachometer */
 			fan_attributes[ARRAY_SIZE(fan_attributes)-2] =
-					&dev_attr_fan_fan2_input.attr;
+					&dev_attr_fan2_input.attr;
 		}
 		rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj,
 					 &fan_attr_group);
@@ -8841,14 +8841,14 @@ static void hotkey_driver_event(const unsigned int scancode)
 }
 
 /* sysfs name ---------------------------------------------------------- */
-static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev,
-			   struct device_attribute *attr,
-			   char *buf)
+static ssize_t name_show(struct device *dev,
+			 struct device_attribute *attr,
+			 char *buf)
 {
 	return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME);
 }
 
-static DEVICE_ATTR_RO(thinkpad_acpi_pdev_name);
+static DEVICE_ATTR_RO(name);
 
 /* --------------------------------------------------------------------- */
 
@@ -9390,8 +9390,7 @@ static void thinkpad_acpi_module_exit(void)
 		hwmon_device_unregister(tpacpi_hwmon);
 
 	if (tp_features.sensors_pdev_attrs_registered)
-		device_remove_file(&tpacpi_sensors_pdev->dev,
-				   &dev_attr_thinkpad_acpi_pdev_name);
+		device_remove_file(&tpacpi_sensors_pdev->dev, &dev_attr_name);
 	if (tpacpi_sensors_pdev)
 		platform_device_unregister(tpacpi_sensors_pdev);
 	if (tpacpi_pdev)
@@ -9512,8 +9511,7 @@ static int __init thinkpad_acpi_module_init(void)
 		thinkpad_acpi_module_exit();
 		return ret;
 	}
-	ret = device_create_file(&tpacpi_sensors_pdev->dev,
-				 &dev_attr_thinkpad_acpi_pdev_name);
+	ret = device_create_file(&tpacpi_sensors_pdev->dev, &dev_attr_name);
 	if (ret) {
 		pr_err("unable to create sysfs hwmon device attributes\n");
 		thinkpad_acpi_module_exit();
Signature · 1 line
2.1.4
#1 lore raw
Quoted 11 lines · Bjørn Mork

The conversion to DEVICE_ATTR_* macros failed to fixup a few cases where the old attribute names didn't match the show/store function names. Instead of renaming the functions, the attributes were renamed. This caused an unintentional API change. The hwmon required 'name' attribute were among the renamed attribute, causing libsensors to fail to detect the hwmon device at all.

Fixes b4dd04ac6ef8 ("thinkpad_acpi: use DEVICE_ATTR_* macros")
Cc Bastien Nocera <[email protected]>
Cc Henrique de Moraes Holschuh <[email protected]>

...

drivers/platform/x86/thinkpad_acpi.c static void hotkey_tablet_mode_notify_change(void) · line 2893

Quoted 2 lines
drivers/platform/x86/thinkpad_acpi.c +1 -1
-static ssize_t hotkey_wakeup_reason_show(struct device *dev,
+static ssize_t wakeup_reason_show(struct device *dev,

Before, all "hotkey subdriver" functions had the hotkey_ prefix. Now, we have to intrude into whatever "namespace" an attribute name happens to clash (in this case, the "wakeup" namespace).

If this is the least horrible way to fix the issue, I will ack it even if I don't like it. However, if there's a way to do it that would keep the "hotkey_" prefix in the C side, and only change the rest of the C function name (if required), I'd rather the fix did that.

Also, the fix needs to go to stable (4.0+).

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh

A message that is not in the archive (sent off-list or not yet received): 1432048439.3106362.272800449.45A5D8AC-2RFepEojUI2N1INw9kWLP6GC3tUn3ZHUQQ4Iyu8u01E@public.gmane.org

#3 lore raw
Quoted 22 lines · Henrique de Moraes Holschuh
Quoted 11 lines · Bjørn Mork

The conversion to DEVICE_ATTR_* macros failed to fixup a few cases where the old attribute names didn't match the show/store function names. Instead of renaming the functions, the attributes were renamed. This caused an unintentional API change. The hwmon required 'name' attribute were among the renamed attribute, causing libsensors to fail to detect the hwmon device at all.

Fixes b4dd04ac6ef8 ("thinkpad_acpi: use DEVICE_ATTR_* macros")
Cc Bastien Nocera <[email protected]>
Cc Henrique de Moraes Holschuh <[email protected]>

...

drivers/platform/x86/thinkpad_acpi.c static void hotkey_tablet_mode_notify_change(void) · line 2893

Quoted 2 lines
drivers/platform/x86/thinkpad_acpi.c +1 -1
-static ssize_t hotkey_wakeup_reason_show(struct device *dev,
+static ssize_t wakeup_reason_show(struct device *dev,

Before, all "hotkey subdriver" functions had the hotkey_ prefix. Now, we have to intrude into whatever "namespace" an attribute name happens to clash (in this case, the "wakeup" namespace).

Quoted 4 lines

If this is the least horrible way to fix the issue, I will ack it even if I don't like it. However, if there's a way to do it that would keep the "hotkey_" prefix in the C side, and only change the rest of the C function name (if required), I'd rather the fix did that.

We could use the DEVICE_ATTR(_name, _mode, _show, _store) macro instead for the affected attributes if you prefer that.

I didn't think the names of these static functions mattered that much, but I do see that yout have a point for a 10kloc source file like thinkpad_acpi.c. You haven't ever considered splitting it? :-)

Quoted 1 line

Also, the fix needs to go to stable (4.0+).

I don't think so. The bug was introduced in v4.1-rc1 AFAICS. Am I missing something?

Bjørn

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
ibm-acpi-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/ibm-acpi-devel

#4 lore raw
Quoted 8 lines · Bjørn Mork
Quoted 7 lines · Henrique de Moraes Holschuh

drivers/platform/x86/thinkpad_acpi.c static void hotkey_tablet_mode_notify_change(void) · line 2893

Quoted 2 lines
drivers/platform/x86/thinkpad_acpi.c +1 -1
-static ssize_t hotkey_wakeup_reason_show(struct device *dev,
+static ssize_t wakeup_reason_show(struct device *dev,

Before, all "hotkey subdriver" functions had the hotkey_ prefix. Now, we have to intrude into whatever "namespace" an attribute name happens to clash (in this case, the "wakeup" namespace).

Quoted 7 lines
Quoted 4 lines

If this is the least horrible way to fix the issue, I will ack it even if I don't like it. However, if there's a way to do it that would keep the "hotkey_" prefix in the C side, and only change the rest of the C function name (if required), I'd rather the fix did that.

We could use the DEVICE_ATTR(_name, _mode, _show, _store) macro instead for the affected attributes if you prefer that.

Yes, please. I'd rather have a bit more boilerplate than sacrifice the "subdriver prefix" in the C functions handling the sysfs nodes.

Quoted 3 lines

I didn't think the names of these static functions mattered that much, but I do see that yout have a point for a 10kloc source file like thinkpad_acpi.c. You haven't ever considered splitting it? :-)

Heh, yeah, I did. I was going to at least kick the hwmon and the alsa-related stuff to separate drivers. But there are all sorts of ties between the separate functionalities due to a common firmware event interface, so the result looked worse than the monolithic driver. And we often get more of those when new firmware/hardware functionality arrives...

A split-and-refactor might be in thinkpad-acpi's future, yes. But the result would not be a bunch of independent modules due to the way the firmware interface works, so there is little reason to not have it as a monolitic module. This is not something you'd have in an embedded kernel, after all...

Those 10k loc are mostly organized into highly modular blocks ("subdrivers"), thus my dislike for the change on the C function prefixes for the sysfs attributes. Those prefixes make it easier to maintain the driver ;-)

When I last tried it several years ago, splitting the large C file into several smaller C files did not make that large a difference in maintainability, for a noticeable cost in lost compile-time optimizations. So, I never published it.

Quoted 4 lines
Quoted 1 line

Also, the fix needs to go to stable (4.0+).

I don't think so. The bug was introduced in v4.1-rc1 AFAICS. Am I missing something?

Hmm, I screwed up when I was trying to locate which trees shipped the broken commit. You're right, this fix does _not_ need to go to stable. Sorry about that!

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh