[PATCH] hwmon: acpi_power_meter: replace deprecated strcpy() with strscpy()

Yacov Simhony posted 1 patch 8 months, 1 week ago
drivers/hwmon/acpi_power_meter.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
[PATCH] hwmon: acpi_power_meter: replace deprecated strcpy() with strscpy()
Posted by Yacov Simhony 8 months, 1 week ago
Use strscpy() instead of strcpy() to prevent potential buffer overflows
in acpi_device_name() and acpi_device_class(), which point to fixed-size
buffers.

This change improves safety and aligns with current kernel cleanup efforts.

Signed-off-by: Yacov Simhony <ysimhony@gmail.com>
---
 drivers/hwmon/acpi_power_meter.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
index 29ccdc2fb..a64497ddb 100644
--- a/drivers/hwmon/acpi_power_meter.c
+++ b/drivers/hwmon/acpi_power_meter.c
@@ -890,8 +890,12 @@ static int acpi_power_meter_add(struct acpi_device *device)
 	resource->sensors_valid = 0;
 	resource->acpi_dev = device;
 	mutex_init(&resource->lock);
-	strcpy(acpi_device_name(device), ACPI_POWER_METER_DEVICE_NAME);
-	strcpy(acpi_device_class(device), ACPI_POWER_METER_CLASS);
+	strscpy(acpi_device_name(device), 
+		ACPI_POWER_METER_DEVICE_NAME,
+	        MAX_ACPI_DEVICE_NAME_LEN);
+	strscpy(acpi_device_class(device), 
+		ACPI_POWER_METER_CLASS,
+		MAX_ACPI_CLASS_NAME_LEN);
 	device->driver_data = resource;
 
 #if IS_REACHABLE(CONFIG_ACPI_IPMI)
-- 
2.47.0
Re: [PATCH] hwmon: acpi_power_meter: replace deprecated strcpy() with strscpy()
Posted by Guenter Roeck 8 months, 1 week ago
On 4/14/25 15:01, Yacov Simhony wrote:
> Use strscpy() instead of strcpy() to prevent potential buffer overflows
> in acpi_device_name() and acpi_device_class(), which point to fixed-size
> buffers.
> 
> This change improves safety and aligns with current kernel cleanup efforts.

ACPI_POWER_METER_DEVICE_NAME and ACPI_POWER_METER_CLASS are constant strings.
There is no danger of buffer overflows. There is no safety improvement.

We should concentrate on fixing real problems, not imaginary ones.

Guenter