linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] input: psmouse: Add unlock mutex before to exit psmouse_attr_set_protocol
@ 2024-10-01 11:08 Alessandro Zanni
  2024-10-01 13:09 ` Dmitry Torokhov
  0 siblings, 1 reply; 2+ messages in thread
From: Alessandro Zanni @ 2024-10-01 11:08 UTC (permalink / raw)
  To: dmitry.torokhov, erick.archer, zhoubinbin, jay_lee, jon_xie
  Cc: Alessandro Zanni, linux-input, linux-kernel, skhan, anupnewsmail

In error handling code for "no such device" or memory already used,
release the mutex before to return.

Found with Coccinelle static analisys tool,
script: https://coccinelle.gitlabpages.inria.fr/website/rules/mut.cocci

Signed-off-by: Alessandro Zanni <alessandro.zanni87@gmail.com>
---
 drivers/input/mouse/psmouse-base.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 5a4defe9cf32..cb3a125d8d7c 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -1930,11 +1930,13 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
 
 		if (serio->drv != &psmouse_drv) {
 			input_free_device(new_dev);
+			mutex_unlock(&psmouse_mutex);
 			return -ENODEV;
 		}
 
 		if (psmouse->protocol == proto) {
 			input_free_device(new_dev);
+			mutex_unlock(&psmouse_mutex);
 			return count; /* switched by other thread */
 		}
 	}
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] input: psmouse: Add unlock mutex before to exit psmouse_attr_set_protocol
  2024-10-01 11:08 [PATCH] input: psmouse: Add unlock mutex before to exit psmouse_attr_set_protocol Alessandro Zanni
@ 2024-10-01 13:09 ` Dmitry Torokhov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Torokhov @ 2024-10-01 13:09 UTC (permalink / raw)
  To: Alessandro Zanni
  Cc: erick.archer, zhoubinbin, jay_lee, jon_xie, linux-input,
	linux-kernel, skhan, anupnewsmail

Hi Alessandro,

On Tue, Oct 01, 2024 at 01:08:38PM +0200, Alessandro Zanni wrote:
> In error handling code for "no such device" or memory already used,
> release the mutex before to return.
> 
> Found with Coccinelle static analisys tool,
> script: https://coccinelle.gitlabpages.inria.fr/website/rules/mut.cocci
> 
> Signed-off-by: Alessandro Zanni <alessandro.zanni87@gmail.com>
> ---
>  drivers/input/mouse/psmouse-base.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
> index 5a4defe9cf32..cb3a125d8d7c 100644
> --- a/drivers/input/mouse/psmouse-base.c
> +++ b/drivers/input/mouse/psmouse-base.c
> @@ -1930,11 +1930,13 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
>  
>  		if (serio->drv != &psmouse_drv) {
>  			input_free_device(new_dev);
> +			mutex_unlock(&psmouse_mutex);

I am sorry, bit this makes absolutely no sense. This mutex is taken
(and then released) in psmouse_attr_set_helper() wrapper.
psmouse_attr_set_protocol() momentarily drops and then reacquires it,
but it should not release it either failure or success parts.

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-10-01 13:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-01 11:08 [PATCH] input: psmouse: Add unlock mutex before to exit psmouse_attr_set_protocol Alessandro Zanni
2024-10-01 13:09 ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).