device_property_read_u32() reads the "max-brightness" property directly
into the signed int max_brightness field. Therefore, values above
INT_MAX are interpreted as negative.

Read the property into a temporary u32 and validate it before assigning
it to the signed max_brightness field.

Values above INT_MAX now cause probe to fail with -EINVAL instead of
registering a backlight with a negative maximum brightness.

Fixes: 40115947b59f ("drm: panel: Add a panel driver for the Summit display")
Signed-off-by: Thorsten Blum <[email protected]>
---
Found by code inspection and compile-tested only.

 drivers/gpu/drm/panel/panel-summit.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/panel/panel-summit.c 
b/drivers/gpu/drm/panel/panel-summit.c
index 84435be52424..2d6fb9e08ddb 100644
--- a/drivers/gpu/drm/panel/panel-summit.c
+++ b/drivers/gpu/drm/panel/panel-summit.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
 #include <linux/backlight.h>
+#include <linux/limits.h>
 #include <linux/property.h>
 #include <drm/drm_device.h>
 #include <drm/drm_mipi_dsi.h>
@@ -67,6 +68,7 @@ static int summit_probe(struct mipi_dsi_device *dsi)
        struct backlight_properties props = { 0 };
        struct device *dev = &dsi->dev;
        struct summit_data *s_data;
+       u32 max_brightness;
        int ret;
 
        s_data = devm_drm_panel_alloc(dev, struct summit_data, panel,
@@ -78,9 +80,14 @@ static int summit_probe(struct mipi_dsi_device *dsi)
        mipi_dsi_set_drvdata(dsi, s_data);
        s_data->dsi = dsi;
 
-       ret = device_property_read_u32(dev, "max-brightness", 
&props.max_brightness);
+       ret = device_property_read_u32(dev, "max-brightness", &max_brightness);
        if (ret)
                return ret;
+
+       if (max_brightness > INT_MAX)
+               return dev_err_probe(dev, -EINVAL, "Invalid maximum brightness: 
%u\n",
+                                    max_brightness);
+       props.max_brightness = max_brightness;
        props.type = BACKLIGHT_RAW;
 
        s_data->bl = devm_backlight_device_register(dev, dev_name(dev),

Reply via email to