]> git.baikalelectronics.ru Git - kernel.git/commitdiff
staging: gasket: Fix mapping refcnt leak when put attribute fails
authorXiyu Yang <xiyuyang19@fudan.edu.cn>
Thu, 23 Apr 2020 05:14:55 +0000 (13:14 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 23 Apr 2020 11:37:25 +0000 (13:37 +0200)
gasket_sysfs_put_attr() invokes get_mapping(), which returns a reference
of the specified gasket_sysfs_mapping object to "mapping" with increased
refcnt.

When gasket_sysfs_put_attr() returns, local variable "mapping" becomes
invalid, so the refcount should be decreased to keep refcount balanced.

The reference counting issue happens in one path of
gasket_sysfs_put_attr(). When mapping attribute is unknown, the function
forgets to decrease the refcnt increased by get_mapping(), causing a
refcnt leak.

Fix this issue by calling put_mapping() when put attribute fails due to
unknown attribute.

Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
Link: https://lore.kernel.org/r/1587618895-13660-1-git-send-email-xiyuyang19@fudan.edu.cn
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/gasket/gasket_sysfs.c

index a2d67c28f530c8991887a4ea64de2254613b2e79..f24edc38c27b46c15539c383affaf392248a8e3a 100644 (file)
@@ -340,6 +340,7 @@ void gasket_sysfs_put_attr(struct device *device,
 
        dev_err(device, "Unable to put unknown attribute: %s\n",
                attr->attr.attr.name);
+       put_mapping(mapping);
 }
 EXPORT_SYMBOL(gasket_sysfs_put_attr);