Input: cs40l50-vibra - fix potential NULL dereference in cs40l50_upload_owt()
authorYunshui Jiang <jiangyunshui@kylinos.cn>
Fri, 4 Jul 2025 04:56:02 +0000 (21:56 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Fri, 4 Jul 2025 05:20:46 +0000 (22:20 -0700)
The cs40l50_upload_owt() function allocates memory via kmalloc()
without checking for allocation failure, which could lead to a
NULL pointer dereference.

Return -ENOMEM in case allocation fails.

Signed-off-by: Yunshui Jiang <jiangyunshui@kylinos.cn>
Fixes: c38fe1bb5d21 ("Input: cs40l50 - Add support for the CS40L50 haptic driver")
Link: https://lore.kernel.org/r/20250704024010.2353841-1-jiangyunshui@kylinos.cn
Cc: stable@vger.kernel.org
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/misc/cs40l50-vibra.c

index dce3b0ec8cf3682b16c1ae316b76281f625d4ace..330f0912363183aa458dd5c5fb16811f320e1e23 100644 (file)
@@ -238,6 +238,8 @@ static int cs40l50_upload_owt(struct cs40l50_work *work_data)
        header.data_words = len / sizeof(u32);
 
        new_owt_effect_data = kmalloc(sizeof(header) + len, GFP_KERNEL);
+       if (!new_owt_effect_data)
+               return -ENOMEM;
 
        memcpy(new_owt_effect_data, &header, sizeof(header));
        memcpy(new_owt_effect_data + sizeof(header), work_data->custom_data, len);