# \[PATCH\] Input: psmouse - fix psmouse detect function is a NULL pointer

- Subsystems: INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN) DRIVERS, THE REST
- Maintainers: Dmitry Torokhov, Linus Torvalds
- List: linux-input
- 2 messages, 2 authors
- Page: https://ratatoskr.run/linux-input/2021/05/1382789/t

## \[PATCH\] Input: psmouse - fix psmouse detect function is a NULL pointer

- From: Qiang Ma \<hidden\>
- Date: 2021-05-19 03:28:09 
- Message: https://ratatoskr.run/linux-input/2021/05/1382789.md

```text
Add a check for psmouse_do_detect(), when the detect is NULL pointer,
returning false, avoiding this possible NULL pointer exception.

Signed-off-by: Qiang Ma <redacted>
---
 drivers/input/mouse/psmouse-base.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 0b4a3039f312..86b095728587 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -1006,6 +1006,9 @@ static bool psmouse_do_detect(int (*detect)(struct psmouse *, bool),
 	if (set_properties)
 		psmouse_apply_defaults(psmouse);
 
+	if (!detect)
+		return false;
+
 	return detect(psmouse, set_properties) == 0;
 }
 
-- 
2.20.1



```

## Re: \[PATCH\] Input: psmouse - fix psmouse detect function is a NULL pointer

- From: Dmitry Torokhov \<dmitry.torokhov@gmail.com\>
- Date: 2021-06-02 05:13:54 
- Message: https://ratatoskr.run/linux-input/2021/06/1399308.md

```text
Hi Qiang,

On Wed, May 19, 2021 at 11:23:35AM +0800, Qiang Ma wrote:
> Add a check for psmouse_do_detect(), when the detect is NULL pointer,
> returning false, avoiding this possible NULL pointer exception.
> 
> Signed-off-by: Qiang Ma <redacted>
> ---
>  drivers/input/mouse/psmouse-base.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
> index 0b4a3039f312..86b095728587 100644
> --- a/drivers/input/mouse/psmouse-base.c
> +++ b/drivers/input/mouse/psmouse-base.c
> @@ -1006,6 +1006,9 @@ static bool psmouse_do_detect(int (*detect)(struct psmouse *, bool),
>  	if (set_properties)
>  		psmouse_apply_defaults(psmouse);
>  
> +	if (!detect)
> +		return false;

There are no protocols that do not define detect() method, so this
condition is not possible.

> +
>  	return detect(psmouse, set_properties) == 0;
>  }
>  

Thanks.

-- 
Dmitry
```
