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

Input: pxa27x_keypad - fix NULL pointer dereference

A NULL pointer dereference exception occurs in the driver probe function when
device tree is used. The pdata pointer will be NULL in this case, but the code
dereferences it in all cases. When device tree is used, a platform data
structure is allocated and initialized, and in all cases this pointer is copied
to the driver's private data, so the variable being tested should be accessed
through the driver's private data structure.

Signed-off-by: Mike Dunn <mikedunn@newsguy.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Mike Dunn and committed by
Dmitry Torokhov
049d75f7 c7dc6573

+9 -2
+9 -2
drivers/input/keyboard/pxa27x_keypad.c
··· 786 786 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); 787 787 input_set_capability(input_dev, EV_MSC, MSC_SCAN); 788 788 789 - if (pdata) 789 + if (pdata) { 790 790 error = pxa27x_keypad_build_keycode(keypad); 791 - else 791 + } else { 792 792 error = pxa27x_keypad_build_keycode_from_dt(keypad); 793 + /* 794 + * Data that we get from DT resides in dynamically 795 + * allocated memory so we need to update our pdata 796 + * pointer. 797 + */ 798 + pdata = keypad->pdata; 799 + } 793 800 if (error) { 794 801 dev_err(&pdev->dev, "failed to build keycode\n"); 795 802 goto failed_put_clk;