Skip to contentSkip to conversation

backlight: aw99706: Fix DT property names to match binding

PATCH Superseded Junjie Cao 2 participants 5 messages Jul 1 – Jul 17

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Junjie Cao

author maintainer
#0 lore raw

PATCH 1/2 backlight: aw99706: Fix DT property names to match binding

The driver reads four tuning properties without the unit suffixes that the binding mandates: "awinic,sw-freq" instead of "awinic,sw-freq-hz", "awinic,sw-ilmt" instead of "awinic,sw-ilmt-microamp", "awinic,iled-max" instead of "awinic,iled-max-microamp", and "awinic,uvlo-thres" instead of "awinic,uvlo-thres-microvolt".

As a result, device_property_read_u32() never finds these properties in a binding-conformant device tree and silently falls back to the compiled-in defaults for switching frequency, switching current limit, max LED current, and UVLO threshold.

Fix by aligning the property name strings in aw99706_dt_props[] with the binding. No value/range changes are needed since both sides already use the same units and enumerations.

Fixes 147b38a5ad06 ("backlight: aw99706: Add support for Awinic AW99706 backlight")
---
 drivers/video/backlight/aw99706.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/video/backlight/aw99706.c +4 -4
index 938f352aaab7..abacf5a6c8ae 100644
@@ -130,23 +130,23 @@ static const struct aw99706_dt_prop aw99706_dt_props[] = {
 		AW99706_CFG0_REG, AW99706_DIM_MODE_MASK, 1,
 	},
 	{
-		"awinic,sw-freq", aw99706_dt_property_lookup,
+		"awinic,sw-freq-hz", aw99706_dt_property_lookup,
 		aw99706_sw_freq_tbl, ARRAY_SIZE(aw99706_sw_freq_tbl),
 		AW99706_CFG1_REG, AW99706_SW_FREQ_MASK, 750000,
 	},
 	{
-		"awinic,sw-ilmt", aw99706_dt_property_lookup,
+		"awinic,sw-ilmt-microamp", aw99706_dt_property_lookup,
 		aw99706_sw_ilmt_tbl, ARRAY_SIZE(aw99706_sw_ilmt_tbl),
 		AW99706_CFG1_REG, AW99706_SW_ILMT_MASK, 3000000,
 	},
 	{
-		"awinic,iled-max", aw99706_dt_property_iled_max_convert,
+		"awinic,iled-max-microamp", aw99706_dt_property_iled_max_convert,
 		NULL, 0,
 		AW99706_CFG2_REG, AW99706_ILED_MAX_MASK, 20000,
 
 	},
 	{
-		"awinic,uvlo-thres", aw99706_dt_property_lookup,
+		"awinic,uvlo-thres-microvolt", aw99706_dt_property_lookup,
 		aw99706_ulvo_thres_tbl, ARRAY_SIZE(aw99706_ulvo_thres_tbl),
 		AW99706_CFG2_REG, AW99706_UVLOSEL_MASK, 2200000,
 	},
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH 2/2 backlight: aw99706: Validate all DT property values consistently

The lookup helpers for dim-mode and ramp-ctl take a shortcut when lookup_tbl is NULL: they accept any u32 value without range-checking and return success unconditionally. Out-of-range values get silently truncated by regmap_update_bits instead of triggering the dev_warn + default-fallback path that the other properties use.

Add a field-width check for the NULL-table case so that values exceeding the register field maximum are rejected the same way a table-lookup miss is.

While here, also switch the error returns to -EINVAL for consistency.

---
 drivers/video/backlight/aw99706.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/video/backlight/aw99706.c +8 -3
index abacf5a6c8ae..a00a4144f160 100644
@@ -94,6 +94,8 @@ static int aw99706_dt_property_lookup(const struct aw99706_dt_prop *prop,
 	int i;
 
 	if (!prop->lookup_tbl) {
+		if (dt_val > (prop->mask >> __ffs(prop->mask)))
+			return -EINVAL;
 		*val = dt_val;
 		return 0;
 	}
@@ -104,7 +106,7 @@ static int aw99706_dt_property_lookup(const struct aw99706_dt_prop *prop,
 
 	*val = i;
 
-	return i == prop->tbl_size ? -1 : 0;
+	return i == prop->tbl_size ? -EINVAL : 0;
 }
 
 #define MIN_ILED_MAX	5000
@@ -116,11 +118,14 @@ aw99706_dt_property_iled_max_convert(const struct aw99706_dt_prop *prop,
 				     u32 dt_val, u8 *val)
 {
 	if (dt_val > MAX_ILED_MAX || dt_val < MIN_ILED_MAX)
-		return -1;
+		return -EINVAL;
+
+	if ((dt_val - MIN_ILED_MAX) % STEP_ILED_MAX)
+		return -EINVAL;
 
 	*val = (dt_val - MIN_ILED_MAX) / STEP_ILED_MAX;
 
-	return (dt_val - MIN_ILED_MAX) % STEP_ILED_MAX;
+	return 0;
 }
 
 static const struct aw99706_dt_prop aw99706_dt_props[] = {
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 2/2] backlight: aw99706: Validate all DT property values consistently

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] I2C read performed before enabling the chip via GPIO. --

