From: Matt Moeller leds_gmc_set() multiplies brightness, intensity and the monochromatic LED's max_brightness in unsigned int, and DIV_ROUND_CLOSEST() then adds half the divisor. With 12-bit LEDs (max_brightness 4095, e.g. the IS31FL3293) the result passes UINT_MAX as soon as brightness * intensity passes about 2^20, and the LEDs get wrapped values: a group at 4095 with intensities 1605 1284 0 sets red 68 and green 3 instead of 1605 and 1284, and a group brightness of 256 at full intensity sets 0. Do the calculation in 64 bits. The problem was found and this fix written with help from Claude (Anthropic), and tested on hardware. Fixes: 37d0849ed392 ("leds: rgb: Add a multicolor LED driver to group monochromatic LEDs") Cc: stable@vger.kernel.org Signed-off-by: Matt Moeller --- drivers/leds/rgb/leds-group-multicolor.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/leds/rgb/leds-group-multicolor.c b/drivers/leds/rgb/leds-group-multicolor.c index a707d51c6a4b..797538f73115 100644 --- a/drivers/leds/rgb/leds-group-multicolor.c +++ b/drivers/leds/rgb/leds-group-multicolor.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -41,8 +42,10 @@ static int leds_gmc_set(struct led_classdev *cdev, enum led_brightness brightnes * Scale the brightness according to relative intensity of the * color AND the max brightness of the monochromatic LED. */ - mono_brightness = DIV_ROUND_CLOSEST(brightness * intensity * mono_max_brightness, - group_max_brightness * group_max_brightness); + mono_brightness = DIV64_U64_ROUND_CLOSEST((u64)brightness * intensity * + mono_max_brightness, + (u64)group_max_brightness * + group_max_brightness); led_set_brightness(mono, mono_brightness); } -- 2.53.0