All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] backlight: ktd253: Initialize properties before device registration
@ 2026-11-19 23:07 Thorsten Blum
  2026-11-19 23:07 ` [PATCH 2/3] backlight: ktd2801: " Thorsten Blum
  2026-11-19 23:07 ` [PATCH 3/3] backlight: aat2870: " Thorsten Blum
  0 siblings, 2 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-11-19 23:07 UTC (permalink / raw)
  To: Lee Jones, Daniel Thompson, Jingoo Han, Helge Deller,
	Linus Walleij, Duje Mihanović, Jin Park, Samuel Ortiz
  Cc: dri-devel, linux-fbdev, Thorsten Blum

The backlight API requires max_brightness to be supplied at device
registration and not to be modified afterwards. KTD253 currently sets it
after registering the device, allowing userspace to read a maximum
brightness of 0 before the configured value is applied.

Pass the initial brightness, maximum brightness, and power state to
devm_backlight_device_register() to set them before the sysfs attributes
become visible to userspace.

Fixes: 5317f37e48b9 ("backlight: Add Kinetic KTD253 backlight driver")
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 drivers/video/backlight/ktd253-backlight.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/video/backlight/ktd253-backlight.c b/drivers/video/backlight/ktd253-backlight.c
index 8091c7e085e8..5fc29c858a4b 100644
--- a/drivers/video/backlight/ktd253-backlight.c
+++ b/drivers/video/backlight/ktd253-backlight.c
@@ -141,6 +141,9 @@ static const struct backlight_ops ktd253_backlight_ops = {
 
 static int ktd253_backlight_probe(struct platform_device *pdev)
 {
+	struct backlight_properties props = {
+		.type = BACKLIGHT_RAW,
+	};
 	struct device *dev = &pdev->dev;
 	struct backlight_device *bl;
 	struct ktd253_backlight *ktd253;
@@ -179,21 +182,16 @@ static int ktd253_backlight_probe(struct platform_device *pdev)
 	/* Bring backlight to a known off state */
 	msleep(KTD253_T_OFF_MS);
 
+	props.max_brightness = max_brightness;
+	props.brightness = brightness;
+	props.power = brightness ? BACKLIGHT_POWER_ON : BACKLIGHT_POWER_OFF;
+
 	bl = devm_backlight_device_register(dev, dev_name(dev), dev, ktd253,
-					    &ktd253_backlight_ops, NULL);
+					    &ktd253_backlight_ops, &props);
 	if (IS_ERR(bl)) {
 		dev_err(dev, "failed to register backlight\n");
 		return PTR_ERR(bl);
 	}
-	bl->props.max_brightness = max_brightness;
-	/* When we just enable the GPIO line we set max brightness */
-	if (brightness) {
-		bl->props.brightness = brightness;
-		bl->props.power = BACKLIGHT_POWER_ON;
-	} else {
-		bl->props.brightness = 0;
-		bl->props.power = BACKLIGHT_POWER_OFF;
-	}
 
 	ktd253->bl = bl;
 	platform_set_drvdata(pdev, bl);

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] backlight: ktd2801: Initialize properties before device registration
  2026-11-19 23:07 [PATCH 1/3] backlight: ktd253: Initialize properties before device registration Thorsten Blum
@ 2026-11-19 23:07 ` Thorsten Blum
  2026-11-19 23:07 ` [PATCH 3/3] backlight: aat2870: " Thorsten Blum
  1 sibling, 0 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-11-19 23:07 UTC (permalink / raw)
  To: Lee Jones, Daniel Thompson, Jingoo Han, Helge Deller,
	Linus Walleij, Duje Mihanović, Jin Park, Samuel Ortiz
  Cc: dri-devel, linux-fbdev, Thorsten Blum

The backlight API requires max_brightness to be supplied at device
registration and not to be modified afterwards. KTD2801 currently sets
it after registering the device, allowing userspace to read a maximum
brightness of 0 before the configured value is applied.

Pass the initial brightness and the maximum brightness to
devm_backlight_device_register() to set them before the sysfs attributes
become visible to userspace.

