2023-07-25 22:18:06

by Jorge Lopez

[permalink] [raw]
Subject: [PATCH 0/5] hp-bioscfg: Address memory leaks and uninitialized variable errors

Submit individual patches to address memory leaks and uninitialized
variable errors for each source file listed below.

- hp_populate_string_elements_from_package()
drivers/platform/x86/hp/hp-bioscfg/string-attributes.c

- hp_populate_ordered_list_elements_from_package()
drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c

- hp_populate_integer_elements_from_package()
drivers/platform/x86/hp/hp-bioscfg/int-attributes.c

- hp_populate_enumeration_elements_from_package()
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c

- hp_populate_password_elements_from_package()
drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c

Changes were tested with a HP EliteBook x360 1030 G3


Jorge Lopez (5):
hp-bioscfg: Fix memory leaks in string_elements_from_package()
hp-bioscfg: Fix memory leaks in ordered_list_elements_from_package
hp-bioscfg: Fix memory leaks in integer_elements_from_package
hp-bioscfg: Fix memory leaks in enumeration_elements_from_package()
hp-bioscfg: Fix memory leaks in password_elements_from_package()

drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c | 8 +++++++-
drivers/platform/x86/hp/hp-bioscfg/int-attributes.c | 7 ++++++-
.../platform/x86/hp/hp-bioscfg/order-list-attributes.c | 10 ++++++++--
.../platform/x86/hp/hp-bioscfg/passwdobj-attributes.c | 10 +++++++++-
drivers/platform/x86/hp/hp-bioscfg/string-attributes.c | 5 ++++-
5 files changed, 34 insertions(+), 6 deletions(-)

--
2.34.1



2023-07-25 22:36:05

by Jorge Lopez

[permalink] [raw]
Subject: [PATCH 4/5] hp-bioscfg: Fix memory leaks in enumeration_elements_from_package()

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

Signed-off-by: Jorge Lopez <[email protected]>

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

diff --git a/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c b/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
index b1b241f0205a..7f77963cd7fa 100644
--- a/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
+++ b/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
@@ -129,7 +129,7 @@ static int hp_populate_enumeration_elements_from_package(union acpi_object *enum
char *str_value = NULL;
int value_len;
u32 size = 0;
- u32 int_value;
+ u32 int_value = 0;
int elem = 0;
int reqs;
int pos_values;
@@ -164,6 +164,7 @@ static int hp_populate_enumeration_elements_from_package(union acpi_object *enum
if (expected_enum_types[eloc] != enum_obj[elem].type) {
pr_err("Error expected type %d for elem %d, but got type %d instead\n",
expected_enum_types[eloc], elem, enum_obj[elem].type);
+ kfree(str_value);
return -EIO;
}

@@ -224,6 +225,7 @@ static int hp_populate_enumeration_elements_from_package(union acpi_object *enum
sizeof(enum_data->common.prerequisites[reqs]));

kfree(str_value);
+ str_value = NULL;
}
break;

@@ -275,6 +277,9 @@ static int hp_populate_enumeration_elements_from_package(union acpi_object *enum
strscpy(enum_data->possible_values[pos_values],
str_value,
sizeof(enum_data->possible_values[pos_values]));
+
+ kfree(str_value);
+ str_value = NULL;
}
break;
default:
@@ -283,6 +288,7 @@ static int hp_populate_enumeration_elements_from_package(union acpi_object *enum
}

kfree(str_value);
+ str_value = NULL;
}

exit_enumeration_package:
--
2.34.1


2023-07-25 22:52:35

by Jorge Lopez

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

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

Signed-off-by: Jorge Lopez <[email protected]>

---
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


2023-07-26 15:51:16

by Hans de Goede

[permalink] [raw]
Subject: Re: [PATCH 0/5] hp-bioscfg: Address memory leaks and uninitialized variable errors

Hi Jorge,

On 7/26/23 00:00, Jorge Lopez wrote:
> Submit individual patches to address memory leaks and uninitialized
> variable errors for each source file listed below.
>
> - hp_populate_string_elements_from_package()
> drivers/platform/x86/hp/hp-bioscfg/string-attributes.c
>
> - hp_populate_ordered_list_elements_from_package()
> drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c
>
> - hp_populate_integer_elements_from_package()
> drivers/platform/x86/hp/hp-bioscfg/int-attributes.c
>
> - hp_populate_enumeration_elements_from_package()
> drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
>
> - hp_populate_password_elements_from_package()
> drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c
>
> Changes were tested with a HP EliteBook x360 1030 G3

Thank you for the patches fixing this.

I'm going to wait a bit with applying these to give other people who have looked at these issues a chance to review these patches (added Dan Carpenter and Christophe JAILLET to the To: list).

For future patches please write one patch for each issue you are addressing instead of one patch per file. Since the fixes are the same for all 5 files in this case that would have meant doing 2 patches:

1. To fix the memory leak errors in all 5 files
2. To fix the uninitialized variable in all 5 files.

There is no need to send a new version unless changes are requested by one of the reviewers, I'll just squash all these 5 patches into 1 patch when merging this (and keep the uninitialized variable changes as part of the same patch).

Also these patches should have something like this as part of the commit msg (directly above your Signed-off-by:) :

Reported-by: Dan Carpenter <[email protected]>
Closes: https://lore.kernel.org/platform-driver-x86/[email protected]/

Regards,

Hans








>
>
> Jorge Lopez (5):
> hp-bioscfg: Fix memory leaks in string_elements_from_package()
> hp-bioscfg: Fix memory leaks in ordered_list_elements_from_package
> hp-bioscfg: Fix memory leaks in integer_elements_from_package
> hp-bioscfg: Fix memory leaks in enumeration_elements_from_package()
> hp-bioscfg: Fix memory leaks in password_elements_from_package()
>
> drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c | 8 +++++++-
> drivers/platform/x86/hp/hp-bioscfg/int-attributes.c | 7 ++++++-
> .../platform/x86/hp/hp-bioscfg/order-list-attributes.c | 10 ++++++++--
> .../platform/x86/hp/hp-bioscfg/passwdobj-attributes.c | 10 +++++++++-
> drivers/platform/x86/hp/hp-bioscfg/string-attributes.c | 5 ++++-
> 5 files changed, 34 insertions(+), 6 deletions(-)
>