]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
leds: multicolor: Use rounded division when calculating color components
authorMarek Behún <kabel@kernel.org>
Tue, 1 Aug 2023 12:49:31 +0000 (14:49 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 19 Sep 2023 10:22:48 +0000 (12:22 +0200)
commit0f715ea7d36e2582ad5bd4b4ddd24f3fd45d13ba
treeaa510a439428cd8925994f81937dcebc6c183d6b
parent1a68bef23726efa1d1939f71b6a58918a4ee3d4e
leds: multicolor: Use rounded division when calculating color components

[ Upstream commit 065d099f1be58187e6629273c50b948a02b7e1bf ]

Given channel intensity, LED brightness and max LED brightness, the
multicolor LED framework helper led_mc_calc_color_components() computes
the color channel brightness as

    chan_brightness = brightness * chan_intensity / max_brightness

Consider the situation when (brightness, intensity, max_brightness) is
for example (16, 15, 255), then chan_brightness is computed to 0
although the fractional divison would give 0.94, which should be rounded
to 1.

Use DIV_ROUND_CLOSEST here for the division to give more realistic
component computation:

    chan_brightness = DIV_ROUND_CLOSEST(brightness * chan_intensity,
                                        max_brightness)

Fixes: 55d5d3b46b08 ("leds: multicolor: Introduce a multicolor class definition")
Signed-off-by: Marek Behún <kabel@kernel.org>
Link: https://lore.kernel.org/r/20230801124931.8661-1-kabel@kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/leds/led-class-multicolor.c