Fixes: a5554f1b5bc3 ("backlight: Add Kinetic KTD2801 Backlight support")
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 drivers/video/backlight/ktd2801-backlight.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/video/backlight/ktd2801-backlight.c b/drivers/video/backlight/ktd2801-backlight.c
index c218ee55f253..ff149de36dee 100644
--- a/drivers/video/backlight/ktd2801-backlight.c
+++ b/drivers/video/backlight/ktd2801-backlight.c
@@ -58,6 +58,9 @@ static const struct backlight_ops ktd2801_backlight_ops = {
 
 static int ktd2801_backlight_probe(struct platform_device *pdev)
 {
+	struct backlight_properties props = {
+		.type = BACKLIGHT_RAW,
+	};
 	struct device *dev = &pdev->dev;
 	struct backlight_device *bd;
 	struct ktd2801_backlight *ktd2801;
@@ -92,15 +95,15 @@ static int ktd2801_backlight_probe(struct platform_device *pdev)
 				"failed to get backlight GPIO");
 	gpiod_set_consumer_name(ktd2801->props.ctrl_gpio, dev_name(dev));
 
+	props.max_brightness = max_brightness;
+	props.brightness = brightness;
+
 	bd = devm_backlight_device_register(dev, dev_name(dev), dev, ktd2801,
-			&ktd2801_backlight_ops, NULL);
+			&ktd2801_backlight_ops, &props);
 	if (IS_ERR(bd))
 		return dev_err_probe(dev, PTR_ERR(bd),
 				"failed to register backlight");
 
-	bd->props.max_brightness = max_brightness;
-	bd->props.brightness = brightness;
-
 	ktd2801->bd = bd;
 	platform_set_drvdata(pdev, bd);
 	backlight_update_status(bd);

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] backlight: aat2870: Initialize properties before device registration
  2026-11-19 23:07 [PATCH 1/3] backlight: ktd253: Initialize properties before device registration Thorsten Blum
  2026-11-19 23:07 ` [PATCH 2/3] backlight: ktd2801: " Thorsten Blum
@ 2026-11-19 23:07 ` Thorsten Blum
  2026-11-19 23:17   ` sashiko-bot
  1 sibling, 1 reply; 4+ messages in thread
From: Thorsten Blum @ 2026-11-19 23:07 UTC (permalink / raw)
  To: Lee Jones, Daniel Thompson, Jingoo Han, Helge Deller,
	Linus Walleij, Duje Mihanović, Jin Park, Samuel Ortiz
  Cc: dri-devel, linux-fbdev, Thorsten Blum

The backlight API requires max_brightness to be supplied at device
registration and not to be modified afterwards. AAT2870 currently sets
it after registering the device, allowing userspace to read a maximum
brightness of 0 before the configured value is applied.

Pass the initial brightness and the maximum brightness to
devm_backlight_device_register() to set them before the sysfs attributes
become visible to userspace.

Fixes: 4b0d711be39f ("backlight: Add AAT2870 backlight driver")
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 drivers/video/backlight/aat2870_bl.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/video/backlight/aat2870_bl.c b/drivers/video/backlight/aat2870_bl.c
index 5af36d3784f1..fa854827e558 100644
--- a/drivers/video/backlight/aat2870_bl.c
+++ b/drivers/video/backlight/aat2870_bl.c
@@ -99,7 +99,11 @@ static int aat2870_bl_probe(struct platform_device *pdev)
 	struct aat2870_bl_platform_data *pdata = dev_get_platdata(&pdev->dev);
 	struct aat2870_bl_driver_data *aat2870_bl;
 	struct backlight_device *bd;
-	struct backlight_properties props;
+	struct backlight_properties props = {
+		.type = BACKLIGHT_RAW,
+		.max_brightness = 255,
+		.power = BACKLIGHT_POWER_ON,
+	};
 	int ret = 0;
 
 	if (!pdata) {
@@ -120,9 +124,10 @@ static int aat2870_bl_probe(struct platform_device *pdev)
 		goto out;
 	}
 
-	memset(&props, 0, sizeof(struct backlight_properties));
+	if (pdata->max_brightness > 0)
+		props.max_brightness = pdata->max_brightness;
+	props.brightness = props.max_brightness;
 
-	props.type = BACKLIGHT_RAW;
 	bd = devm_backlight_device_register(&pdev->dev, "aat2870-backlight",
 					&pdev->dev, aat2870_bl, &aat2870_bl_ops,
 					&props);
@@ -148,14 +153,7 @@ static int aat2870_bl_probe(struct platform_device *pdev)
 	else
 		aat2870_bl->max_current = AAT2870_CURRENT_27_9;
 
-	if (pdata->max_brightness > 0)
-		bd->props.max_brightness = pdata->max_brightness;
-	else
-		bd->props.max_brightness = 255;
-
 	aat2870_bl->brightness = 0;
-	bd->props.power = BACKLIGHT_POWER_ON;
-	bd->props.brightness = bd->props.max_brightness;
 
 	ret = aat2870_bl_update_status(bd);
 	if (ret < 0) {

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 3/3] backlight: aat2870: Initialize properties before device registration
  2026-11-19 23:07 ` [PATCH 3/3] backlight: aat2870: " Thorsten Blum
