Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

firmware: dmi-sysfs: Fix memory leak in dmi_sysfs_register_handle

kobject_init_and_add() takes reference even when it fails.
According to the doc of kobject_init_and_add()

If this function returns an error, kobject_put() must be called to
properly clean up the memory associated with the object.

Fix this issue by calling kobject_put().

Fixes: 948af1f0bbc8 ("firmware: Basic dmi-sysfs support")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Link: https://lore.kernel.org/r/20220511071421.9769-1-linmq006@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Miaoqian Lin and committed by
Greg Kroah-Hartman
660ba678 077f5d90

+1 -1
+1 -1
drivers/firmware/dmi-sysfs.c
··· 604 604 "%d-%d", dh->type, entry->instance); 605 605 606 606 if (*ret) { 607 - kfree(entry); 607 + kobject_put(&entry->kobj); 608 608 return; 609 609 } 610 610