summaryrefslogtreecommitdiff
path: root/drivers/input/touchscreen
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2024-06-30 22:47:44 -0700
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2026-03-24 21:14:20 -0700
commitd77c45c8f0fd6a8cbbcaceb181633c092856f1c7 (patch)
tree4516bfe765a93789b8f0cb52ed723535490ed0ed /drivers/input/touchscreen
parentab2a8300179b80c7d05b460cbf319cd56c0eaf4d (diff)
downloadlwn-d77c45c8f0fd6a8cbbcaceb181633c092856f1c7.tar.gz
lwn-d77c45c8f0fd6a8cbbcaceb181633c092856f1c7.zip
Input: ads7846 - switch to using cleanup functions
Start using __free() and guard() primitives to simplify the code and error handling. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/touchscreen')
-rw-r--r--drivers/input/touchscreen/ads7846.c44
1 files changed, 16 insertions, 28 deletions
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index 0963b1a78a0c..4b39f7212d35 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -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;
}