Patch "leds: multicolor: Use rounded division when calculating color components" has been added to the 6.5-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    leds: multicolor: Use rounded division when calculating color components

to the 6.5-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     leds-multicolor-use-rounded-division-when-calculatin.patch
and it can be found in the queue-6.5 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 82690142e115ef33de4b9f8ef99c46392af09632
Author: Marek Behún <kabel@xxxxxxxxxx>
Date:   Tue Aug 1 14:49:31 2023 +0200

    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@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20230801124931.8661-1-kabel@xxxxxxxxxx
    Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/leds/led-class-multicolor.c b/drivers/leds/led-class-multicolor.c
index e317408583df9..ec62a48116135 100644
--- a/drivers/leds/led-class-multicolor.c
+++ b/drivers/leds/led-class-multicolor.c
@@ -6,6 +6,7 @@
 #include <linux/device.h>
 #include <linux/init.h>
 #include <linux/led-class-multicolor.h>
+#include <linux/math.h>
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
@@ -19,9 +20,10 @@ int led_mc_calc_color_components(struct led_classdev_mc *mcled_cdev,
 	int i;
 
 	for (i = 0; i < mcled_cdev->num_colors; i++)
-		mcled_cdev->subled_info[i].brightness = brightness *
-					mcled_cdev->subled_info[i].intensity /
-					led_cdev->max_brightness;
+		mcled_cdev->subled_info[i].brightness =
+			DIV_ROUND_CLOSEST(brightness *
+					  mcled_cdev->subled_info[i].intensity,
+					  led_cdev->max_brightness);
 
 	return 0;
 }



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux