[PATCH] Input: cs40l50 - fix possible NULL pointer dereference

Hongbin Ji posted 1 patch 3 months ago
drivers/input/misc/cs40l50-vibra.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH] Input: cs40l50 - fix possible NULL pointer dereference
Posted by Hongbin Ji 3 months ago
Add a NULL‐check and return ‑ENOMEM if allocation failed to prevent a kernel oops

Signed-off-by: Hongbin Ji <jhb_ee@163.com>
---
 drivers/input/misc/cs40l50-vibra.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/input/misc/cs40l50-vibra.c b/drivers/input/misc/cs40l50-vibra.c
index dce3b0ec8cf3..61d87bc5f175 100644
--- a/drivers/input/misc/cs40l50-vibra.c
+++ b/drivers/input/misc/cs40l50-vibra.c
@@ -238,6 +238,9 @@ 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.34.1

Re: [PATCH] Input: cs40l50 - fix possible NULL pointer dereference
Posted by Dmitry Torokhov 3 months ago
Hi Hongbin,

On Fri, Jul 04, 2025 at 10:58:38AM +0800, Hongbin Ji wrote:
> Add a NULL‐check and return ‑ENOMEM if allocation failed to prevent a kernel oops

Thank you for your submission but I already have a similar patch
applied.

Thanks.

-- 
Dmitry