Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: cs40l50-vibra - fix potential NULL dereference in cs40l50_upload_owt()

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>

authored by

Yunshui Jiang and committed by
Dmitry Torokhov
4cf65845 a106b6a8

+2
+2
drivers/input/misc/cs40l50-vibra.c
··· 238 238 header.data_words = len / sizeof(u32); 239 239 240 240 new_owt_effect_data = kmalloc(sizeof(header) + len, GFP_KERNEL); 241 + if (!new_owt_effect_data) 242 + return -ENOMEM; 241 243 242 244 memcpy(new_owt_effect_data, &header, sizeof(header)); 243 245 memcpy(new_owt_effect_data + sizeof(header), work_data->custom_data, len);