HID: wacom: fix resource cleanup issues
Subsystems (3)
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
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.
--- drivers/hid/wacom_sys.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hid/wacom_sys.c +3 -1
@@ -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
PATCH RESEND 2/3 HID: wacom: fix memory leak on sysfs attribute creation failure
In reply to Qasim IjazWhen 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.
--- drivers/hid/wacom_sys.c | 1 + 1 file changed, 1 insertion(+)
drivers/hid/wacom_sys.c +1 -0
@@ -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
PATCH RESEND 3/3 HID: wacom: fix kobject reference count leak
In reply to Qasim IjazWhen 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.
--- drivers/hid/wacom_sys.c | 1 + 1 file changed, 1 insertion(+)
drivers/hid/wacom_sys.c +1 -0
@@ -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
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 leakdrivers/hid/wacom_sys.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
Applied, thanks.
Signature · 2 lines
Jiri Kosina SUSE Labs