@ 2026-11-19 23:17   ` sashiko-bot
  0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-19 23:17 UTC (permalink / raw)
  To: Thorsten Blum; +Cc: dri-devel

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] backlight: aat2870_bl: NULL pointer dereference in
  aat2870_bl_update_status() [1]
--

commit d325449f615b625e1f4a4a3e7a3f53db9a33c1e2
Author: Thorsten Blum <blum@kernel.org>

backlight: aat2870: Initialize properties before device registration

This commit initializes the backlight properties before calling
devm_backlight_device_register() so that max_brightness and initial
brightness are set before the sysfs attributes are exposed to userspace.

> diff --git a/drivers/video/backlight/aat2870_bl.c b/drivers/video/backlight/aat2870_bl.c
> index 5af36d3784f11..fa854827e5580 100644
> --- a/drivers/video/backlight/aat2870_bl.c
> +++ b/drivers/video/backlight/aat2870_bl.c
[ ... ]
> @@ -120,9 +124,10 @@ static int aat2870_bl_probe(struct platform_device *pdev)
>  		goto out;
>  	}
>  
> -	memset(&props, 0, sizeof(struct backlight_properties));
> +	if (pdata->max_brightness > 0)
> +		props.max_brightness = pdata->max_brightness;
> +	props.brightness = props.max_brightness;
>  
> -	props.type = BACKLIGHT_RAW;
>  	bd = devm_backlight_device_register(&pdev->dev, "aat2870-backlight",
>  					&pdev->dev, aat2870_bl, &aat2870_bl_ops,
>  					&props);

[Severity: Critical]
This problem wasn't introduced by this patch, but can registering the
backlight device before initializing aat2870_bl->pdev cause a NULL pointer
dereference in aat2870_bl_update_status() [1]?

devm_backlight_device_register() exposes the sysfs interface before
aat2870_bl_probe() populates aat2870_bl->pdev (and aat2870_bl->bd,
channels, and max_current):

drivers/video/backlight/aat2870_bl.c:aat2870_bl_update_status() {
	struct aat2870_bl_driver_data *aat2870_bl = bl_get_data(bd);
	struct aat2870_data *aat2870 =
			dev_get_drvdata(aat2870_bl->pdev->dev.parent);
    ...
}

If userspace writes to a sysfs attribute such as brightness right after
registration, the backlight core invokes aat2870_bl_update_status() while
aat2870_bl->pdev is still NULL:

CPU0                                CPU1
aat2870_bl_probe()
  devm_backlight_device_register()
                                    brightness_store()
                                      ...
                                        aat2870_bl_update_status()
                                          aat2870_bl->pdev->dev.parent
                                            <-- NULL pointer dereference
  aat2870_bl->pdev = pdev;

Initializing the driver data fields in aat2870_bl before calling
devm_backlight_device_register() would avoid this race.

[1] https://sashiko.dev/#/bug/linux-9a61532b-5d7a-467d-b3d1-d6420978c8f3

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119230733.790573-4-blum@kernel.org?part=3

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-19 23:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 23:07 [PATCH 1/3] backlight: ktd253: Initialize properties before device registration Thorsten Blum
2026-11-19 23:07 ` [PATCH 2/3] backlight: ktd2801: " Thorsten Blum
2026-11-19 23:07 ` [PATCH 3/3] backlight: aat2870: " Thorsten Blum
2026-11-19 23:17   ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.