linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND 0/3] HID: wacom: fix resource cleanup issues
@ 2025-06-06 18:49 Qasim Ijaz
  2025-06-06 18:49 ` [PATCH RESEND 1/3] HID: wacom: fix memory leak on kobject creation failure Qasim Ijaz
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Qasim Ijaz @ 2025-06-06 18:49 UTC (permalink / raw)
  To: Ping Cheng, Jason Gerecke, Jiri Kosina, Benjamin Tissoires,
	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] 5+ messages in thread

* [PATCH RESEND 1/3] HID: wacom: fix memory leak on kobject creation failure
  2025-06-06 18:49 [PATCH RESEND 0/3] HID: wacom: fix resource cleanup issues Qasim Ijaz
@ 2025-06-06 18:49 ` Qasim Ijaz
  2025-06-06 18:49 ` [PATCH RESEND 2/3] HID: wacom: fix memory leak on sysfs attribute " Qasim Ijaz
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Qasim Ijaz @ 2025-06-06 18:49 UTC (permalink / raw)
  To: Ping Cheng, Jason Gerecke, Jiri Kosina, Benjamin Tissoires,
	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")
Reviewed-by: Ping Cheng <ping.cheng@wacom.com>
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] 5+ messages in thread

* [PATCH RESEND 2/3] HID: wacom: fix memory leak on sysfs attribute creation failure
  2025-06-06 18:49 [PATCH RESEND 0/3] HID: wacom: fix resource cleanup issues Qasim Ijaz
  2025-06-06 18:49 ` [PATCH RESEND 1/3] HID: wacom: fix memory leak on kobject creation failure Qasim Ijaz
@ 2025-06-06 18:49 ` Qasim Ijaz
  2025-06-06 18:49 ` [PATCH RESEND 3/3] HID: wacom: fix kobject reference count leak Qasim Ijaz
  2025-06-10 19:10 ` [PATCH RESEND 0/3] HID: wacom: fix resource cleanup issues Jiri Kosina
  3 siblings, 0 replies; 5+ messages in thread
From: Qasim Ijaz @ 2025-06-06 18:49 UTC (permalink / raw)
  To: Ping Cheng, Jason Gerecke, Jiri Kosina, Benjamin Tissoires,
	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")
Reviewed-by: Ping Cheng <ping.cheng@wacom.com>
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] 5+ messages in thread

* [PATCH RESEND 3/3] HID: wacom: fix kobject reference count leak
  2025-06-06 18:49 [PATCH RESEND 0/3] HID: wacom: fix resource cleanup issues Qasim Ijaz
  2025-06-06 18:49 ` [PATCH RESEND 1/3] HID: wacom: fix memory leak on kobject creation failure Qasim Ijaz
  2025-06-06 18:49 ` [PATCH RESEND 2/3] HID: wacom: fix memory leak on sysfs attribute " Qasim Ijaz
@ 2025-06-06 18:49 ` Qasim Ijaz
  2025-06-10 19:10 ` [PATCH RESEND 0/3] HID: wacom: fix resource cleanup issues Jiri Kosina
  3 siblings, 0 replies; 5+ messages in thread
From: Qasim Ijaz @ 2025-06-06 18:49 UTC (permalink / raw)
  To: Ping Cheng, Jason Gerecke, Jiri Kosina, Benjamin Tissoires,
	linux-input, linux-kernel
  Cc: Qasim Ijaz, stable

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=n, Size: 1014 bytes --]

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")
Acked-by: Ping Cheng <ping.cheng@wacom.com>
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] 5+ messages in thread

* Re: [PATCH RESEND 0/3] HID: wacom: fix resource cleanup issues
  2025-06-06 18:49 [PATCH RESEND 0/3] HID: wacom: fix resource cleanup issues Qasim Ijaz
                   ` (2 preceding siblings ...)
  2025-06-06 18:49 ` [PATCH RESEND 3/3] HID: wacom: fix kobject reference count leak Qasim Ijaz
@ 2025-06-10 19:10 ` Jiri Kosina
  3 siblings, 0 replies; 5+ messages in thread
From: Jiri Kosina @ 2025-06-10 19:10 UTC (permalink / raw)
  To: Qasim Ijaz
  Cc: Ping Cheng, Jason Gerecke, Benjamin Tissoires, linux-input,
	linux-kernel

On Fri, 6 Jun 2025, Qasim Ijaz wrote:

> 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.

-- 
Jiri Kosina
SUSE Labs


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

end of thread, other threads:[~2025-06-10 19:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-06 18:49 [PATCH RESEND 0/3] HID: wacom: fix resource cleanup issues Qasim Ijaz
2025-06-06 18:49 ` [PATCH RESEND 1/3] HID: wacom: fix memory leak on kobject creation failure Qasim Ijaz
2025-06-06 18:49 ` [PATCH RESEND 2/3] HID: wacom: fix memory leak on sysfs attribute " Qasim Ijaz
2025-06-06 18:49 ` [PATCH RESEND 3/3] HID: wacom: fix kobject reference count leak Qasim Ijaz
2025-06-10 19:10 ` [PATCH RESEND 0/3] HID: wacom: fix resource cleanup issues Jiri Kosina

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).