Skip to contentSkip to conversation

hwmon: acpi_power_meter: fix style issue

PATCH Superseded Corentin Labbe 3 participants 10 messages May 2, 2022 – May 4, 2022 Hardware monitoring

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 hwmon: acpi_power_meter: fix style issue

Fix style issues found by checkpatch.

---
 drivers/hwmon/acpi_power_meter.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/hwmon/acpi_power_meter.c +9 -8
index c405a5869581..d2545a1be9fc 100644
@@ -481,7 +481,7 @@ static struct sensor_template meter_attrs[] = {
 	RO_SENSOR_TEMPLATE("power1_average_interval_max", show_val, 1),
 	RO_SENSOR_TEMPLATE("power1_is_battery", show_val, 5),
 	RW_SENSOR_TEMPLATE(POWER_AVG_INTERVAL_NAME, show_avg_interval,
-		set_avg_interval, 0),
+			   set_avg_interval, 0),
 	{},
 };
 
@@ -530,6 +530,7 @@ static void remove_domain_devices(struct acpi_power_meter_resource *resource)
 
 	for (i = 0; i < resource->num_domain_devices; i++) {
 		struct acpi_device *obj = resource->domain_devices[i];
+
 		if (!obj)
 			continue;
 
@@ -580,7 +581,7 @@ static int read_domain_devices(struct acpi_power_meter_resource *resource)
 	}
 
 	resource->holders_dir = kobject_create_and_add("measures",
-					&resource->acpi_dev->dev.kobj);
+						       &resource->acpi_dev->dev.kobj);
 	if (!resource->holders_dir) {
 		res = -ENOMEM;
 		goto exit_free;
@@ -590,7 +591,7 @@ static int read_domain_devices(struct acpi_power_meter_resource *resource)
 
 	for (i = 0; i < pss->package.count; i++) {
 		struct acpi_device *obj;
-		union acpi_object *element = &(pss->package.elements[i]);
+		union acpi_object *element = &pss->package.elements[i];
 
 		/* Refuse non-references */
 		if (element->type != ACPI_TYPE_LOCAL_REFERENCE)
@@ -603,7 +604,7 @@ static int read_domain_devices(struct acpi_power_meter_resource *resource)
 			continue;
 
 		res = sysfs_create_link(resource->holders_dir, &obj->dev.kobj,
-				      kobject_name(&obj->dev.kobj));
+					kobject_name(&obj->dev.kobj));
 		if (res) {
 			acpi_dev_put(obj);
 			resource->domain_devices[i] = NULL;
@@ -788,7 +789,7 @@ static int read_capabilities(struct acpi_power_meter_resource *resource)
 	str = &resource->model_number;
 
 	for (i = 11; i < 14; i++) {
-		union acpi_object *element = &(pss->package.elements[i]);
+		union acpi_object *element = &pss->package.elements[i];
 
 		if (element->type != ACPI_TYPE_STRING) {
 			res = -EINVAL;
@@ -868,8 +869,7 @@ static int acpi_power_meter_add(struct acpi_device *device)
 	if (!device)
 		return -EINVAL;
 
-	resource = kzalloc(sizeof(struct acpi_power_meter_resource),
-			   GFP_KERNEL);
+	resource = kzalloc(sizeof(*resource), GFP_KERNEL);
 	if (!resource)
 		return -ENOMEM;
 
@@ -884,7 +884,8 @@ static int acpi_power_meter_add(struct acpi_device *device)
 	if (res)
 		goto exit_free;
 
-	resource->trip[0] = resource->trip[1] = -1;
+	resource->trip[0] = -1;
+	resource->trip[1] = -1;
 
 	res = setup_attrs(resource);
 	if (res)
Signature · 1 line
2.35.1
#1 lore raw

PATCH 2/2 hwmon: acpi_power_meter: convert to hwmon_device_register_with_info

Booting lead to a hwmon_device_register() is deprecated. Please convert the driver to use hwmon_device_register_with_info(). So let's convert the driver to use hwmon_device_register_with_info().

---
 drivers/hwmon/acpi_power_meter.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hwmon/acpi_power_meter.c +4 -1
index d2545a1be9fc..98293727f980 100644
@@ -891,7 +891,10 @@ static int acpi_power_meter_add(struct acpi_device *device)
 	if (res)
 		goto exit_free_capability;
 
-	resource->hwmon_dev = hwmon_device_register(&device->dev);
+	resource->hwmon_dev = hwmon_device_register_with_info(&device->dev,
+							      ACPI_POWER_METER_DEVICE_NAME,
+							      NULL, NULL,
+							      NULL);
 	if (IS_ERR(resource->hwmon_dev)) {
 		res = PTR_ERR(resource->hwmon_dev);
 		goto exit_remove;
Signature · 1 line
2.35.1
maintainer
#2 lore raw

Re: [PATCH 2/2] hwmon: acpi_power_meter: convert to hwmon_device_register_with_info

Quoted 13 lines · Corentin Labbe

Booting lead to a hwmon_device_register() is deprecated. Please convert the driver to use hwmon_device_register_with_info(). So let's convert the driver to use hwmon_device_register_with_info().

---
  drivers/hwmon/acpi_power_meter.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hwmon/acpi_power_meter.c +0 -0
index d2545a1be9fc..98293727f980 100644

drivers/hwmon/acpi_power_meter.c static int acpi_power_meter_add(struct acpi_device *device) · line 897

Quoted 8 lines
drivers/hwmon/acpi_power_meter.c +4 -1
@@ -891,7 +891,10 @@ static int acpi_power_meter_add(struct acpi_device *device)
  	if (res)
  		goto exit_free_capability;
 
-	resource->hwmon_dev = hwmon_device_register(&device->dev);
+	resource->hwmon_dev = hwmon_device_register_with_info(&device->dev,
+							      ACPI_POWER_METER_DEVICE_NAME,
+							      NULL, NULL,
+							      NULL);

NACK. That isn't a conversion to the new API, it just abuses the fact that the new API has to accept a NULL info pointer for historic reasons.

Guenter

#3 lore raw

Re: [PATCH 2/2] hwmon: acpi_power_meter: convert to hwmon_device_register_with_info

Quoted 17 lines · Guenter Roeck
Quoted 16 lines · Corentin Labbe

Booting lead to a hwmon_device_register() is deprecated. Please convert the driver to use hwmon_device_register_with_info(). So let's convert the driver to use hwmon_device_register_with_info().

---
  drivers/hwmon/acpi_power_meter.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hwmon/acpi_power_meter.c +0 -0
index d2545a1be9fc..98293727f980 100644
@@ -891,7 +891,10 @@ static int acpi_power_meter_add(struct acpi_device *device)
  	if (res)
  		goto exit_free_capability;
 
Quoted 9 lines

drivers/hwmon/acpi_power_meter.c static int acpi_power_meter_add(struct acpi_device *device) · line 897

Quoted 5 lines
drivers/hwmon/acpi_power_meter.c +4 -1
-	resource->hwmon_dev = hwmon_device_register(&device->dev);
+	resource->hwmon_dev = hwmon_device_register_with_info(&device->dev,
+							      ACPI_POWER_METER_DEVICE_NAME,
+							      NULL, NULL,
+							      NULL);

NACK. That isn't a conversion to the new API, it just abuses the fact that the new API has to accept a NULL info pointer for historic reasons.

Hello

I am sorry, I found a driver doing it, so I believed it was okay.
Converting seems not to hard but, by using the new API, how can I convert power1_model_number/power1_is_battery attribute ? There are the remaining attributes I dont find how to convert.

Regards

maintainer
#4 lore raw

Re: [PATCH 2/2] hwmon: acpi_power_meter: convert to hwmon_device_register_with_info

Quoted 28 lines · LABBE Corentin
Quoted 17 lines · Guenter Roeck
Quoted 16 lines · Corentin Labbe

Booting lead to a hwmon_device_register() is deprecated. Please convert the driver to use hwmon_device_register_with_info(). So let's convert the driver to use hwmon_device_register_with_info().

---
   drivers/hwmon/acpi_power_meter.c | 5 ++++-
   1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hwmon/acpi_power_meter.c +0 -0
index d2545a1be9fc..98293727f980 100644
@@ -891,7 +891,10 @@ static int acpi_power_meter_add(struct acpi_device *device)
   	if (res)
   		goto exit_free_capability;
 
Quoted 9 lines

drivers/hwmon/acpi_power_meter.c static int acpi_power_meter_add(struct acpi_device *device) · line 897

Quoted 5 lines
drivers/hwmon/acpi_power_meter.c +4 -1
-	resource->hwmon_dev = hwmon_device_register(&device->dev);
+	resource->hwmon_dev = hwmon_device_register_with_info(&device->dev,
+							      ACPI_POWER_METER_DEVICE_NAME,
+							      NULL, NULL,
+							      NULL);

NACK. That isn't a conversion to the new API, it just abuses the fact that the new API has to accept a NULL info pointer for historic reasons.

Quoted 3 lines

Hello

I am sorry, I found a driver doing it, so I believed it was okay.

Yeah, that is what happens if an API is flexible: It is prone to abuse, and once the abuse starts others start to abuse it as well "because that other driver did it".

Quoted 3 lines

Converting seems not to hard but, by using the new API, how can I convert power1_model_number/power1_is_battery attribute ? There are the remaining attributes I dont find how to convert.

It is ok to use the pointer to sysfs attribute groups for non-standard attributes.

Guenter

#5 lore raw

Re: [PATCH 2/2] hwmon: acpi_power_meter: convert to hwmon_device_register_with_info

In reply to LABBE Corentin

Am 02.05.22 um 20:59 schrieb LABBE Corentin:

Quoted 26 lines · Guenter Roeck
Quoted 17 lines · Corentin Labbe
Quoted 16 lines

Booting lead to a hwmon_device_register() is deprecated. Please convert the driver to use hwmon_device_register_with_info(). So let's convert the driver to use hwmon_device_register_with_info().

---
   drivers/hwmon/acpi_power_meter.c | 5 ++++-
   1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hwmon/acpi_power_meter.c +0 -0
index d2545a1be9fc..98293727f980 100644
@@ -891,7 +891,10 @@ static int acpi_power_meter_add(struct acpi_device *device)
   	if (res)
   		goto exit_free_capability;
 
Quoted 8 lines

drivers/hwmon/acpi_power_meter.c static int acpi_power_meter_add(struct acpi_device *device) · line 897

Quoted 5 lines
drivers/hwmon/acpi_power_meter.c +4 -1
-	resource->hwmon_dev = hwmon_device_register(&device->dev);
+	resource->hwmon_dev = hwmon_device_register_with_info(&device->dev,
+							      ACPI_POWER_METER_DEVICE_NAME,
+							      NULL, NULL,
+							      NULL);

NACK. That isn't a conversion to the new API, it just abuses the fact that the new API has to accept a NULL info pointer for historic reasons.

Quoted 7 lines

Hello

I am sorry, I found a driver doing it, so I believed it was okay.
Converting seems not to hard but, by using the new API, how can I convert power1_model_number/power1_is_battery attribute ? There are the remaining attributes I dont find how to convert.

Regards

Hi,

for allowing the driver to provide nonstandard attributes, hwmon_device_register_with_info() has the argument "extra_groups" which is an pointer to a list of sysfs attribute groups. There are some drivers which are using this functionality, maybe you can use them as an inspiration.

Just a question: what is the name of the driver you originally used as an inspiration?

Armin Wolf

maintainer
#6 lore raw

Re: [PATCH 2/2] hwmon: acpi_power_meter: convert to hwmon_device_register_with_info

Quoted 36 lines · Armin Wolf

Am 02.05.22 um 20:59 schrieb LABBE Corentin:

Quoted 26 lines · Guenter Roeck
Quoted 17 lines · Corentin Labbe
Quoted 16 lines

Booting lead to a hwmon_device_register() is deprecated. Please convert the driver to use hwmon_device_register_with_info(). So let's convert the driver to use hwmon_device_register_with_info().

---
   drivers/hwmon/acpi_power_meter.c | 5 ++++-

   1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hwmon/acpi_power_meter.c +0 -0
index d2545a1be9fc..98293727f980 100644
@@ -891,7 +891,10 @@ static int acpi_power_meter_add(struct acpi_device *device)
        if (res)
            goto exit_free_capability;
 
Quoted 8 lines

drivers/hwmon/acpi_power_meter.c static int acpi_power_meter_add(struct acpi_device *device) · line 897

Quoted 5 lines
drivers/hwmon/acpi_power_meter.c +4 -1
-    resource->hwmon_dev = hwmon_device_register(&device->dev);
+    resource->hwmon_dev = hwmon_device_register_with_info(&device->dev,
+                                  ACPI_POWER_METER_DEVICE_NAME,
+                                  NULL, NULL,
+                                  NULL);

NACK. That isn't a conversion to the new API, it just abuses the fact that the new API has to accept a NULL info pointer for historic reasons.

Quoted 7 lines

Hello

I am sorry, I found a driver doing it, so I believed it was okay.
Converting seems not to hard but, by using the new API, how can I convert power1_model_number/power1_is_battery attribute ? There are the remaining attributes I dont find how to convert.

Regards

Quoted 9 lines

Hi,

for allowing the driver to provide nonstandard attributes, hwmon_device_register_with_info() has the argument "extra_groups" which is an pointer to a list of sysfs attribute groups. There are some drivers which are using this functionality, maybe you can use them as an inspiration.

Just a question: what is the name of the driver you originally used as an inspiration?

Originally it was for drivers/thermal/thermal_hwmon.c. Now there is also drivers/platform/mips/cpu_hwmon.c which is clearly an abuse. I may have missed others.

Guenter

#7 lore raw

Re: [PATCH 2/2] hwmon: acpi_power_meter: convert to hwmon_device_register_with_info

Am 02.05.22 um 22:42 schrieb Guenter Roeck:

Quoted 57 lines · Armin Wolf
Quoted 52 lines

Am 02.05.22 um 20:59 schrieb LABBE Corentin:

Quoted 31 lines · Guenter Roeck
Quoted 20 lines · Corentin Labbe
Quoted 19 lines

Booting lead to a hwmon_device_register() is deprecated. Please convert the driver to use hwmon_device_register_with_info(). So let's convert the driver to use hwmon_device_register_with_info().

---
   drivers/hwmon/acpi_power_meter.c | 5 ++++-

   1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hwmon/acpi_power_meter.c +0 -0
index d2545a1be9fc..98293727f980 100644
@@ -891,7 +891,10 @@ static int acpi_power_meter_add(struct
 acpi_device *device)
        if (res)
            goto exit_free_capability;
 
Quoted 10 lines

drivers/hwmon/acpi_power_meter.c static int acpi_power_meter_add(struct acpi_device *device) · line 897

Quoted 6 lines
drivers/hwmon/acpi_power_meter.c +4 -1
-    resource->hwmon_dev = hwmon_device_register(&device->dev);
+    resource->hwmon_dev =
 hwmon_device_register_with_info(&device->dev,
+ ACPI_POWER_METER_DEVICE_NAME,
+                                  NULL, NULL,
+                                  NULL);

NACK. That isn't a conversion to the new API, it just abuses the fact that the new API has to accept a NULL info pointer for historic reasons.

Quoted 8 lines

Hello

I am sorry, I found a driver doing it, so I believed it was okay. Converting seems not to hard but, by using the new API, how can I convert power1_model_number/power1_is_battery attribute ? There are the remaining attributes I dont find how to convert.

Regards

Hi,

for allowing the driver to provide nonstandard attributes, hwmon_device_register_with_info()
has the argument "extra_groups" which is an pointer to a list of sysfs attribute groups.
There are some drivers which are using this functionality, maybe you can use them as an
inspiration.

Quoted 3 lines

Just a question: what is the name of the driver you originally used as an inspiration?

Quoted 5 lines

Originally it was for drivers/thermal/thermal_hwmon.c. Now there is also drivers/platform/mips/cpu_hwmon.c which is clearly an abuse. I may have missed others.

Guenter

Should we notify the maintainers of cpu_hwmon.c about that? This could potentially prevent such incidents from happening again.

Armin Wolf

maintainer
#8 lore raw

Re: [PATCH 2/2] hwmon: acpi_power_meter: convert to hwmon_device_register_with_info

Quoted 58 lines · Armin Wolf

Am 02.05.22 um 22:42 schrieb Guenter Roeck:

Quoted 57 lines · Armin Wolf
Quoted 55 lines

Am 02.05.22 um 20:59 schrieb LABBE Corentin:

Quoted 31 lines · Guenter Roeck
Quoted 20 lines · Corentin Labbe
Quoted 19 lines

Booting lead to a hwmon_device_register() is deprecated. Please convert the driver to use hwmon_device_register_with_info(). So let's convert the driver to use hwmon_device_register_with_info().

---
   drivers/hwmon/acpi_power_meter.c | 5 ++++-

   1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hwmon/acpi_power_meter.c +0 -0
index d2545a1be9fc..98293727f980 100644
@@ -891,7 +891,10 @@ static int acpi_power_meter_add(struct
 acpi_device *device)
        if (res)
            goto exit_free_capability;
 
Quoted 10 lines

drivers/hwmon/acpi_power_meter.c static int acpi_power_meter_add(struct acpi_device *device) · line 897

Quoted 6 lines
drivers/hwmon/acpi_power_meter.c +4 -1
-    resource->hwmon_dev = hwmon_device_register(&device->dev);
+    resource->hwmon_dev =
 hwmon_device_register_with_info(&device->dev,
+ ACPI_POWER_METER_DEVICE_NAME,
+                                  NULL, NULL,
+                                  NULL);

NACK. That isn't a conversion to the new API, it just abuses the fact that the new API has to accept a NULL info pointer for historic reasons.

Quoted 8 lines

Hello

I am sorry, I found a driver doing it, so I believed it was okay. Converting seems not to hard but, by using the new API, how can I convert power1_model_number/power1_is_battery attribute ? There are the remaining attributes I dont find how to convert.

Regards

Hi,

for allowing the driver to provide nonstandard attributes, hwmon_device_register_with_info()
has the argument "extra_groups" which is an pointer to a list of sysfs attribute groups.
There are some drivers which are using this functionality, maybe you can use them as an
inspiration.

Just a question: what is the name of the driver you originally used as an inspiration?

Quoted 8 lines
Quoted 5 lines

Originally it was for drivers/thermal/thermal_hwmon.c. Now there is also drivers/platform/mips/cpu_hwmon.c which is clearly an abuse. I may have missed others.

Guenter

Should we notify the maintainers of cpu_hwmon.c about that? This could potentially prevent such incidents from happening again.

I am more inclined to create a special API for thermal, call it from the thermal code, and issue a warning with backtrace if anyone else calls hwmon_device_register_with_info() with NULL info pointer. And explain all that in detail in the API documentation.

Guenter

#9 lore raw

Re: [PATCH 2/2] hwmon: acpi_power_meter: convert to hwmon_device_register_with_info

Am 03.05.22 um 01:43 schrieb Guenter Roeck:

Quoted 71 lines · Armin Wolf
Quoted 60 lines

Am 02.05.22 um 22:42 schrieb Guenter Roeck:

Quoted 59 lines · Armin Wolf
Quoted 57 lines

Am 02.05.22 um 20:59 schrieb LABBE Corentin:

Quoted 33 lines · Guenter Roeck
Quoted 21 lines · Corentin Labbe
Quoted 20 lines

Booting lead to a hwmon_device_register() is deprecated. Please convert the driver to use hwmon_device_register_with_info(). So let's convert the driver to use hwmon_device_register_with_info().

---
   drivers/hwmon/acpi_power_meter.c | 5 ++++-

   1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hwmon/acpi_power_meter.c +0 -0
index d2545a1be9fc..98293727f980 100644
@@ -891,7 +891,10 @@ static int acpi_power_meter_add(struct
 acpi_device *device)
        if (res)
            goto exit_free_capability;
 
Quoted 11 lines

drivers/hwmon/acpi_power_meter.c static int acpi_power_meter_add(struct · line 899

Quoted 6 lines
drivers/hwmon/acpi_power_meter.c +4 -1
-    resource->hwmon_dev = hwmon_device_register(&device->dev);
+    resource->hwmon_dev =
 hwmon_device_register_with_info(&device->dev,
+ ACPI_POWER_METER_DEVICE_NAME,
+                                  NULL, NULL,
+                                  NULL);

NACK. That isn't a conversion to the new API, it just abuses the fact
that the new API has to accept a NULL info pointer for historic reasons.

Quoted 8 lines

Hello

I am sorry, I found a driver doing it, so I believed it was okay. Converting seems not to hard but, by using the new API, how can I convert power1_model_number/power1_is_battery attribute ? There are the remaining attributes I dont find how to convert.

Regards

Hi,

for allowing the driver to provide nonstandard attributes, hwmon_device_register_with_info()
has the argument "extra_groups" which is an pointer to a list of sysfs attribute groups.
There are some drivers which are using this functionality, maybe you can use them as an
inspiration.

Just a question: what is the name of the driver you originally used as an inspiration?

Quoted 9 lines
Quoted 6 lines

Originally it was for drivers/thermal/thermal_hwmon.c. Now there is also
drivers/platform/mips/cpu_hwmon.c which is clearly an abuse. I may have missed others.

Guenter

Should we notify the maintainers of cpu_hwmon.c about that? This could potentially prevent such incidents from happening again.

Quoted 6 lines

I am more inclined to create a special API for thermal, call it from the thermal code, and issue a warning with backtrace if anyone else calls hwmon_device_register_with_info() with NULL info pointer. And explain all that in detail in the API documentation.

Guenter

Sounds good.

Armin Wolf