mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alessandro Zanni <alessandro.zanni87@gmail.com>
To: dmitry.torokhov@gmail.com, erick.archer@outlook.com,
	zhoubinbin@loongson.cn, jay_lee@pixart.com, jon_xie@pixart.com
Cc: Alessandro Zanni <alessandro.zanni87@gmail.com>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	skhan@linuxfoundation.org, anupnewsmail@gmail.com
Subject: [PATCH] input: psmouse: Add unlock mutex before to exit psmouse_attr_set_protocol
Date: Tue,  1 Oct 2024 13:08:38 +0200	[thread overview]
Message-ID: <20241001110839.44762-1-alessandro.zanni87@gmail.com> (raw)

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


             reply	other threads:[~2024-10-01 11:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-01 11:08 Alessandro Zanni [this message]
2024-10-01 13:09 ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241001110839.44762-1-alessandro.zanni87@gmail.com \
    --to=alessandro.zanni87@gmail.com \
    --cc=anupnewsmail@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=erick.archer@outlook.com \
    --cc=jay_lee@pixart.com \
    --cc=jon_xie@pixart.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=zhoubinbin@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®