DriverDev-Devel Archive on
 help / color / Atom feed
* [PATCH] staging: gasket: Fix mapping refcnt leak when register/store fails
@ 2020-04-23  5:15 Xiyu Yang
  0 siblings, 0 replies; only message in thread
From: Xiyu Yang @ 2020-04-23  5:15 UTC (permalink / raw)
  To: Rob Springer, Todd Poynor, Ben Chan, Greg Kroah-Hartman, devel,
  Cc: Xin Tan, yuanxzhang, kjlu, Xiyu Yang

gasket_sysfs_register_store() invokes get_mapping(), which returns a
reference of the specified gasket_sysfs_mapping object to "mapping" with
increased refcnt.

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

The reference counting issue happens in one exception handling path of
gasket_sysfs_register_store(). When gasket_dev is NULL, the function
forgets to decrease the refcnt increased by get_mapping(), causing a
refcnt leak.

Fix this issue by calling put_mapping() when gasket_dev is NULL.

Signed-off-by: Xiyu Yang <>
Signed-off-by: Xin Tan <>
 drivers/staging/gasket/gasket_sysfs.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/gasket/gasket_sysfs.c b/drivers/staging/gasket/gasket_sysfs.c
index f24edc38c27b..b4aa8c2ba2c0 100644
--- a/drivers/staging/gasket/gasket_sysfs.c
+++ b/drivers/staging/gasket/gasket_sysfs.c
@@ -374,6 +374,7 @@ ssize_t gasket_sysfs_register_store(struct device *device,
 	gasket_dev = mapping->gasket_dev;
 	if (!gasket_dev) {
 		dev_err(device, "Device driver may have been removed\n");
+		put_mapping(mapping);
 		return 0;

devel mailing list

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-23  5:15 [PATCH] staging: gasket: Fix mapping refcnt leak when register/store fails Xiyu Yang

DriverDev-Devel Archive on

Archives are clonable:
	git clone --mirror driverdev-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 driverdev-devel driverdev-devel/ \
	public-inbox-index driverdev-devel

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone