Skip to content

Commit f40f939

Browse files
harshimogalapalliij-intel
authored andcommitted
platform/x86: hp-bioscfg: Fix error handling in hp_add_other_attributes()
'attr_name_kobj' is allocated using kzalloc, but on all the error paths it is not freed, hence we have a memory leak. Fix the error path before kobject_init_and_add() by adding kfree(). kobject_put() must be always called after passing the object to kobject_init_and_add(). Only the error path which is immediately next to kobject_init_and_add() calls kobject_put() and not any other error path after it. Fix the error handling after kobject_init_and_add() by moving the kobject_put() into the goto label err_other_attr_init that is already used by all the error paths after kobject_init_and_add(). Fixes: a34fc32 ("platform/x86: hp-bioscfg: bioscfg") Cc: [email protected] # 6.6.x: c5dbf04: platform/x86: hp-bioscfg: Simplify return check in hp_add_other_attributes() Cc: [email protected] # 6.6.x: 5736aa9: platform/x86: hp-bioscfg: move mutex_lock() down in hp_add_other_attributes() Reported-by: kernel test robot <[email protected]> Reported-by: Dan Carpenter <[email protected]> Closes: https://lore.kernel.org/r/[email protected]/ Signed-off-by: Harshit Mogalapalli <[email protected]> [ij: Added the stable dep tags] Reviewed-by: Ilpo Järvinen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ilpo Järvinen <[email protected]>
1 parent 5736aa9 commit f40f939

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,14 +613,14 @@ static int hp_add_other_attributes(int attr_type)
613613
default:
614614
pr_err("Error: Unknown attr_type: %d\n", attr_type);
615615
ret = -EINVAL;
616-
goto err_other_attr_init;
616+
kfree(attr_name_kobj);
617+
goto unlock_drv_mutex;
617618
}
618619

619620
ret = kobject_init_and_add(attr_name_kobj, &attr_name_ktype,
620621
NULL, "%s", attr_name);
621622
if (ret) {
622623
pr_err("Error encountered [%d]\n", ret);
623-
kobject_put(attr_name_kobj);
624624
goto err_other_attr_init;
625625
}
626626

@@ -645,6 +645,8 @@ static int hp_add_other_attributes(int attr_type)
645645
return 0;
646646

647647
err_other_attr_init:
648+
kobject_put(attr_name_kobj);
649+
unlock_drv_mutex:
648650
mutex_unlock(&bioscfg_drv.mutex);
649651
kfree(obj);
650652
return ret;

0 commit comments

Comments
 (0)