[PATCH 1/5] hp-bioscfg: Fix memory leaks in string_elements_from_package()

From: Jorge Lopez
Date: Tue Jul 25 2023 - 18:01:06 EST


Address memory leaks in hp_populate_string_elements_from_package()
and uninitialized variable errors.

Signed-off-by: Jorge Lopez <jorge.lopez2@xxxxxx>

---
Based on the latest platform-drivers-x86.git/for-next
---
drivers/platform/x86/hp/hp-bioscfg/string-attributes.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/hp/hp-bioscfg/string-attributes.c b/drivers/platform/x86/hp/hp-bioscfg/string-attributes.c
index 1b62e372fb9e..e0ecdfca4def 100644
--- a/drivers/platform/x86/hp/hp-bioscfg/string-attributes.c
+++ b/drivers/platform/x86/hp/hp-bioscfg/string-attributes.c
@@ -133,7 +133,7 @@ static int hp_populate_string_elements_from_package(union acpi_object *string_ob
char *str_value = NULL;
int value_len;
int ret = 0;
- u32 int_value;
+ u32 int_value = 0;
int elem;
int reqs;
int eloc;
@@ -171,6 +171,7 @@ static int hp_populate_string_elements_from_package(union acpi_object *string_ob
if (expected_string_types[eloc] != string_obj[elem].type) {
pr_err("Error expected type %d for elem %d, but got type %d instead\n",
expected_string_types[eloc], elem, string_obj[elem].type);
+ kfree(str_value);
return -EIO;
}

@@ -232,6 +233,7 @@ static int hp_populate_string_elements_from_package(union acpi_object *string_ob
str_value,
sizeof(string_data->common.prerequisites[reqs]));
kfree(str_value);
+ str_value = NULL;
}
break;

@@ -250,6 +252,7 @@ static int hp_populate_string_elements_from_package(union acpi_object *string_ob
}

kfree(str_value);
+ str_value = NULL;
}

exit_string_package:
--
2.34.1