[PATCH] Input: walkera0701 - Fix possible NULL pointer dereference

From: Sudip Mukherjee
Date: Wed Oct 16 2019 - 11:08:43 EST


If walkera0701_attach() fails and input_dev is made NULL then we are
unregistering the pardevice but it still has the pointer to the dev
which has now been released. And as a result in the walkera0701_detach()
it will now try to do input_unregister_device() with a NULL pointer.
We should mark the pardevice as NULL when it is unregistered.

Reported-by: Hulk Robot <hulkci@xxxxxxxxxx>
Reported-by: Yue Haibing <yuehaibing@xxxxxxxxxx>
Fixes: 221bcb24c653 ("Input: walkera0701 - use parallel port device model")
Cc: stable@xxxxxxxxxxxxxxx # v4.4+
Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@xxxxxxxxx>
---
drivers/input/joystick/walkera0701.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/input/joystick/walkera0701.c b/drivers/input/joystick/walkera0701.c
index 56abc8c6c763..d8ae1329bf00 100644
--- a/drivers/input/joystick/walkera0701.c
+++ b/drivers/input/joystick/walkera0701.c
@@ -275,6 +275,7 @@ static void walkera0701_attach(struct parport *pp)
input_free_device(w->input_dev);
err_unregister_device:
parport_unregister_device(w->pardevice);
+ w->pardevice = NULL;
}

static void walkera0701_detach(struct parport *port)
--
2.11.0


--bvhtikaycjjwg76b--