From: Michael Tretter <m.tretter@pengutronix.de>
To: Lee Jones <lee@kernel.org>
Cc: Andy Shevchenko <andriy.shevchenko@intel.com>,
Pavel Machek <pavel@kernel.org>, Dan Murphy <dmurphy@ti.com>,
Jacek Anaszewski <jacek.anaszewski@gmail.com>,
Pavel Machek <pavel@ucw.cz>,
linux-leds@vger.kernel.org, kernel@pengutronix.de,
Khalid Talash <ktalash@topcon.com>
Subject: Re: [PATCH] leds: multicolor: limit intensity to max_brightness of LED
Date: Fri, 6 Mar 2026 16:29:52 +0100 [thread overview]
Message-ID: <aary8OPCveDNbbpP@pengutronix.de> (raw)
In-Reply-To: <20260306135505.GN183676@google.com>
On Fri, 06 Mar 2026 13:55:05 +0000, Lee Jones wrote:
> On Thu, 05 Mar 2026, Andy Shevchenko wrote:
>
> > On Fri, Jan 23, 2026 at 11:13:24AM +0100, Michael Tretter wrote:
> > > According to Documentation/ABI/testing/sysfs-class-led-multicolor, the
> > > intensity should not exceed /sys/class/leds/<led>/max_brightness.
> > >
> > > The interface doesn't check the values and higher values may lead to
> > > unexpected color changes if the brightness is changed.
> > >
> > > Clamp the intensity value to max_brightness.
> >
> > This also brings a regression if somebody doesn't care about wrapping around.
> > It's possible to return an error instead, but still the user space will be
> > broken (in some rare weird cases).
If somebody in user space doesn't care about the wrap around for the
brightness value, the behavior will still differ between systems,
because the value for the wraparound for brightness depends on
max_brightness, which is driver specific and some drivers already
implement clamping on max_brightness.
Handling this in a coherent way at the API level leads to more
consistent behavior between different drivers.
Furthermore, intensity for multicolor LEDs behaves kind of like
brightness for single color LEDs and for these, the documentation
(Documentation/ABI/testing/sysfs-class-led) specifies that
The [brightness] value is between 0 and
/sys/class/leds/<led>/max_brightness
and
Most LEDs don't have hardware brightness support, so will
just be turned on for non-zero brightness settings.
With a wraparound behavior, writing (max_brightness + 1) to brightness
would lead to a wraparound and turn the LED off, which is against this
specification.
I agree that the behavior of intensity is undefined if it exceeds
max_brightness. Do you have an example of user space (or use case) that
relies on this behavior or is this a hypothetical case?
> >
> > Again, I care even less about this change, but be always careful,
> > the main rule in the kernel "We do NOT break user space".
>
> I'm going to remove this patch for now.
>
> /tmp/next/build/drivers/leds/led-class-multicolor.c: In function 'multi_intensity_store':
> /tmp/next/build/include/linux/compiler_types.h:706:45: error: call to '__compiletime_assert_434' declared with attribute error: min(intensity_value[i], led_cdev->max_brightness) signedness error
> 706 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
> | ^
> /tmp/next/build/include/linux/compiler_types.h:687:25: note: in definition of macro '__compiletime_assert'
> 687 | prefix ## suffix(); \
> | ^~~~~~
> /tmp/next/build/include/linux/compiler_types.h:706:9: note: in expansion of macro '_compiletime_assert'
> 706 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
> | ^~~~~~~~~~~~~~~~~~~
> /tmp/next/build/include/linux/build_bug.h:40:37: note: in expansion of macro 'compiletime_assert'
> 40 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
> | ^~~~~~~~~~~~~~~~~~
> /tmp/next/build/include/linux/minmax.h:93:9: note: in expansion of macro 'BUILD_BUG_ON_MSG'
> 93 | BUILD_BUG_ON_MSG(!__types_ok(ux, uy), \
> | ^~~~~~~~~~~~~~~~
> /tmp/next/build/include/linux/minmax.h:98:9: note: in expansion of macro '__careful_cmp_once'
> 98 | __careful_cmp_once(op, x, y, __UNIQUE_ID(x_), __UNIQUE_ID(y_))
> | ^~~~~~~~~~~~~~~~~~
> /tmp/next/build/include/linux/minmax.h:105:25: note: in expansion of macro '__careful_cmp'
> 105 | #define min(x, y) __careful_cmp(min, x, y)
> | ^~~~~~~~~~~~~
> /tmp/next/build/drivers/leds/led-class-multicolor.c:51:38: note: in expansion of macro 'min'
> 51 | intensity_value[i] = min(intensity_value[i],
> |
I'm confused because you already applied [0] my patch that fixes this
exact error.
[0] https://lore.kernel.org/all/177273014112.321702.15159156714467402540.b4-ty@kernel.org/
Michael
next prev parent reply other threads:[~2026-03-06 15:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-23 10:13 [PATCH] leds: multicolor: limit intensity to max_brightness of LED Michael Tretter
2026-02-05 15:51 ` (subset) " Lee Jones
2026-03-05 14:08 ` Andy Shevchenko
2026-03-06 11:30 ` Lee Jones
2026-03-06 15:08 ` Andy Shevchenko
2026-03-06 13:55 ` Lee Jones
2026-03-06 15:09 ` Andy Shevchenko
2026-03-06 15:34 ` Michael Tretter
2026-03-06 15:29 ` Michael Tretter [this message]
2026-03-06 18:58 ` Andy Shevchenko
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=aary8OPCveDNbbpP@pengutronix.de \
--to=m.tretter@pengutronix.de \
--cc=andriy.shevchenko@intel.com \
--cc=dmurphy@ti.com \
--cc=jacek.anaszewski@gmail.com \
--cc=kernel@pengutronix.de \
--cc=ktalash@topcon.com \
--cc=lee@kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@kernel.org \
--cc=pavel@ucw.cz \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox