Skip to contentSkip to conversation

HID: wacom: fix resource cleanup issues

PATCH RESEND Applied Qasim Ijaz 2 participants 5 messages Jun 6, 2025 – Jun 10, 2025

Subsystems (3)
lore
Share & tools
lore

Qasim Ijaz

author
#0 lore raw

cover HID: wacom: fix resource cleanup issues

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(-)
Signature · 1 line
2.39.5
author
#1 lore raw

PATCH RESEND 1/3 HID: wacom: fix memory leak on kobject creation failure

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")
---
 drivers/hid/wacom_sys.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hid/wacom_sys.c +3 -1
index eaf099b2efdb..ec5282bc69d6 100644
@@ -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);
 
Signature · 1 line
2.39.5
author
#2 lore raw

PATCH RESEND 2/3 HID: wacom: fix memory leak on sysfs attribute creation failure

In reply to Qasim Ijaz

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")
---
 drivers/hid/wacom_sys.c | 1 +
 1 file changed, 1 insertion(+)
drivers/hid/wacom_sys.c +1 -0
index ec5282bc69d6..58cbd43a37e9 100644
@@ -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;
 	}
 
Signature · 1 line
2.39.5
author
#3 lore raw

PATCH RESEND 3/3 HID: wacom: fix kobject reference count leak

In reply to Qasim Ijaz

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")
---
 drivers/hid/wacom_sys.c | 1 +
 1 file changed, 1 insertion(+)
drivers/hid/wacom_sys.c +1 -0
index 58cbd43a37e9..1257131b1e34 100644
@@ -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;
 	}
 
Signature · 1 line
2.39.5
maintainer Applied
#4 lore raw
In reply to Qasim Ijaz
Quoted 9 lines · 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(-)

Applied, thanks.

Signature · 2 lines
Jiri Kosina
SUSE Labs