Skip to content

Commit 981368e

Browse files
Wer-Wolfjwrdegoede
authored andcommitted
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 7295a99 ("platform/x86: dell-sysman: Fix reference leak"), so it seems that the bug was copied from that driver. Compile-tested only. Fixes: a34fc32 ("platform/x86: hp-bioscfg: bioscfg") Suggested-by: Ilpo Järvinen <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Armin Wolf <[email protected]> Reviewed-by: Jorge Lopez <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Hans de Goede <[email protected]>
1 parent 528ab3e commit 981368e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ static int hp_init_bios_package_attribute(enum hp_wmi_data_type attr_type,
659659
const char *guid, int min_elements,
660660
int instance_id)
661661
{
662-
struct kobject *attr_name_kobj;
662+
struct kobject *attr_name_kobj, *duplicate;
663663
union acpi_object *elements;
664664
struct kset *temp_kset;
665665

@@ -704,8 +704,11 @@ static int hp_init_bios_package_attribute(enum hp_wmi_data_type attr_type,
704704
}
705705

706706
/* All duplicate attributes found are ignored */
707-
if (kset_find_obj(temp_kset, str_value)) {
707+
duplicate = kset_find_obj(temp_kset, str_value);
708+
if (duplicate) {
708709
pr_debug("Duplicate attribute name found - %s\n", str_value);
710+
/* kset_find_obj() returns a reference */
711+
kobject_put(duplicate);
709712
goto pack_attr_exit;
710713
}
711714

@@ -768,7 +771,7 @@ static int hp_init_bios_buffer_attribute(enum hp_wmi_data_type attr_type,
768771
const char *guid, int min_elements,
769772
int instance_id)
770773
{
771-
struct kobject *attr_name_kobj;
774+
struct kobject *attr_name_kobj, *duplicate;
772775
struct kset *temp_kset;
773776
char str[MAX_BUFF_SIZE];
774777

@@ -794,8 +797,11 @@ static int hp_init_bios_buffer_attribute(enum hp_wmi_data_type attr_type,
794797
temp_kset = bioscfg_drv.main_dir_kset;
795798

796799
/* All duplicate attributes found are ignored */
797-
if (kset_find_obj(temp_kset, str)) {
800+
duplicate = kset_find_obj(temp_kset, str);
801+
if (duplicate) {
798802
pr_debug("Duplicate attribute name found - %s\n", str);
803+
/* kset_find_obj() returns a reference */
804+
kobject_put(duplicate);
799805
goto buff_attr_exit;
800806
}
801807

0 commit comments

Comments
 (0)