[PATCH] acpi: check for null return of devm_kzalloc in fch_misc_setup

Kang Chen posted 1 patch 2 years, 6 months ago
drivers/acpi/acpi_apd.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] acpi: check for null return of devm_kzalloc in fch_misc_setup
Posted by Kang Chen 2 years, 6 months ago
devm_kzalloc may fail, clk_data->name might be null and will
cause illegal address access later.

Signed-off-by: Kang Chen <void0red@gmail.com>
---
 drivers/acpi/acpi_apd.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
index 3bbe2276c..80f945cbe 100644
--- a/drivers/acpi/acpi_apd.c
+++ b/drivers/acpi/acpi_apd.c
@@ -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 {
-- 
2.34.1
Re: [PATCH] acpi: check for null return of devm_kzalloc in fch_misc_setup
Posted by Rafael J. Wysocki 2 years, 5 months ago
On Sun, Feb 26, 2023 at 6:54 AM Kang Chen <void0red@gmail.com> wrote:
>
> devm_kzalloc may fail, clk_data->name might be null and will
> cause illegal address access later.
>
> Signed-off-by: Kang Chen <void0red@gmail.com>
> ---
>  drivers/acpi/acpi_apd.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
> index 3bbe2276c..80f945cbe 100644
> --- a/drivers/acpi/acpi_apd.c
> +++ b/drivers/acpi/acpi_apd.c
> @@ -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!