All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thorsten Blum <blum@kernel.org>
To: Huacai Chen <chenhuacai@kernel.org>,
	WANG Xuerui <kernel@xen0n.name>,
	Jianmin Lv <lvjianmin@loongson.cn>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: loongarch@lists.linux.dev, Thorsten Blum <blum@kernel.org>
Subject: [PATCH] platform/loongarch: laptop: Reject negative max brightness values
Date: Fri, 27 Nov 2026 16:55:08 +0100	[thread overview]
Message-ID: <20261127155507.805377-2-blum@kernel.org> (raw)

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")
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
Found by code inspection and compile-tested only.

 drivers/platform/loongarch/loongson-laptop.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/platform/loongarch/loongson-laptop.c b/drivers/platform/loongarch/loongson-laptop.c
index 4ec56621db24..d582eec765ef 100644
--- a/drivers/platform/loongarch/loongson-laptop.c
+++ b/drivers/platform/loongarch/loongson-laptop.c
@@ -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;

             reply	other threads:[~2026-11-27 15:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 15:55 Thorsten Blum [this message]
2026-11-27 16:07 ` [PATCH] platform/loongarch: laptop: Reject negative max brightness values Thorsten Blum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127155507.805377-2-blum@kernel.org \
    --to=blum@kernel.org \
    --cc=chenhuacai@kernel.org \
    --cc=kernel@xen0n.name \
    --cc=loongarch@lists.linux.dev \
    --cc=lvjianmin@loongson.cn \
    --cc=rafael.j.wysocki@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.