Skip to content

Commit

Permalink
vinput: Fix NULL pointer dereference caused by failed kzalloc allocation
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
visitorckw committed May 8, 2024
1 parent 1e26743 commit c068fa4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/vinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ static struct vinput *vinput_alloc_vdevice(void)
int err;
struct vinput *vinput = kzalloc(sizeof(struct vinput), GFP_KERNEL);

if (!vinput) {
pr_err("vinput: Cannot allocate vinput input device\n");
return ERR_PTR(-ENOMEM);
}

try_module_get(THIS_MODULE);

spin_lock_init(&vinput->lock);
Expand Down

0 comments on commit c068fa4

Please sign in to comment.