From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: linux-input@vger.kernel.org
Cc: Hans de Goede <hansg@kernel.org>
Subject: [PATCH 4/4] Input: psmouse - use guard() for resource management
Date: Sun, 26 Jul 2026 22:08:01 -0700 [thread overview]
Message-ID: <20260727050803.1269941-4-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20260727050803.1269941-1-dmitry.torokhov@gmail.com>
Replace manual serialization with guard(mutex) and guard(serio_pause_rx)
where appropriate. This eliminates the need for explicit goto-based error
paths.
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/mouse/psmouse-base.c | 31 ++++++++++++------------------
1 file changed, 12 insertions(+), 19 deletions(-)
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index a9a110f2c860..58b9b5dd7f08 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -256,9 +256,8 @@ static inline void __psmouse_set_state(struct psmouse *psmouse, enum psmouse_sta
*/
void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state)
{
- serio_pause_rx(psmouse->ps2dev.serio);
+ guard(serio_pause_rx)(psmouse->ps2dev.serio);
__psmouse_set_state(psmouse, new_state);
- serio_continue_rx(psmouse->ps2dev.serio);
}
/*
@@ -1318,10 +1317,10 @@ static void psmouse_resync(struct work_struct *work)
bool failed = false, enabled = false;
int i;
- mutex_lock(&psmouse_mutex);
+ guard(mutex)(&psmouse_mutex);
if (psmouse->state != PSMOUSE_RESYNCING)
- goto out;
+ return;
if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
parent = psmouse_from_serio(serio->parent);
@@ -1399,8 +1398,6 @@ static void psmouse_resync(struct work_struct *work)
if (parent)
psmouse_activate(parent);
- out:
- mutex_unlock(&psmouse_mutex);
}
/*
@@ -1411,7 +1408,7 @@ static void psmouse_cleanup(struct serio *serio)
struct psmouse *psmouse = psmouse_from_serio(serio);
struct psmouse *parent = NULL;
- mutex_lock(&psmouse_mutex);
+ guard(mutex)(&psmouse_mutex);
if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
parent = psmouse_from_serio(serio->parent);
@@ -1447,8 +1444,6 @@ static void psmouse_cleanup(struct serio *serio)
psmouse_activate(parent);
}
-
- mutex_unlock(&psmouse_mutex);
}
/*
@@ -1461,7 +1456,7 @@ static void psmouse_disconnect(struct serio *serio)
disable_work_sync(&psmouse->resync_work);
- mutex_lock(&psmouse_mutex);
+ guard(mutex)(&psmouse_mutex);
psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
@@ -1491,8 +1486,6 @@ static void psmouse_disconnect(struct serio *serio)
if (parent)
psmouse_activate(parent);
-
- mutex_unlock(&psmouse_mutex);
}
static int psmouse_switch_protocol(struct psmouse *psmouse,
@@ -1661,14 +1654,12 @@ static int __psmouse_reconnect(struct serio *serio, bool fast_reconnect)
enum psmouse_type type;
int rc = -1;
- mutex_lock(&psmouse_mutex);
+ lockdep_assert_held(&psmouse_mutex);
if (fast_reconnect) {
reconnect_handler = psmouse->fast_reconnect;
- if (!reconnect_handler) {
- rc = -ENOENT;
- goto out_unlock;
- }
+ if (!reconnect_handler)
+ return -ENOENT;
} else {
reconnect_handler = psmouse->reconnect;
}
@@ -1720,18 +1711,20 @@ static int __psmouse_reconnect(struct serio *serio, bool fast_reconnect)
if (parent)
psmouse_activate(parent);
-out_unlock:
- mutex_unlock(&psmouse_mutex);
return rc;
}
static int psmouse_reconnect(struct serio *serio)
{
+ guard(mutex)(&psmouse_mutex);
+
return __psmouse_reconnect(serio, false);
}
static int psmouse_fast_reconnect(struct serio *serio)
{
+ guard(mutex)(&psmouse_mutex);
+
return __psmouse_reconnect(serio, true);
}
--
2.55.0.229.g6434b31f56-goog
next prev parent reply other threads:[~2026-07-27 5:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 5:07 [PATCH 1/4] Input: psmouse - fix use-after-free during protocol disconnect Dmitry Torokhov
2026-07-27 5:07 ` [PATCH 2/4] Input: psmouse - clean up locking around disable_work_sync() Dmitry Torokhov
2026-07-27 5:32 ` sashiko-bot
2026-07-27 5:52 ` Dmitry Torokhov
2026-07-27 5:08 ` [PATCH 3/4] Input: psmouse - modernize PNP ID parsing Dmitry Torokhov
2026-07-27 5:08 ` Dmitry Torokhov [this message]
2026-07-27 5:35 ` [PATCH 4/4] Input: psmouse - use guard() for resource management sashiko-bot
2026-07-27 5:38 ` [PATCH 1/4] Input: psmouse - fix use-after-free during protocol disconnect sashiko-bot
2026-07-27 5:53 ` 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=20260727050803.1269941-4-dmitry.torokhov@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=hansg@kernel.org \
--cc=linux-input@vger.kernel.org \
/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