commit 9b2c49c6b957cfe305a408b8c9b3c4052b039334
Author: Junjie Cao <[email protected]>

backlight: aw99706: Validate all DT property values consistently

The lookup helpers for dim-mode and ramp-ctl take a shortcut when lookup_tbl is NULL: they accept any u32 value without range-checking and return success unconditionally. Out-of-range values get silently truncated by regmap_update_bits instead of triggering the dev_warn + default-fallback path that the other properties use.

drivers/video/backlight/aw99706.c

Quoted 4 lines
drivers/video/backlight/aw99706.c +0 -0
index e130f164303a2..dfb4b38b5b4c7 100644

[ ... ]

[Severity: High]
This is a pre-existing issue, but while reviewing this driver I noticed a potential issue in aw99706_probe(). Does the driver attempt to read the chip ID before enabling the device?

drivers/video/backlight/aw99706.c:aw99706_probe() {
    ...
	ret = aw99706_chip_id_read(aw);
	if (ret != AW99706_ID)
		return dev_err_probe(dev, -ENODEV,
				     "Unknown chip id 0x%02x\n", ret);

	aw99706_dt_parse(aw, &props);

	aw->hwen_gpio = devm_gpiod_get(aw->dev, "enable", GPIOD_OUT_LOW);
    ...
}

If the bootloader leaves the chip disabled, would this I2C read fail or time out because the enable GPIO is not fetched and asserted until later in the probe sequence?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#3 lore raw
In reply to Junjie Cao
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The driver attempts to communicate with the chip via I2C before acquiring and enabling the hardware via its enable GPIO. --

commit a2f8eb8bf399f54262cbf37acb4512885c65a3b6
Author: Junjie Cao <[email protected]>

backlight: aw99706: Fix DT property names to match binding

The driver reads four tuning properties without the unit suffixes that the binding mandates. As a result, device_property_read_u32() never finds these properties in a binding-conformant device tree and silently falls back to the compiled-in defaults. This patch fixes the property name strings in aw99706_dt_props[] to match the binding.

drivers/video/backlight/aw99706.c static const struct aw99706_dt_prop aw99706_dt_props[] = {

Quoted 5 lines
drivers/video/backlight/aw99706.c +0 -0
index 18299faf06ad4..e130f164303a2 100644
@@ -130,23 +130,23 @@ static const struct aw99706_dt_prop aw99706_dt_props[] = {

[ ... ]

This is a pre-existing issue, but I noticed something concerning in the initialization sequence within aw99706_probe() in the same file:

drivers/video/backlight/aw99706.c:aw99706_probe() {
    ...
	ret = aw99706_chip_id_read(aw);
	if (ret != AW99706_ID)
		return dev_err_probe(dev, -ENODEV,
				     "Unknown chip id 0x%02x\n", ret);

	aw99706_dt_parse(aw, &props);

	aw->hwen_gpio = devm_gpiod_get(aw->dev, "enable", GPIOD_OUT_LOW);
	if (IS_ERR(aw->hwen_gpio))
		return dev_err_probe(dev, PTR_ERR(aw->hwen_gpio),
				     "Failed to get enable gpio\n");

	ret = aw99706_hw_init(aw);
    ...
}

[Severity: High]
Does this sequence result in unconditional probe failure on platforms where the bootloader does not pre-enable the backlight hardware?

The driver attempts to communicate with the chip via I2C during aw99706_chip_id_read() before the hardware enable GPIO is acquired and asserted in aw99706_hw_init().

Because the hardware is likely powered down when aw99706_chip_id_read() is called, it will not acknowledge the I2C transaction and will return an error.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1