Skip to contentSkip to conversation

HID: alps: Fix memory leak

PATCH Applied Axel Lin 3 participants 3 messages Sep 11, 2016 – Sep 19, 2016 HID

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 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.

---
 drivers/hid/hid-alps.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hid/hid-alps.c +3 -2
index 048befd..2808da9 100644
@@ -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,
@@ -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;
 		}
 
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Axel Lin

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.

Cheers,
Benjamin

Quoted 30 lines
---
 drivers/hid/hid-alps.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hid/hid-alps.c +3 -2
index 048befd..2808da9 100644
@@ -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,
@@ -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;
 		}
 
Signature · 1 line
2.7.4
maintainer Applied
#2 lore raw
In reply to Axel Lin
Quoted 2 lines · Axel Lin

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.

Applied to hid.git#for-4.8/upstream-fixes, thanks.

Signature · 2 lines
Jiri Kosina
SUSE Labs