]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
Input: tsc2007 - use guard notation when acquiring mutexes
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Tue, 6 Aug 2024 23:48:00 +0000 (16:48 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 25 Mar 2026 14:53:59 +0000 (07:53 -0700)
This makes the code more compact and error handling more robust.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/touchscreen/tsc2007_core.c
drivers/input/touchscreen/tsc2007_iio.c

index 948935de894bfb0c3f75327aa6ac50bf0b1e9f40..524f14eb3da2f95f8ea21288b083f87c118b7c6c 100644 (file)
@@ -122,9 +122,10 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)
 
                /* pen is down, continue with the measurement */
 
-               mutex_lock(&ts->mlock);
-               tsc2007_read_values(ts, &tc);
-               mutex_unlock(&ts->mlock);
+               /* Serialize access between the ISR and IIO reads. */
+               scoped_guard(mutex, &ts->mlock) {
+                       tsc2007_read_values(ts, &tc);
+               }
 
                rt = tsc2007_calculate_resistance(ts, &tc);
 
index 752eb7fe5da3af8d0972a46eeff4583af840fb79..e9e495ec0b6c51ce50f82a6debf3604dbc638376 100644 (file)
@@ -41,7 +41,6 @@ static int tsc2007_read_raw(struct iio_dev *indio_dev,
        struct tsc2007_iio *iio = iio_priv(indio_dev);
        struct tsc2007 *tsc = iio->ts;
        int adc_chan = chan->channel;
-       int ret = 0;
 
        if (adc_chan >= ARRAY_SIZE(tsc2007_iio_channel))
                return -EINVAL;
@@ -49,7 +48,7 @@ static int tsc2007_read_raw(struct iio_dev *indio_dev,
        if (mask != IIO_CHAN_INFO_RAW)
                return -EINVAL;
 
-       mutex_lock(&tsc->mlock);
+       guard(mutex)(&tsc->mlock);
 
        switch (chan->channel) {
        case 0:
@@ -92,11 +91,7 @@ static int tsc2007_read_raw(struct iio_dev *indio_dev,
        /* Prepare for next touch reading - power down ADC, enable PENIRQ */
        tsc2007_xfer(tsc, PWRDOWN);
 
-       mutex_unlock(&tsc->mlock);
-
-       ret = IIO_VAL_INT;
-
-       return ret;
+       return IIO_VAL_INT;
 }
 
 static const struct iio_info tsc2007_iio_info = {