]> git.karo-electronics.de Git - linux-beck.git/commitdiff
HID: alps: Fix memory leak
authorAxel Lin <axel.lin@ingics.com>
Sun, 11 Sep 2016 04:09:01 +0000 (12:09 +0800)
committerJiri Kosina <jkosina@suse.cz>
Mon, 19 Sep 2016 12:42:22 +0000 (14:42 +0200)
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 <axel.lin@ingics.com>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-alps.c

index 048befde295a2f79e8c847b87f7aebd0b93d7c0c..2808da9ed9c8e353e1cdb9f5b3a8a469de55e012 100644 (file)
@@ -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;
                }