Skip to content

Commit 7ee2eaa

Browse files
AxelLinJiri Kosina
authored andcommitted
HID: alps: Fix memory leak
A kfree(readbuf) call was missed if hid_hw_raw_request() fails, fix it. Also avoid mixing direct return with goto in the error paths. Signed-off-by: Axel Lin <[email protected]> Reviewed-by: Benjamin Tissoires <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent b490a85 commit 7ee2eaa

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/hid/hid-alps.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ static int u1_read_write_register(struct hid_device *hdev, u32 address,
139139
if (read_flag) {
140140
readbuf = kzalloc(U1_FEATURE_REPORT_LEN, GFP_KERNEL);
141141
if (!readbuf) {
142-
kfree(input);
143-
return -ENOMEM;
142+
ret = -ENOMEM;
143+
goto exit;
144144
}
145145

146146
ret = hid_hw_raw_request(hdev, U1_FEATURE_REPORT_ID, readbuf,
@@ -149,6 +149,7 @@ static int u1_read_write_register(struct hid_device *hdev, u32 address,
149149

150150
if (ret < 0) {
151151
dev_err(&hdev->dev, "failed read register (%d)\n", ret);
152+
kfree(readbuf);
152153
goto exit;
153154
}
154155

0 commit comments

Comments
 (0)