Skip to contentSkip to conversation

platform/loongarch: laptop: Reject negative max brightness values

PATCH In review Thorsten Blum 1 participant 2 messages Nov 27 LoongArch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/loongarch: laptop: Reject negative max brightness values

laptop_backlight_register() uses the maximum brightness reported by the ECLL ACPI method without validating it. A negative result could cause the driver to register a backlight with an invalid brightness range.

Return -EINVAL for negative values before powering on and registering the backlight.

Fixes 6246ed09111f ("LoongArch: Add ACPI-based generic laptop driver")

---
Found by code inspection and compile-tested only.

 drivers/platform/loongarch/loongson-laptop.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/platform/loongarch/loongson-laptop.c +5 -0
index 4ec56621db24..d582eec765ef 100644
@@ -415,6 +415,11 @@ static int laptop_backlight_register(void)
 	if (!acpi_evalf(hotkey_handle, &status, "ECLL", "d"))
 		return -EIO;
 
+	if (status < 0) {
+		pr_err("Invalid maximum brightness: %d\n", status);
+		return -EINVAL;
+	}
+
 	ret = ec_backlight_set_power(true);
 	if (ret)
 		return ret;
#1 lore raw

+Cc [email protected]

Quoted 31 lines · Thorsten Blum

laptop_backlight_register() uses the maximum brightness reported by the ECLL ACPI method without validating it. A negative result could cause the driver to register a backlight with an invalid brightness range.

Return -EINVAL for negative values before powering on and registering the backlight.

Fixes 6246ed09111f ("LoongArch: Add ACPI-based generic laptop driver")

---
Found by code inspection and compile-tested only.

 drivers/platform/loongarch/loongson-laptop.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/platform/loongarch/loongson-laptop.c +5 -0
index 4ec56621db24..d582eec765ef 100644
@@ -415,6 +415,11 @@ static int laptop_backlight_register(void)
 	if (!acpi_evalf(hotkey_handle, &status, "ECLL", "d"))
 		return -EIO;
 
+	if (status < 0) {
+		pr_err("Invalid maximum brightness: %d\n", status);
+		return -EINVAL;
+	}
+
 	ret = ec_backlight_set_power(true);
 	if (ret)
 		return ret;