Commit 5c200267 authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: zforce_ts - use guard notation when acquiring mutexes

Guard notation allows for simpler code and ensures that mutexes are
automatically released in all code paths.

Tested-by: Andreas Kemnade <andreas@kemnade.info> # Tolino Shine2HD
Link: https://lore.kernel.org/r/20240824055047.1706392-9-dmitry.torokhov@gmail.comSigned-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 9ba33f61
...@@ -578,17 +578,13 @@ static void zforce_input_close(struct input_dev *dev) ...@@ -578,17 +578,13 @@ static void zforce_input_close(struct input_dev *dev)
return; 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 i2c_client *client = ts->client;
struct zforce_ts *ts = i2c_get_clientdata(client);
struct input_dev *input = ts->input; struct input_dev *input = ts->input;
int ret = 0; int ret;
mutex_lock(&input->mutex);
WRITE_ONCE(ts->suspending, true); guard(mutex)(&input->mutex);
smp_mb();
/* /*
* When configured as a wakeup source device should always wake * When configured as a wakeup source device should always wake
...@@ -601,7 +597,7 @@ static int zforce_suspend(struct device *dev) ...@@ -601,7 +597,7 @@ static int zforce_suspend(struct device *dev)
if (!input_device_enabled(input)) { if (!input_device_enabled(input)) {
ret = zforce_start(ts); ret = zforce_start(ts);
if (ret) if (ret)
goto unlock; return ret;
} }
enable_irq_wake(client->irq); enable_irq_wake(client->irq);
...@@ -611,18 +607,28 @@ static int zforce_suspend(struct device *dev) ...@@ -611,18 +607,28 @@ static int zforce_suspend(struct device *dev)
ret = zforce_stop(ts); ret = zforce_stop(ts);
if (ret) if (ret)
goto unlock; return ret;
disable_irq(client->irq); disable_irq(client->irq);
} }
ts->suspended = true; 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(); smp_mb();
WRITE_ONCE(ts->suspending, false);
mutex_unlock(&input->mutex); ret = __zforce_suspend(ts);
smp_mb();
WRITE_ONCE(ts->suspending, false);
return ret; return ret;
} }
...@@ -632,9 +638,9 @@ static int zforce_resume(struct device *dev) ...@@ -632,9 +638,9 @@ static int zforce_resume(struct device *dev)
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct zforce_ts *ts = i2c_get_clientdata(client); struct zforce_ts *ts = i2c_get_clientdata(client);
struct input_dev *input = ts->input; struct input_dev *input = ts->input;
int ret = 0; int ret;
mutex_lock(&input->mutex); guard(mutex)(&input->mutex);
ts->suspended = false; ts->suspended = false;
...@@ -647,7 +653,7 @@ static int zforce_resume(struct device *dev) ...@@ -647,7 +653,7 @@ static int zforce_resume(struct device *dev)
if (!input_device_enabled(input)) { if (!input_device_enabled(input)) {
ret = zforce_stop(ts); ret = zforce_stop(ts);
if (ret) if (ret)
goto unlock; return ret;
} }
} else if (input_device_enabled(input)) { } else if (input_device_enabled(input)) {
dev_dbg(&client->dev, "resume without being a wakeup source\n"); dev_dbg(&client->dev, "resume without being a wakeup source\n");
...@@ -656,13 +662,10 @@ static int zforce_resume(struct device *dev) ...@@ -656,13 +662,10 @@ static int zforce_resume(struct device *dev)
ret = zforce_start(ts); ret = zforce_start(ts);
if (ret < 0) if (ret < 0)
goto unlock; return ret;
} }
unlock: return 0;
mutex_unlock(&input->mutex);
return ret;
} }
static DEFINE_SIMPLE_DEV_PM_OPS(zforce_pm_ops, zforce_suspend, zforce_resume); static DEFINE_SIMPLE_DEV_PM_OPS(zforce_pm_ops, zforce_suspend, zforce_resume);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment