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: <20220724164316.68393-1-matti.lehtimaki@gmail.com>
Date:   Sun, 24 Jul 2022 19:43:15 +0300
From:   Matti Lehtimäki <matti.lehtimaki@...il.com>
To:     linux-iio@...r.kernel.org
Cc:     ~postmarketos/upstreaming@...ts.sr.ht,
        Matti Lehtimäki <matti.lehtimaki@...il.com>,
        Jonathan Cameron <jic23@...nel.org>,
        Lars-Peter Clausen <lars@...afoo.de>,
        Miquel Raynal <miquel.raynal@...tlin.com>,
        Linus Walleij <linus.walleij@...aro.org>,
        Alexandru Ardelean <aardelean@...iqon.com>,
        Cai Huoqing <cai.huoqing@...ux.dev>,
        linux-kernel@...r.kernel.org
Subject: [PATCH 1/2] iio: st_sensors: Retry ID verification on failure

Some sensors do not always start fast enough to read a valid ID from
registers at first attempt. Let's retry at most 3 times with short sleep
in between to fix random timing issues.

Signed-off-by: Matti Lehtimäki <matti.lehtimaki@...il.com>
---
 drivers/iio/common/st_sensors/st_sensors_core.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index 9910ba1da085..106f7953683e 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -21,6 +21,8 @@
 
 #include "st_sensors_core.h"
 
+#define VERIFY_ID_RETRY_COUNT 3
+
 int st_sensors_write_data_with_mask(struct iio_dev *indio_dev,
 				    u8 reg_addr, u8 mask, u8 data)
 {
@@ -619,11 +621,18 @@ EXPORT_SYMBOL_NS(st_sensors_get_settings_index, IIO_ST_SENSORS);
 int st_sensors_verify_id(struct iio_dev *indio_dev)
 {
 	struct st_sensor_data *sdata = iio_priv(indio_dev);
-	int wai, err;
+	int wai, err, i;
 
 	if (sdata->sensor_settings->wai_addr) {
-		err = regmap_read(sdata->regmap,
-				  sdata->sensor_settings->wai_addr, &wai);
+		for (i = 0; i < VERIFY_ID_RETRY_COUNT; i++) {
+			err = regmap_read(sdata->regmap,
+					  sdata->sensor_settings->wai_addr, &wai);
+
+			if (!err && sdata->sensor_settings->wai == wai)
+				return 0;
+
+			msleep(20);
+		}
 		if (err < 0) {
 			dev_err(&indio_dev->dev,
 				"failed to read Who-Am-I register.\n");
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