HID: alps: Save a memory allocation in 't4_read_write_register()' when writing data
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Mon, 19 Mar 2018 20:53:27 +0000 (21:53 +0100)
committerJiri Kosina <jkosina@suse.cz>
Thu, 26 Apr 2018 12:33:35 +0000 (14:33 +0200)
if 'read_flag' is false, there is no need to allocate and free memory.
We can simply avoid the memory allocation and pass NULL to kfree.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-alps.c

index 925396fdf0d9ed9a0a1f46c20d8c3a5e19c6bcdd..fe8a0624d5e451278bcda53fd53a55c7fd8a5f56 100644 (file)
@@ -171,7 +171,7 @@ static int t4_read_write_register(struct hid_device *hdev, u32 address,
        int ret;
        u16 check_sum;
        u8 *input;
-       u8 *readbuf;
+       u8 *readbuf = NULL;
 
        input = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL);
        if (!input)
@@ -204,8 +204,8 @@ static int t4_read_write_register(struct hid_device *hdev, u32 address,
                goto exit;
        }
 
-       readbuf = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL);
        if (read_flag) {
+               readbuf = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL);
                if (!readbuf) {
                        ret = -ENOMEM;
                        goto exit;