lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240405104641.29478-1-subhajit.ghosh@tweaklogic.com>
Date: Fri,  5 Apr 2024 21:16:41 +1030
From: Subhajit Ghosh <subhajit.ghosh@...aklogic.com>
To: Jonathan Cameron <jic23@...nel.org>,
	Lars-Peter Clausen <lars@...afoo.de>,
	Dan Carpenter <dan.carpenter@...aro.org>
Cc: Subhajit Ghosh <subhajit.ghosh@...aklogic.com>,
	linux-iio@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH] iio: light: apds9306: Improve apds9306_write_event_config()

Simplify event configuration flow.

Suggested-by: Jonathan Cameron <jic23@...nel.org>
Link: https://lore.kernel.org/all/20240310124237.52fa8a56@jic23-huawei/
Signed-off-by: Subhajit Ghosh <subhajit.ghosh@...aklogic.com>
---
 drivers/iio/light/apds9306.c | 48 ++++++++++++++++++++----------------
 1 file changed, 27 insertions(+), 21 deletions(-)

diff --git a/drivers/iio/light/apds9306.c b/drivers/iio/light/apds9306.c
index 4d8490602cd7..465b6957682b 100644
--- a/drivers/iio/light/apds9306.c
+++ b/drivers/iio/light/apds9306.c
@@ -1075,14 +1075,16 @@ static int apds9306_write_event_config(struct iio_dev *indio_dev,
 {
 	struct apds9306_data *data = iio_priv(indio_dev);
 	struct apds9306_regfields *rf = &data->rf;
-	int ret, val;
-
-	state = !!state;
+	int ret, enabled;
 
 	switch (type) {
 	case IIO_EV_TYPE_THRESH: {
 		guard(mutex)(&data->mutex);
 
+		ret = regmap_field_read(rf->int_en, &enabled);
+		if (ret)
+			return ret;
+
 		/*
 		 * If interrupt is enabled, the channel is set before enabling
 		 * the interrupt. In case of disable, no need to switch
@@ -1091,38 +1093,42 @@ static int apds9306_write_event_config(struct iio_dev *indio_dev,
 		 */
 		if (state) {
 			if (chan->type == IIO_LIGHT)
-				val = 1;
+				ret = regmap_field_write(rf->int_src, 1);
 			else if (chan->type == IIO_INTENSITY)
-				val = 0;
+				ret = regmap_field_write(rf->int_src, 0);
 			else
 				return -EINVAL;
 
-			ret = regmap_field_write(rf->int_src, val);
 			if (ret)
 				return ret;
-		}
 
-		ret = regmap_field_read(rf->int_en, &val);
-		if (ret)
-			return ret;
-
-		if (val == state)
-			return 0;
+			if (enabled)
+				return 0;
 
-		ret = regmap_field_write(rf->int_en, state);
-		if (ret)
-			return ret;
+			ret = regmap_field_write(rf->int_en, 1);
+			if (ret)
+				return ret;
 
-		if (state)
 			return pm_runtime_resume_and_get(data->dev);
+		} else {
+			if (!enabled)
+				return 0;
 
-		pm_runtime_mark_last_busy(data->dev);
-		pm_runtime_put_autosuspend(data->dev);
+			ret = regmap_field_write(rf->int_en, 0);
+			if (ret)
+				return ret;
 
-		return 0;
+			pm_runtime_mark_last_busy(data->dev);
+			pm_runtime_put_autosuspend(data->dev);
+
+			return 0;
+		}
 	}
 	case IIO_EV_TYPE_THRESH_ADAPTIVE:
-		return regmap_field_write(rf->int_thresh_var_en, state);
+		if (state)
+			return regmap_field_write(rf->int_thresh_var_en, 1);
+		else
+			return regmap_field_write(rf->int_thresh_var_en, 0);
 	default:
 		return -EINVAL;
 	}

base-commit: 526f7f17b651c78ead26fea7cea20948c00e47a5
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