[PATCH] hwmon: acpi_power_meter: replace deprecated strcpy() with strscpy()
From: Yacov Simhony
Date: Mon Apr 14 2025 - 18:02:02 EST
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@xxxxxxxxx>
---
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