Skip to contentSkip to conversation

acpi: check for null return of devm_kzalloc in fch_misc_setup

PATCH Applied Kang Chen 2 participants 2 messages Feb 26, 2023 – Mar 20, 2023 ACPI

lore
Share & tools
lore

Kang Chen

author
#0 lore raw

PATCH 1/1 acpi: check for null return of devm_kzalloc in fch_misc_setup

devm_kzalloc may fail, clk_data->name might be null and will cause illegal address access later.

---
 drivers/acpi/acpi_apd.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/acpi/acpi_apd.c +2 -0
index 3bbe2276c..80f945cbe 100644
@@ -83,6 +83,8 @@ static int fch_misc_setup(struct apd_private_data *pdata)
 	if (!acpi_dev_get_property(adev, "clk-name", ACPI_TYPE_STRING, &obj)) {
 		clk_data->name = devm_kzalloc(&adev->dev, obj->string.length,
 					      GFP_KERNEL);
+		if (!clk_data->name)
+			return -ENOMEM;
 
 		strcpy(clk_data->name, obj->string.pointer);
 	} else {
Signature · 1 line
2.34.1
maintainer Applied
#1 lore raw
Quoted 14 lines · Kang Chen

devm_kzalloc may fail, clk_data->name might be null and will cause illegal address access later.

---
 drivers/acpi/acpi_apd.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/acpi/acpi_apd.c +0 -0
index 3bbe2276c..80f945cbe 100644

drivers/acpi/acpi_apd.c static int fch_misc_setup(struct apd_private_data *pdata)

Quoted 9 lines
drivers/acpi/acpi_apd.c +2 -1
@@ -83,6 +83,8 @@ static int fch_misc_setup(struct apd_private_data *pdata)
        if (!acpi_dev_get_property(adev, "clk-name", ACPI_TYPE_STRING, &obj)) {
                clk_data->name = devm_kzalloc(&adev->dev, obj->string.length,
                                              GFP_KERNEL);
+               if (!clk_data->name)
+                       return -ENOMEM;
 
                strcpy(clk_data->name, obj->string.pointer);
        } else {
--

Applied as 6.4 material with some edits in the subject and changelog, thanks!