Skip to content

Commit

Permalink
HID: alps: Fix memory leak
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
AxelLin authored and Jiri Kosina committed Sep 19, 2016
1 parent b490a85 commit 7ee2eaa
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/hid/hid-alps.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ static int u1_read_write_register(struct hid_device *hdev, u32 address,
if (read_flag) {
readbuf = kzalloc(U1_FEATURE_REPORT_LEN, GFP_KERNEL);
if (!readbuf) {
kfree(input);
return -ENOMEM;
ret = -ENOMEM;
goto exit;
}

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

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

Expand Down

0 comments on commit 7ee2eaa

Please sign in to comment.