lkml.org 
[lkml]   [2020]   [Aug]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH] [v2] HID: elan: Fix memleak in elan_input_configured
    Date
    When input_mt_init_slots() fails, input should be freed
    to prevent memleak. When input_register_device() fails,
    we should call input_mt_destroy_slots() to free memory
    allocated by input_mt_init_slots().

    Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
    ---

    Changelog:

    v2: - Add input_mt_destroy_slots() on failure of
    input_register_device().
    ---
    drivers/hid/hid-elan.c | 2 ++
    1 file changed, 2 insertions(+)

    diff --git a/drivers/hid/hid-elan.c b/drivers/hid/hid-elan.c
    index 45c4f888b7c4..dae193749d44 100644
    --- a/drivers/hid/hid-elan.c
    +++ b/drivers/hid/hid-elan.c
    @@ -188,6 +188,7 @@ static int elan_input_configured(struct hid_device *hdev, struct hid_input *hi)
    ret = input_mt_init_slots(input, ELAN_MAX_FINGERS, INPUT_MT_POINTER);
    if (ret) {
    hid_err(hdev, "Failed to init elan MT slots: %d\n", ret);
    + input_free_device(input);
    return ret;
    }

    @@ -198,6 +199,7 @@ static int elan_input_configured(struct hid_device *hdev, struct hid_input *hi)
    if (ret) {
    hid_err(hdev, "Failed to register elan input device: %d\n",
    ret);
    + input_mt_destroy_slots(input);
    input_free_device(input);
    return ret;
    }
    --
    2.17.1
    \
     
     \ /
      Last update: 2020-08-31 11:07    [W:3.177 / U:0.628 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site