linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] HID: wacom: fix resource cleanup issues
@ 2025-04-30 17:39 Qasim Ijaz
  2025-04-30 17:39 ` [PATCH 1/3] HID: wacom: fix memory leak on kobject creation failure Qasim Ijaz
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Qasim Ijaz @ 2025-04-30 17:39 UTC (permalink / raw)
  To: ping.cheng, jason.gerecke, jikos, bentiss, linux-input,
	linux-kernel
  Cc: Qasim Ijaz

Fix a few resource cleanup issues.

Qasim Ijaz (3):
  fix memory leak on kobject creation failure
  fix memory leak on sysfs attribute creation failure
  fix kobject reference count leak

 drivers/hid/wacom_sys.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

-- 
2.39.5


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] HID: wacom: fix memory leak on kobject creation failure
  2025-04-30 17:39 [PATCH 0/3] HID: wacom: fix resource cleanup issues Qasim Ijaz
@ 2025-04-30 17:39 ` Qasim Ijaz
  2025-04-30 17:39 ` [PATCH 2/3] HID: wacom: fix memory leak on sysfs attribute " Qasim Ijaz
  2025-04-30 17:39 ` [PATCH 3/3] HID: wacom: fix kobject reference count leak Qasim Ijaz
  2 siblings, 0 replies; 4+ messages in thread
From: Qasim Ijaz @ 2025-04-30 17:39 UTC (permalink / raw)
  To: ping.cheng, jason.gerecke, jikos, bentiss, linux-input,
	linux-kernel
  Cc: Qasim Ijaz, stable

During wacom_initialize_remotes() a fifo buffer is allocated
with kfifo_alloc() and later a cleanup action is registered
during devm_add_action_or_reset() to clean it up.

However if the code fails to create a kobject and register it
with sysfs the code simply returns -ENOMEM before the cleanup
action is registered leading to a memory leak.

Fix this by ensuring the fifo is freed when the kobject creation
and registration process fails.

Fixes: 83e6b40e2de6 ("HID: wacom: EKR: have the wacom resources dynamically allocated")
Cc: stable@vger.kernel.org
Signed-off-by: Qasim Ijaz <qasdev00@gmail.com> 
---
 drivers/hid/wacom_sys.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index eaf099b2efdb..ec5282bc69d6 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -2048,8 +2048,10 @@ static int wacom_initialize_remotes(struct wacom *wacom)
 
 	remote->remote_dir = kobject_create_and_add("wacom_remote",
 						    &wacom->hdev->dev.kobj);
-	if (!remote->remote_dir)
+	if (!remote->remote_dir) {
+		kfifo_free(&remote->remote_fifo);
 		return -ENOMEM;
+	}
 
 	error = sysfs_create_files(remote->remote_dir, remote_unpair_attrs);
 
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] HID: wacom: fix memory leak on sysfs attribute creation failure
  2025-04-30 17:39 [PATCH 0/3] HID: wacom: fix resource cleanup issues Qasim Ijaz
  2025-04-30 17:39 ` [PATCH 1/3] HID: wacom: fix memory leak on kobject creation failure Qasim Ijaz
@ 2025-04-30 17:39 ` Qasim Ijaz
  2025-04-30 17:39 ` [PATCH 3/3] HID: wacom: fix kobject reference count leak Qasim Ijaz
  2 siblings, 0 replies; 4+ messages in thread
From: Qasim Ijaz @ 2025-04-30 17:39 UTC (permalink / raw)
  To: ping.cheng, jason.gerecke, jikos, bentiss, linux-input,
	linux-kernel
  Cc: Qasim Ijaz, stable

When sysfs_create_files() fails during wacom_initialize_remotes() the
fifo buffer is not freed leading to a memory leak.

Fix this by calling kfifo_free() before returning.

Fixes: 83e6b40e2de6 ("HID: wacom: EKR: have the wacom resources dynamically allocated")
Cc: stable@vger.kernel.org
Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
---
 drivers/hid/wacom_sys.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index ec5282bc69d6..58cbd43a37e9 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -2058,6 +2058,7 @@ static int wacom_initialize_remotes(struct wacom *wacom)
 	if (error) {
 		hid_err(wacom->hdev,
 			"cannot create sysfs group err: %d\n", error);
+		kfifo_free(&remote->remote_fifo);
 		return error;
 	}
 
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] HID: wacom: fix kobject reference count leak
  2025-04-30 17:39 [PATCH 0/3] HID: wacom: fix resource cleanup issues Qasim Ijaz
  2025-04-30 17:39 ` [PATCH 1/3] HID: wacom: fix memory leak on kobject creation failure Qasim Ijaz
  2025-04-30 17:39 ` [PATCH 2/3] HID: wacom: fix memory leak on sysfs attribute " Qasim Ijaz
@ 2025-04-30 17:39 ` Qasim Ijaz
  2 siblings, 0 replies; 4+ messages in thread
From: Qasim Ijaz @ 2025-04-30 17:39 UTC (permalink / raw)
  To: ping.cheng, jason.gerecke, jikos, bentiss, linux-input,
	linux-kernel
  Cc: Qasim Ijaz, stable

When sysfs_create_files() fails in wacom_initialize_remotes() the error
is returned and the cleanup action will not have been registered yet.

As a result the kobject’s refcount is never dropped, so the
kobject can never be freed leading to a reference leak.

Fix this by calling kobject_put() before returning.

Fixes: 83e6b40e2de6 ("HID: wacom: EKR: have the wacom resources dynamically allocated")
Cc: stable@vger.kernel.org
Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
---
 drivers/hid/wacom_sys.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index 58cbd43a37e9..1257131b1e34 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -2059,6 +2059,7 @@ static int wacom_initialize_remotes(struct wacom *wacom)
 		hid_err(wacom->hdev,
 			"cannot create sysfs group err: %d\n", error);
 		kfifo_free(&remote->remote_fifo);
+		kobject_put(remote->remote_dir);
 		return error;
 	}
 
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-04-30 17:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-30 17:39 [PATCH 0/3] HID: wacom: fix resource cleanup issues Qasim Ijaz
2025-04-30 17:39 ` [PATCH 1/3] HID: wacom: fix memory leak on kobject creation failure Qasim Ijaz
2025-04-30 17:39 ` [PATCH 2/3] HID: wacom: fix memory leak on sysfs attribute " Qasim Ijaz
2025-04-30 17:39 ` [PATCH 3/3] HID: wacom: fix kobject reference count leak Qasim Ijaz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).