From: Thorsten Blum <blum@kernel.org>
To: "Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Seth Forshee" <sforshee@kernel.org>,
"Matthew Garrett" <mjg@redhat.com>
Cc: Thorsten Blum <blum@kernel.org>, platform-driver-x86@vger.kernel.org
Subject: [PATCH v2] platform/x86: apple-gmux: Fix max_brightness limit check in gmux_probe()
Date: Fri, 20 Nov 2026 17:29:41 +0100 [thread overview]
Message-ID: <20261120162940.867852-2-blum@kernel.org> (raw)
gmux_read32() returns a u32, but the maximum brightness is stored in the
signed ->max_brightness field. Large values can thus become negative and
bypass the GMUX_MAX_BRIGHTNESS check.
Store the maximum brightness in a local u32 variable until after the
bounds check, and then assign it to props.max_brightness. Use dev_warn()
instead of WARN_ON() to report an out-of-range hardware value.
Also move the backlight properties and maximum brightness calculation
into the device registration block, use a designated initializer for the
properties, and simplify the comments.
Fixes: 917ee75a5916 ("platform/x86: Add driver for Apple gmux device")
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
Changes in v2:
- Store the maximum brightness in a local u32 and assign it to
props.max_brightness after the bounds check (Ilpo)
- Replace WARN_ON() with dev_warn() to report out-of-range values (Ilpo)
- Declare and initialize props in the device registration block
- Simplify the comments
- v1: https://lore.kernel.org/r/20261120142914.825047-2-blum@kernel.org/
drivers/platform/x86/apple-gmux.c | 45 ++++++++++++++++---------------
1 file changed, 24 insertions(+), 21 deletions(-)
diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c
index 9c728ac4e045..4f7ed3c563ce 100644
--- a/drivers/platform/x86/apple-gmux.c
+++ b/drivers/platform/x86/apple-gmux.c
@@ -781,7 +781,6 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
{
struct apple_gmux_data *gmux_data;
struct resource *res;
- struct backlight_properties props;
struct backlight_device *bdev = NULL;
u8 ver_major, ver_minor, ver_release;
bool register_bdev = true;
@@ -857,32 +856,36 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
pr_info("Found gmux version %d.%d.%d [%s]\n", ver_major, ver_minor,
ver_release, gmux_data->config->name);
- memset(&props, 0, sizeof(props));
- props.type = BACKLIGHT_PLATFORM;
-
- /*
- * All MMIO gmux's have 0xffff as max brightness, but some iMacs incorrectly
- * report 0x03ff, despite the firmware being happy to set 0xffff as the brightness
- * at boot. Force 0xffff for all MMIO gmux's so they all have the correct brightness
- * range.
- */
- if (type == APPLE_GMUX_TYPE_MMIO)
- props.max_brightness = MMIO_GMUX_MAX_BRIGHTNESS;
- else
- props.max_brightness = gmux_read32(gmux_data, GMUX_PORT_MAX_BRIGHTNESS);
-
#if IS_REACHABLE(CONFIG_ACPI_VIDEO)
register_bdev = acpi_video_get_backlight_type() == acpi_backlight_apple_gmux;
#endif
if (register_bdev) {
+ struct backlight_properties props = {
+ .type = BACKLIGHT_PLATFORM,
+ };
+ u32 max_brightness;
+
/*
- * Currently it's assumed that the maximum brightness is less than
- * 2^24 for compatibility with old gmux versions. Cap the max
- * brightness at this value, but print a warning if the hardware
- * reports something higher so that it can be fixed.
+ * Some iMacs incorrectly report 0x03ff as the maximum
+ * brightness even though the firmware accepts 0xffff at boot.
+ * Use the full brightness range for all MMIO gmux devices.
*/
- if (WARN_ON(props.max_brightness > GMUX_MAX_BRIGHTNESS))
- props.max_brightness = GMUX_MAX_BRIGHTNESS;
+ if (type == APPLE_GMUX_TYPE_MMIO)
+ max_brightness = MMIO_GMUX_MAX_BRIGHTNESS;
+ else
+ max_brightness = gmux_read32(gmux_data, GMUX_PORT_MAX_BRIGHTNESS);
+
+ /*
+ * Keep the maximum brightness below 2^24 for compatibility with
+ * older gmux versions.
+ */
+ if (max_brightness > GMUX_MAX_BRIGHTNESS) {
+ dev_warn(&pnp->dev,
+ "Maximum brightness %#x exceeds limit, capping to %#x\n",
+ max_brightness, GMUX_MAX_BRIGHTNESS);
+ max_brightness = GMUX_MAX_BRIGHTNESS;
+ }
+ props.max_brightness = max_brightness;
bdev = backlight_device_register("gmux_backlight", &pnp->dev,
gmux_data, &gmux_bl_ops, &props);
reply other threads:[~2026-11-20 16:30 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261120162940.867852-2-blum@kernel.org \
--to=blum@kernel.org \
--cc=hansg@kernel.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=mjg@redhat.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=sforshee@kernel.org \
/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.