Skip to content

Commit 5c20026

Browse files
committed
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 <[email protected]> # Tolino Shine2HD Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 9ba33f6 commit 5c20026

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

drivers/input/touchscreen/zforce_ts.c

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -578,17 +578,13 @@ static void zforce_input_close(struct input_dev *dev)
578578
return;
579579
}
580580

581-
static int zforce_suspend(struct device *dev)
581+
static int __zforce_suspend(struct zforce_ts *ts)
582582
{
583-
struct i2c_client *client = to_i2c_client(dev);
584-
struct zforce_ts *ts = i2c_get_clientdata(client);
583+
struct i2c_client *client = ts->client;
585584
struct input_dev *input = ts->input;
586-
int ret = 0;
587-
588-
mutex_lock(&input->mutex);
585+
int ret;
589586

590-
WRITE_ONCE(ts->suspending, true);
591-
smp_mb();
587+
guard(mutex)(&input->mutex);
592588

593589
/*
594590
* When configured as a wakeup source device should always wake
@@ -601,7 +597,7 @@ static int zforce_suspend(struct device *dev)
601597
if (!input_device_enabled(input)) {
602598
ret = zforce_start(ts);
603599
if (ret)
604-
goto unlock;
600+
return ret;
605601
}
606602

607603
enable_irq_wake(client->irq);
@@ -611,18 +607,28 @@ static int zforce_suspend(struct device *dev)
611607

612608
ret = zforce_stop(ts);
613609
if (ret)
614-
goto unlock;
610+
return ret;
615611

616612
disable_irq(client->irq);
617613
}
618614

619615
ts->suspended = true;
616+
return 0;
617+
}
620618

621-
unlock:
619+
static int zforce_suspend(struct device *dev)
620+
{
621+
struct i2c_client *client = to_i2c_client(dev);
622+
struct zforce_ts *ts = i2c_get_clientdata(client);
623+
int ret;
624+
625+
WRITE_ONCE(ts->suspending, true);
622626
smp_mb();
623-
WRITE_ONCE(ts->suspending, false);
624627

625-
mutex_unlock(&input->mutex);
628+
ret = __zforce_suspend(ts);
629+
630+
smp_mb();
631+
WRITE_ONCE(ts->suspending, false);
626632

627633
return ret;
628634
}
@@ -632,9 +638,9 @@ static int zforce_resume(struct device *dev)
632638
struct i2c_client *client = to_i2c_client(dev);
633639
struct zforce_ts *ts = i2c_get_clientdata(client);
634640
struct input_dev *input = ts->input;
635-
int ret = 0;
641+
int ret;
636642

637-
mutex_lock(&input->mutex);
643+
guard(mutex)(&input->mutex);
638644

639645
ts->suspended = false;
640646

@@ -647,7 +653,7 @@ static int zforce_resume(struct device *dev)
647653
if (!input_device_enabled(input)) {
648654
ret = zforce_stop(ts);
649655
if (ret)
650-
goto unlock;
656+
return ret;
651657
}
652658
} else if (input_device_enabled(input)) {
653659
dev_dbg(&client->dev, "resume without being a wakeup source\n");
@@ -656,13 +662,10 @@ static int zforce_resume(struct device *dev)
656662

657663
ret = zforce_start(ts);
658664
if (ret < 0)
659-
goto unlock;
665+
return ret;
660666
}
661667

662-
unlock:
663-
mutex_unlock(&input->mutex);
664-
665-
return ret;
668+
return 0;
666669
}
667670

668671
static DEFINE_SIMPLE_DEV_PM_OPS(zforce_pm_ops, zforce_suspend, zforce_resume);

0 commit comments

Comments
 (0)