Skip to content

Commit 049d75f

Browse files
mike-dunndtor
authored andcommitted
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>
1 parent c7dc657 commit 049d75f

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎drivers/input/keyboard/pxa27x_keypad.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,10 +786,17 @@ static int pxa27x_keypad_probe(struct platform_device *pdev)
786786
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
787787
input_set_capability(input_dev, EV_MSC, MSC_SCAN);
788788

789-
if (pdata)
789+
if (pdata) {
790790
error = pxa27x_keypad_build_keycode(keypad);
791-
else
791+
} else {
792792
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+
}
793800
if (error) {
794801
dev_err(&pdev->dev, "failed to build keycode\n");
795802
goto failed_put_clk;

0 commit comments

Comments
 (0)