]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
Input: ads7846 - switch to using cleanup functions
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Mon, 1 Jul 2024 05:47:44 +0000 (22:47 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 25 Mar 2026 04:14:20 +0000 (21:14 -0700)
Start using __free() and guard() primitives to simplify the code
and error handling.

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

index 0963b1a78a0c5d7e851b0d64f080a631cf7b7af2..4b39f7212d35c6111033fee95d0670251fc13ea6 100644 (file)
@@ -289,7 +289,7 @@ static void __ads7846_enable(struct ads7846 *ts)
 
 static void ads7846_disable(struct ads7846 *ts)
 {
-       mutex_lock(&ts->lock);
+       guard(mutex)(&ts->lock);
 
        if (!ts->disabled) {
 
@@ -298,13 +298,11 @@ static void ads7846_disable(struct ads7846 *ts)
 
                ts->disabled = true;
        }
-
-       mutex_unlock(&ts->lock);
 }
 
 static void ads7846_enable(struct ads7846 *ts)
 {
-       mutex_lock(&ts->lock);
+       guard(mutex)(&ts->lock);
 
        if (ts->disabled) {
 
@@ -313,8 +311,6 @@ static void ads7846_enable(struct ads7846 *ts)
                if (!ts->suspended)
                        __ads7846_enable(ts);
        }
-
-       mutex_unlock(&ts->lock);
 }
 
 /*--------------------------------------------------------------------------*/
@@ -354,10 +350,9 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
 {
        struct spi_device *spi = to_spi_device(dev);
        struct ads7846 *ts = dev_get_drvdata(dev);
-       struct ser_req *req;
        int status;
 
-       req = kzalloc_obj(*req);
+       struct ser_req *req __free(kfree) = kzalloc_obj(*req);
        if (!req)
                return -ENOMEM;
 
@@ -418,11 +413,11 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
        CS_CHANGE(req->xfer[7]);
        spi_message_add_tail(&req->xfer[7], &req->msg);
 
-       mutex_lock(&ts->lock);
-       ads7846_stop(ts);
-       status = spi_sync(spi, &req->msg);
-       ads7846_restart(ts);
-       mutex_unlock(&ts->lock);
+       scoped_guard(mutex, &ts->lock) {
+               ads7846_stop(ts);
+               status = spi_sync(spi, &req->msg);
+               ads7846_restart(ts);
+       }
 
        if (status == 0) {
                /* on-wire is a must-ignore bit, a BE12 value, then padding */
@@ -431,7 +426,6 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
                status &= 0x0fff;
        }
 
-       kfree(req);
        return status;
 }
 
@@ -439,10 +433,9 @@ static int ads7845_read12_ser(struct device *dev, unsigned command)
 {
        struct spi_device *spi = to_spi_device(dev);
        struct ads7846 *ts = dev_get_drvdata(dev);
-       struct ads7845_ser_req *req;
        int status;
 
-       req = kzalloc_obj(*req);
+       struct ads7845_ser_req *req __free(kfree) = kzalloc_obj(*req);
        if (!req)
                return -ENOMEM;
 
@@ -454,11 +447,11 @@ static int ads7845_read12_ser(struct device *dev, unsigned command)
        req->xfer[0].len = 3;
        spi_message_add_tail(&req->xfer[0], &req->msg);
 
-       mutex_lock(&ts->lock);
-       ads7846_stop(ts);
-       status = spi_sync(spi, &req->msg);
-       ads7846_restart(ts);
-       mutex_unlock(&ts->lock);
+       scoped_guard(mutex, &ts->lock) {
+               ads7846_stop(ts);
+               status = spi_sync(spi, &req->msg);
+               ads7846_restart(ts);
+       }
 
        if (status == 0) {
                /* BE12 value, then padding */
@@ -467,7 +460,6 @@ static int ads7845_read12_ser(struct device *dev, unsigned command)
                status &= 0x0fff;
        }
 
-       kfree(req);
        return status;
 }
 
@@ -966,7 +958,7 @@ static int ads7846_suspend(struct device *dev)
 {
        struct ads7846 *ts = dev_get_drvdata(dev);
 
-       mutex_lock(&ts->lock);
+       guard(mutex)(&ts->lock);
 
        if (!ts->suspended) {
 
@@ -979,8 +971,6 @@ static int ads7846_suspend(struct device *dev)
                ts->suspended = true;
        }
 
-       mutex_unlock(&ts->lock);
-
        return 0;
 }
 
@@ -988,7 +978,7 @@ static int ads7846_resume(struct device *dev)
 {
        struct ads7846 *ts = dev_get_drvdata(dev);
 
-       mutex_lock(&ts->lock);
+       guard(mutex)(&ts->lock);
 
        if (ts->suspended) {
 
@@ -1001,8 +991,6 @@ static int ads7846_resume(struct device *dev)
                        __ads7846_enable(ts);
        }
 
-       mutex_unlock(&ts->lock);
-
        return 0;
 }