From: Jianyue Wu <wujianyue000@xxxxxxxxx> Add a NULL pointer check after kmalloc when allocating memory for OWT effect data in cs40l50_upload_owt(). If the allocation fails, print an error message and return -ENOMEM to prevent dereferencing a NULL pointer. Signed-off-by: Jianyue Wu <wujianyue000@xxxxxxxxx> --- drivers/input/misc/cs40l50-vibra.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/input/misc/cs40l50-vibra.c b/drivers/input/misc/cs40l50-vibra.c index dce3b0ec8cf3..330f09123631 100644 --- a/drivers/input/misc/cs40l50-vibra.c +++ b/drivers/input/misc/cs40l50-vibra.c @@ -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); -- 2.48.1