All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] platform/x86: apple-gmux: Fix max_brightness limit check in gmux_probe()
@ 2026-11-20 14:29 Thorsten Blum
  2026-11-20 14:38 ` Ilpo Järvinen
  0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Blum @ 2026-11-20 14:29 UTC (permalink / raw)
  To: Hans de Goede, Ilpo Järvinen, Seth Forshee, Matthew Garrett
  Cc: Thorsten Blum, platform-driver-x86

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.

Cast props.max_brightness to u32 for the check so that these values also
trigger the warning and are capped at GMUX_MAX_BRIGHTNESS.

Fixes: 917ee75a5916 ("platform/x86: Add driver for Apple gmux device")
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
Found by code inspection; not reproduced on hardware.

 drivers/platform/x86/apple-gmux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c
index 9c728ac4e045..4d3a6d2393f7 100644
--- a/drivers/platform/x86/apple-gmux.c
+++ b/drivers/platform/x86/apple-gmux.c
@@ -881,7 +881,7 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
 		 * brightness at this value, but print a warning if the hardware
 		 * reports something higher so that it can be fixed.
 		 */
-		if (WARN_ON(props.max_brightness > GMUX_MAX_BRIGHTNESS))
+		if (WARN_ON((u32)props.max_brightness > GMUX_MAX_BRIGHTNESS))
 			props.max_brightness = GMUX_MAX_BRIGHTNESS;
 
 		bdev = backlight_device_register("gmux_backlight", &pnp->dev,

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] platform/x86: apple-gmux: Fix max_brightness limit check in gmux_probe()
  2026-11-20 14:29 [PATCH] platform/x86: apple-gmux: Fix max_brightness limit check in gmux_probe() Thorsten Blum
@ 2026-11-20 14:38 ` Ilpo Järvinen
  2026-11-20 14:56   ` Thorsten Blum
  0 siblings, 1 reply; 3+ messages in thread
From: Ilpo Järvinen @ 2026-11-20 14:38 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Hans de Goede, Seth Forshee, Matthew Garrett, platform-driver-x86

On Fri, 20 Nov 2026, Thorsten Blum wrote:

> 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.
> 
> Cast props.max_brightness to u32 for the check so that these values also
> trigger the warning and are capped at GMUX_MAX_BRIGHTNESS.
> 
> Fixes: 917ee75a5916 ("platform/x86: Add driver for Apple gmux device")
> Signed-off-by: Thorsten Blum <blum@kernel.org>
> ---
> Found by code inspection; not reproduced on hardware.
> 
>  drivers/platform/x86/apple-gmux.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c
> index 9c728ac4e045..4d3a6d2393f7 100644
> --- a/drivers/platform/x86/apple-gmux.c
> +++ b/drivers/platform/x86/apple-gmux.c
> @@ -881,7 +881,7 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
>  		 * brightness at this value, but print a warning if the hardware
>  		 * reports something higher so that it can be fixed.
>  		 */
> -		if (WARN_ON(props.max_brightness > GMUX_MAX_BRIGHTNESS))
> +		if (WARN_ON((u32)props.max_brightness > GMUX_MAX_BRIGHTNESS))

???

This looks very wrong way to fix the problem (using int as proxy to 
carry it until it's bounds checked).

And why is it using WARN_ON()? Is it an indication of programming error 
that gmux_read32() returns a too large value??

-- 
 i.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] platform/x86: apple-gmux: Fix max_brightness limit check in gmux_probe()
  2026-11-20 14:38 ` Ilpo Järvinen
@ 2026-11-20 14:56   ` Thorsten Blum
  0 siblings, 0 replies; 3+ messages in thread
From: Thorsten Blum @ 2026-11-20 14:56 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Hans de Goede, Seth Forshee, Matthew Garrett, platform-driver-x86

On Fri, Nov 20, 2026 at 04:38:57PM +0200, Ilpo Järvinen wrote:
> On Fri, 20 Nov 2026, Thorsten Blum wrote:
> 
> > 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.
> > 
> > Cast props.max_brightness to u32 for the check so that these values also
> > trigger the warning and are capped at GMUX_MAX_BRIGHTNESS.
> > 
> > Fixes: 917ee75a5916 ("platform/x86: Add driver for Apple gmux device")
> > Signed-off-by: Thorsten Blum <blum@kernel.org>
> > ---
> > Found by code inspection; not reproduced on hardware.
> > 
> >  drivers/platform/x86/apple-gmux.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c
> > index 9c728ac4e045..4d3a6d2393f7 100644
> > --- a/drivers/platform/x86/apple-gmux.c
> > +++ b/drivers/platform/x86/apple-gmux.c
> > @@ -881,7 +881,7 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
> >  		 * brightness at this value, but print a warning if the hardware
> >  		 * reports something higher so that it can be fixed.
> >  		 */
> > -		if (WARN_ON(props.max_brightness > GMUX_MAX_BRIGHTNESS))
> > +		if (WARN_ON((u32)props.max_brightness > GMUX_MAX_BRIGHTNESS))
> 
> ???
> 
> This looks very wrong way to fix the problem (using int as proxy to 
> carry it until it's bounds checked).

I considered a local u32 variable before assigning it to
props.max_brightness, but then chose the smaller change.

> And why is it using WARN_ON()? Is it an indication of programming error 
> that gmux_read32() returns a too large value??

It's a hardware value, so dev_warn() would be better.

I'll send a v2.

Thanks,
Thorsten

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-20 14:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 14:29 [PATCH] platform/x86: apple-gmux: Fix max_brightness limit check in gmux_probe() Thorsten Blum
2026-11-20 14:38 ` Ilpo Järvinen
2026-11-20 14:56   ` Thorsten Blum

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.