powerpc/secvar: fix refcount leak in format_show()

[ Upstream commit d601fd24e6 ]

Refcount leak will happen when format_show returns failure in multiple
cases. Unified management of of_node_put can fix this problem.

Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220302021959.10959-1-hbh25y@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Hangyu Hua 2022-03-02 10:19:59 +08:00 committed by Greg Kroah-Hartman
parent c1f16b96c5
commit d05e4265d3

View file

@ -26,15 +26,18 @@ static ssize_t format_show(struct kobject *kobj, struct kobj_attribute *attr,
const char *format; const char *format;
node = of_find_compatible_node(NULL, NULL, "ibm,secvar-backend"); node = of_find_compatible_node(NULL, NULL, "ibm,secvar-backend");
if (!of_device_is_available(node)) if (!of_device_is_available(node)) {
return -ENODEV; rc = -ENODEV;
goto out;
}
rc = of_property_read_string(node, "format", &format); rc = of_property_read_string(node, "format", &format);
if (rc) if (rc)
return rc; goto out;
rc = sprintf(buf, "%s\n", format); rc = sprintf(buf, "%s\n", format);
out:
of_node_put(node); of_node_put(node);
return rc; return rc;