Skip to contentSkip to conversation

platform/x86: dasharo-acpi: Fix a couple off by one bugs

PATCH In review Dan Carpenter 2 participants 2 messages May 7, 2025 – May 8, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/x86: dasharo-acpi: Fix a couple off by one bugs

These two > comparisons should be >= to prevent reading beyond the end of the array.

Fixes 2dd40523b7e2 ("platform/x86: Introduce dasharo-acpi platform driver")
---
 drivers/platform/x86/dasharo-acpi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/dasharo-acpi.c +2 -2
index f10f52e44641..f0c5136af29d 100644
@@ -101,10 +101,10 @@ static int dasharo_read_channel(struct dasharo_data *data, char *method, enum da
 	acpi_status status;
 	u64 val;
 
-	if (feat > ARRAY_SIZE(data->capabilities))
+	if (feat >= ARRAY_SIZE(data->capabilities))
 		return -EINVAL;
 
-	if (channel > data->caps_found[feat])
+	if (channel >= data->caps_found[feat])
 		return -EINVAL;
 
 	obj[0].type = ACPI_TYPE_INTEGER;
Signature · 1 line
2.47.2
maintainer
#1 lore raw
Quoted 17 lines · Dan Carpenter

These two > comparisons should be >= to prevent reading beyond the end of the array.

Fixes 2dd40523b7e2 ("platform/x86: Introduce dasharo-acpi platform driver")
---
 drivers/platform/x86/dasharo-acpi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/dasharo-acpi.c +0 -0
index f10f52e44641..f0c5136af29d 100644
@@ -101,10 +101,10 @@ static int dasharo_read_channel(struct dasharo_data *data, char *method, enum da
 	acpi_status status;
 	u64 val;

drivers/platform/x86/dasharo-acpi.c static int dasharo_read_channel(struct dasharo_data *data, char *method, enum da · line 110

Quoted 10 lines
drivers/platform/x86/dasharo-acpi.c +2 -2
 
-	if (feat > ARRAY_SIZE(data->capabilities))
+	if (feat >= ARRAY_SIZE(data->capabilities))
 		return -EINVAL;
 
-	if (channel > data->caps_found[feat])
+	if (channel >= data->caps_found[feat])
 		return -EINVAL;
 
 	obj[0].type = ACPI_TYPE_INTEGER;

Thanks Dan, I've folded this into the original commit as I was rewriting history anyway due to some other fixes.

Signature · 1 line
 i.