linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandru Ardelean <alexandru.ardelean@analog.com>
To: <linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <jic23@kernel.org>, <nuno.sa@analog.com>,
	<Michael.Hennerich@analog.com>,
	Alexandru Ardelean <alexandru.ardelean@analog.com>
Subject: [PATCH v2 06/11] iio: imu: adis: protect initial startup routine with state lock
Date: Fri, 22 Nov 2019 15:24:16 +0200	[thread overview]
Message-ID: <20191122132421.5500-7-alexandru.ardelean@analog.com> (raw)
In-Reply-To: <20191122132421.5500-1-alexandru.ardelean@analog.com>

The initial startup routine is called by some ADIS drivers during probe,
and before registering with IIO. Normally, userspace should not be able to
do any access to the device (as there shouldn't be any available).

This change extends the state lock to the entire initial-startup routine.
Behaviourally nothing should change, but this should make the library
function a bit more robust.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/imu/adis.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/imu/adis.c b/drivers/iio/imu/adis.c
index 615f174f0e6e..10b8922fd51b 100644
--- a/drivers/iio/imu/adis.c
+++ b/drivers/iio/imu/adis.c
@@ -331,7 +331,7 @@ static int adis_self_test(struct adis *adis)
 {
 	int ret;
 
-	ret = adis_write_reg_16(adis, adis->data->msc_ctrl_reg,
+	ret = __adis_write_reg_16(adis, adis->data->msc_ctrl_reg,
 			adis->data->self_test_mask);
 	if (ret) {
 		dev_err(&adis->spi->dev, "Failed to initiate self test: %d\n",
@@ -341,10 +341,10 @@ static int adis_self_test(struct adis *adis)
 
 	msleep(adis->data->startup_delay);
 
-	ret = adis_check_status(adis);
+	ret = __adis_check_status(adis);
 
 	if (adis->data->self_test_no_autoclear)
-		adis_write_reg_16(adis, adis->data->msc_ctrl_reg, 0x00);
+		__adis_write_reg_16(adis, adis->data->msc_ctrl_reg, 0x00);
 
 	return ret;
 }
@@ -362,19 +362,23 @@ int adis_initial_startup(struct adis *adis)
 {
 	int ret;
 
+	mutex_lock(&adis->state_lock);
+
 	ret = adis_self_test(adis);
 	if (ret) {
 		dev_err(&adis->spi->dev, "Self-test failed, trying reset.\n");
-		adis_reset(adis);
+		__adis_reset(adis);
 		msleep(adis->data->startup_delay);
 		ret = adis_self_test(adis);
 		if (ret) {
 			dev_err(&adis->spi->dev, "Second self-test failed, giving up.\n");
-			return ret;
+			goto out_unlock;
 		}
 	}
 
-	return 0;
+out_unlock:
+	mutex_unlock(&adis->state_lock);
+	return ret;
 }
 EXPORT_SYMBOL_GPL(adis_initial_startup);
 
-- 
2.20.1


  parent reply	other threads:[~2019-11-22 13:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-22 13:24 [PATCH v2 00/11] iio: imu: adis: cleanup lock usage Alexandru Ardelean
2019-11-22 13:24 ` [PATCH v2 01/11] iio: imu: adis: rename txrx_lock -> state_lock Alexandru Ardelean
2019-11-22 13:24 ` [PATCH v2 02/11] iio: imu: adis: add unlocked read/write function versions Alexandru Ardelean
2019-11-22 13:24 ` [PATCH v2 03/11] iio: imu: adis[16480]: group RW into a single lock in adis_enable_irq() Alexandru Ardelean
2019-11-22 13:24 ` [PATCH v2 04/11] iio: imu: adis: create an unlocked version of adis_check_status() Alexandru Ardelean
2019-11-22 13:24 ` [PATCH v2 05/11] iio: imu: adis: create an unlocked version of adis_reset() Alexandru Ardelean
2019-11-22 13:24 ` Alexandru Ardelean [this message]
2019-11-22 13:24 ` [PATCH v2 07/11] iio: imu: adis: group single conversion under a single state lock Alexandru Ardelean
2019-11-22 13:24 ` [PATCH v2 08/11] iio: imu: adis16400: rework locks using ADIS library's " Alexandru Ardelean
2019-11-22 13:24 ` [PATCH v2 09/11] iio: gyro: adis16136: " Alexandru Ardelean
2019-11-22 13:24 ` [PATCH v2 10/11] iio: imu: adis16480: use state lock for filter freq set Alexandru Ardelean
2019-11-22 13:24 ` [PATCH v2 11/11] iio: gyro: adis16260: replace mlock with ADIS lib's state_lock Alexandru Ardelean
2019-11-23 12:21 ` [PATCH v2 00/11] iio: imu: adis: cleanup lock usage Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191122132421.5500-7-alexandru.ardelean@analog.com \
    --to=alexandru.ardelean@analog.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).