Skip to content

Commit 5ae416c

Browse files
qasim-ijazJiri Kosina
authored andcommitted
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: 83e6b40 ("HID: wacom: EKR: have the wacom resources dynamically allocated") Reviewed-by: Ping Cheng <[email protected]> Cc: [email protected] Signed-off-by: Qasim Ijaz <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 2043ae9 commit 5ae416c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/hid/wacom_sys.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2048,8 +2048,10 @@ static int wacom_initialize_remotes(struct wacom *wacom)
20482048

20492049
remote->remote_dir = kobject_create_and_add("wacom_remote",
20502050
&wacom->hdev->dev.kobj);
2051-
if (!remote->remote_dir)
2051+
if (!remote->remote_dir) {
2052+
kfifo_free(&remote->remote_fifo);
20522053
return -ENOMEM;
2054+
}
20532055

20542056
error = sysfs_create_files(remote->remote_dir, remote_unpair_attrs);
20552057

0 commit comments

Comments
 (0)