Skip to content

Commit e65407f

Browse files
committed
Input: tsc2007 - use guard notation when acquiring mutexes
This makes the code more compact and error handling more robust. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 600a2db commit e65407f

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

drivers/input/touchscreen/tsc2007_core.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)
122122

123123
/* pen is down, continue with the measurement */
124124

125-
mutex_lock(&ts->mlock);
126-
tsc2007_read_values(ts, &tc);
127-
mutex_unlock(&ts->mlock);
125+
/* Serialize access between the ISR and IIO reads. */
126+
scoped_guard(mutex, &ts->mlock) {
127+
tsc2007_read_values(ts, &tc);
128+
}
128129

129130
rt = tsc2007_calculate_resistance(ts, &tc);
130131

drivers/input/touchscreen/tsc2007_iio.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@ static int tsc2007_read_raw(struct iio_dev *indio_dev,
4141
struct tsc2007_iio *iio = iio_priv(indio_dev);
4242
struct tsc2007 *tsc = iio->ts;
4343
int adc_chan = chan->channel;
44-
int ret = 0;
4544

4645
if (adc_chan >= ARRAY_SIZE(tsc2007_iio_channel))
4746
return -EINVAL;
4847

4948
if (mask != IIO_CHAN_INFO_RAW)
5049
return -EINVAL;
5150

52-
mutex_lock(&tsc->mlock);
51+
guard(mutex)(&tsc->mlock);
5352

5453
switch (chan->channel) {
5554
case 0:
@@ -92,11 +91,7 @@ static int tsc2007_read_raw(struct iio_dev *indio_dev,
9291
/* Prepare for next touch reading - power down ADC, enable PENIRQ */
9392
tsc2007_xfer(tsc, PWRDOWN);
9493

95-
mutex_unlock(&tsc->mlock);
96-
97-
ret = IIO_VAL_INT;
98-
99-
return ret;
94+
return IIO_VAL_INT;
10095
}
10196

10297
static const struct iio_info tsc2007_iio_info = {

0 commit comments

Comments
 (0)