mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matt Moeller via B4 Relay <devnull+matthew.moeller.kinze.com@kernel.org>
To: Lee Jones <lee@kernel.org>, Pavel Machek <pavel@kernel.org>,
	 Griffin Kroah-Hartman <griffin@kroah.com>,
	Daniel Mack <daniel@zonque.org>,
	 Jean-Jacques Hiblot <jjhiblot@traphandler.com>
Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org,
	 stable@vger.kernel.org, Matt Moeller <matthew.moeller@kinze.com>
Subject: [PATCH 2/2] leds: rgb: leds-group-multicolor: Fix overflow with high max_brightness
Date: Wed, 02 Dec 2026 11:34:55 -0600	[thread overview]
Message-ID: <20261202-for-upstream-v1-2-709b6da8706b@kinze.com> (raw)
In-Reply-To: <20261202-for-upstream-v1-0-709b6da8706b@kinze.com>

From: Matt Moeller <matthew.moeller@kinze.com>

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 <matthew.moeller@kinze.com>
---
 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 <linux/leds.h>
 #include <linux/led-class-multicolor.h>
 #include <linux/math.h>
+#include <linux/math64.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
@@ -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



      parent reply	other threads:[~2026-12-02 17:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 17:34 [PATCH 0/2] leds: Fix IS31FL3293 reset and leds-group-multicolor overflow Matt Moeller via B4 Relay
2026-12-02 17:34 ` [PATCH 1/2] leds: is31fl32xx: Fix the IS31FL3293 reset register Matt Moeller via B4 Relay
2026-12-02 17:34 ` Matt Moeller via B4 Relay [this message]

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=20261202-for-upstream-v1-2-709b6da8706b@kinze.com \
    --to=devnull+matthew.moeller.kinze.com@kernel.org \
    --cc=daniel@zonque.org \
    --cc=griffin@kroah.com \
    --cc=jjhiblot@traphandler.com \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=matthew.moeller@kinze.com \
    --cc=pavel@kernel.org \
    --cc=stable@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®