Commit 981368e1 authored by Armin Wolf's avatar Armin Wolf Committed by Hans de Goede

platform/x86: hp-bioscfg: Fix reference leak

If a duplicate attribute is found using kset_find_obj(), a reference
to that attribute is returned which needs to be disposed accordingly
using kobject_put(). Use kobject_put() to dispose the duplicate
attribute in such a case.
As a side note, a very similar bug was fixed in
commit 7295a996 ("platform/x86: dell-sysman: Fix reference leak"),
so it seems that the bug was copied from that driver.

Compile-tested only.

Fixes: a34fc329 ("platform/x86: hp-bioscfg: bioscfg")
Suggested-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: default avatarArmin Wolf <W_Armin@gmx.de>
Reviewed-by: default avatarJorge Lopez <jorge.lopez2@hp.com>
Link: https://lore.kernel.org/r/20230925142819.74525-3-W_Armin@gmx.deReviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
parent 528ab3e6
...@@ -659,7 +659,7 @@ static int hp_init_bios_package_attribute(enum hp_wmi_data_type attr_type, ...@@ -659,7 +659,7 @@ static int hp_init_bios_package_attribute(enum hp_wmi_data_type attr_type,
const char *guid, int min_elements, const char *guid, int min_elements,
int instance_id) int instance_id)
{ {
struct kobject *attr_name_kobj; struct kobject *attr_name_kobj, *duplicate;
union acpi_object *elements; union acpi_object *elements;
struct kset *temp_kset; struct kset *temp_kset;
...@@ -704,8 +704,11 @@ static int hp_init_bios_package_attribute(enum hp_wmi_data_type attr_type, ...@@ -704,8 +704,11 @@ static int hp_init_bios_package_attribute(enum hp_wmi_data_type attr_type,
} }
/* All duplicate attributes found are ignored */ /* All duplicate attributes found are ignored */
if (kset_find_obj(temp_kset, str_value)) { duplicate = kset_find_obj(temp_kset, str_value);
if (duplicate) {
pr_debug("Duplicate attribute name found - %s\n", str_value); pr_debug("Duplicate attribute name found - %s\n", str_value);
/* kset_find_obj() returns a reference */
kobject_put(duplicate);
goto pack_attr_exit; goto pack_attr_exit;
} }
...@@ -768,7 +771,7 @@ static int hp_init_bios_buffer_attribute(enum hp_wmi_data_type attr_type, ...@@ -768,7 +771,7 @@ static int hp_init_bios_buffer_attribute(enum hp_wmi_data_type attr_type,
const char *guid, int min_elements, const char *guid, int min_elements,
int instance_id) int instance_id)
{ {
struct kobject *attr_name_kobj; struct kobject *attr_name_kobj, *duplicate;
struct kset *temp_kset; struct kset *temp_kset;
char str[MAX_BUFF_SIZE]; char str[MAX_BUFF_SIZE];
...@@ -794,8 +797,11 @@ static int hp_init_bios_buffer_attribute(enum hp_wmi_data_type attr_type, ...@@ -794,8 +797,11 @@ static int hp_init_bios_buffer_attribute(enum hp_wmi_data_type attr_type,
temp_kset = bioscfg_drv.main_dir_kset; temp_kset = bioscfg_drv.main_dir_kset;
/* All duplicate attributes found are ignored */ /* All duplicate attributes found are ignored */
if (kset_find_obj(temp_kset, str)) { duplicate = kset_find_obj(temp_kset, str);
if (duplicate) {
pr_debug("Duplicate attribute name found - %s\n", str); pr_debug("Duplicate attribute name found - %s\n", str);
/* kset_find_obj() returns a reference */
kobject_put(duplicate);
goto buff_attr_exit; goto buff_attr_exit;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment