Skip to content

Commit c068fa4

Browse files
committed
vinput: Fix NULL pointer dereference caused by failed kzalloc allocation
When kzalloc fails to allocate memory and returns NULL, it leads to a NULL pointer dereference error later on. Add a check for the return value of kzalloc. When kzalloc fails to allocate memory, it prints an error message and returns ERR_PTR(-ENOMEM).
1 parent 1e26743 commit c068fa4

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

examples/vinput.c

+5
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ static struct vinput *vinput_alloc_vdevice(void)
177177
int err;
178178
struct vinput *vinput = kzalloc(sizeof(struct vinput), GFP_KERNEL);
179179

180+
if (!vinput) {
181+
pr_err("vinput: Cannot allocate vinput input device\n");
182+
return ERR_PTR(-ENOMEM);
183+
}
184+
180185
try_module_get(THIS_MODULE);
181186

182187
spin_lock_init(&vinput->lock);

0 commit comments

Comments
 (0)