From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: "Heiko Stübner" <heiko@sntech.de>, linux-input@vger.kernel.org
Cc: Andreas Kemnade <andreas@kemnade.info>, linux-kernel@vger.kernel.org
Subject: [PATCH 08/18] Input: zforce_ts - use guard notation when acquiring mutexes
Date: Fri, 23 Aug 2024 22:50:32 -0700 [thread overview]
Message-ID: <20240824055047.1706392-9-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20240824055047.1706392-1-dmitry.torokhov@gmail.com>
Guard notation allows for simpler code and ensures that mutexes are
automatically released in all code paths.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/touchscreen/zforce_ts.c | 45 ++++++++++++++-------------
1 file changed, 24 insertions(+), 21 deletions(-)
diff --git a/drivers/input/touchscreen/zforce_ts.c b/drivers/input/touchscreen/zforce_ts.c
index 004ef728fb90..0dea389594bd 100644
--- a/drivers/input/touchscreen/zforce_ts.c
+++ b/drivers/input/touchscreen/zforce_ts.c
@@ -578,17 +578,13 @@ static void zforce_input_close(struct input_dev *dev)
return;
}
-static int zforce_suspend(struct device *dev)
+static int __zforce_suspend(struct zforce_ts *ts)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct zforce_ts *ts = i2c_get_clientdata(client);
+ struct i2c_client *client = ts->client;
struct input_dev *input = ts->input;
- int ret = 0;
-
- mutex_lock(&input->mutex);
+ int ret;
- WRITE_ONCE(ts->suspending, true);
- smp_mb();
+ guard(mutex)(&input->mutex);
/*
* When configured as a wakeup source device should always wake
@@ -601,7 +597,7 @@ static int zforce_suspend(struct device *dev)
if (!input_device_enabled(input)) {
ret = zforce_start(ts);
if (ret)
- goto unlock;
+ return ret;
}
enable_irq_wake(client->irq);
@@ -611,18 +607,28 @@ static int zforce_suspend(struct device *dev)
ret = zforce_stop(ts);
if (ret)
- goto unlock;
+ return ret;
disable_irq(client->irq);
}
ts->suspended = true;
+ return 0;
+}
-unlock:
+static int zforce_suspend(struct device *dev)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct zforce_ts *ts = i2c_get_clientdata(client);
+ int ret;
+
+ WRITE_ONCE(ts->suspending, true);
smp_mb();
- WRITE_ONCE(ts->suspending, false);
- mutex_unlock(&input->mutex);
+ ret = __zforce_suspend(ts);
+
+ smp_mb();
+ WRITE_ONCE(ts->suspending, false);
return ret;
}
@@ -632,9 +638,9 @@ static int zforce_resume(struct device *dev)
struct i2c_client *client = to_i2c_client(dev);
struct zforce_ts *ts = i2c_get_clientdata(client);
struct input_dev *input = ts->input;
- int ret = 0;
+ int ret;
- mutex_lock(&input->mutex);
+ guard(mutex)(&input->mutex);
ts->suspended = false;
@@ -647,7 +653,7 @@ static int zforce_resume(struct device *dev)
if (!input_device_enabled(input)) {
ret = zforce_stop(ts);
if (ret)
- goto unlock;
+ return ret;
}
} else if (input_device_enabled(input)) {
dev_dbg(&client->dev, "resume without being a wakeup source\n");
@@ -656,13 +662,10 @@ static int zforce_resume(struct device *dev)
ret = zforce_start(ts);
if (ret < 0)
- goto unlock;
+ return ret;
}
-unlock:
- mutex_unlock(&input->mutex);
-
- return ret;
+ return 0;
}
static DEFINE_SIMPLE_DEV_PM_OPS(zforce_pm_ops, zforce_suspend, zforce_resume);
--
2.46.0.295.g3b9ea8a38a-goog
next prev parent reply other threads:[~2024-08-24 5:51 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-24 5:50 [PATCH 00/18] zforse_ts: assorted cleanups Dmitry Torokhov
2024-08-24 5:50 ` [PATCH 01/18] Input: zforce_ts - use devm_add_action_or_reset() Dmitry Torokhov
2024-08-24 11:13 ` Heiko Stübner
2024-08-29 17:54 ` Dmitry Torokhov
2024-08-24 5:50 ` [PATCH 02/18] Input: zforce_ts - simplify reporting of slot state Dmitry Torokhov
2024-08-24 5:50 ` [PATCH 03/18] Input: zforce_ts - remove support for platfrom data Dmitry Torokhov
2024-08-24 5:50 ` [PATCH 04/18] Input: zforce_ts - do not explicitly set EV_SYN, etc bits Dmitry Torokhov
2024-08-24 5:50 ` [PATCH 05/18] Input: zforce_ts - handle errors from input_mt_init_sots() Dmitry Torokhov
2024-08-24 5:50 ` [PATCH 06/18] Input: zforce_ts - remove unneeded locking Dmitry Torokhov
2024-08-24 5:50 ` [PATCH 07/18] Input: zforce_ts - ensure that pm_stay_awake() and pm_relax() are balanced Dmitry Torokhov
2024-08-24 5:50 ` Dmitry Torokhov [this message]
2024-08-24 5:50 ` [PATCH 09/18] Input: zforce_ts - switch to using get_unaligned_le16 Dmitry Torokhov
2024-08-24 5:50 ` [PATCH 10/18] Input: zforce_ts - make parsing of contacts less confusing Dmitry Torokhov
2024-08-24 5:50 ` [PATCH 11/18] Input: zforce_ts - do not ignore errors when acquiring regulator Dmitry Torokhov
2024-08-24 5:50 ` [PATCH 12/18] Input: zforce_ts - use dev_err_probe() where appropriate Dmitry Torokhov
2024-08-24 5:50 ` [PATCH 13/18] Input: zforce_ts - make zforce_idtable constant Dmitry Torokhov
2024-08-24 5:50 ` [PATCH 14/18] Input: zforce_ts - stop treating VDD regulator as optional Dmitry Torokhov
2024-08-24 5:50 ` [PATCH 15/18] Input: zforce_ts - switch to using devm_regulator_get_enable() Dmitry Torokhov
2024-08-24 5:50 ` [PATCH 16/18] Input: zforce_ts - do not hardcode interrupt level Dmitry Torokhov
2024-08-24 5:50 ` [PATCH 17/18] Input: zforce_ts - remove assert/deassert wrappers Dmitry Torokhov
2024-08-24 5:50 ` [PATCH 18/18] Input: zforce_ts - switch to using asynchronous probing Dmitry Torokhov
2024-09-02 8:08 ` [PATCH 00/18] zforse_ts: assorted cleanups Andreas Kemnade
2024-09-06 5:49 ` 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=20240824055047.1706392-9-dmitry.torokhov@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=andreas@kemnade.info \
--cc=heiko@sntech.de \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@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;
as well as URLs for NNTP newsgroup(s).