Skip to contentSkip to conversation

backlight: pm8941: Add NULL check in wled_configure()

PATCH Superseded Henry Martin 3 participants 3 messages Mar 31, 2025

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 backlight: pm8941: Add NULL check in wled_configure()

devm_kasprintf() return NULL if memory allocation fails. Currently, wled_configure() does not check for this case, leading to a possible NULL pointer dereference.

Add NULL check after devm_kasprintf() to prevent this issue.

Fixes f86b77583d88 ("backlight: pm8941: Convert to using %pOFn instead of device_node.name")

---
V1 -> V2: Fix commit message to use imperative mood and wrap lines to 75 characters.

 drivers/video/backlight/qcom-wled.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/video/backlight/qcom-wled.c +4 -2
index 9afe701b2a1b..a63bb42c8f8b 100644
@@ -1406,9 +1406,11 @@ static int wled_configure(struct wled *wled)
 	wled->ctrl_addr = be32_to_cpu(*prop_addr);
 
 	rc = of_property_read_string(dev->of_node, "label", &wled->name);
-	if (rc)
+	if (rc) {
 		wled->name = devm_kasprintf(dev, GFP_KERNEL, "%pOFn", dev->of_node);
-
+		if (!wled->name)
+			return -ENOMEM;
+	}
 	switch (wled->version) {
 	case 3:
 		u32_opts = wled3_opts;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 1 line

devm_kasprintf() return NULL if memory allocation fails. Currently,

call? failed?

Quoted 2 lines

wled_configure() does not check for this case, leading to a possible NULL pointer dereference.

You may omit the word “possible” in such a change description. (Would questionable data processing happen in other function implementations?)

Quoted 1 line

Add NULL check after devm_kasprintf() to prevent this issue.

Do you complete the error/exception handling also with the statement “return -ENOMEM;”?

Regards,
Markus

Reviewed-by on v2 1/1
#2 lore raw
In reply to Henry Martin
Quoted 6 lines · Henry Martin

devm_kasprintf() return NULL if memory allocation fails. Currently, wled_configure() does not check for this case, leading to a possible NULL pointer dereference.

Add NULL check after devm_kasprintf() to prevent this issue.

Quoted 9 lines
Fixes f86b77583d88 ("backlight: pm8941: Convert to using %pOFn instead of device_node.name")

---
V1 -> V2: Fix commit message to use imperative mood and wrap lines to 75 characters.

 drivers/video/backlight/qcom-wled.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Signature · 2 lines
With best wishes
Dmitry