All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandru Ardelean <alexandru.ardelean@analog.com>
To: <linux-iio@vger.kernel.org>,
	<linux-stm32@st-md-mailman.stormreply.com>,
	<linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>
Cc: <jic23@kernel.org>, <alexandre.torgue@st.com>,
	<fabrice.gasnier@st.com>,
	Sergiu Cuciurean <sergiu.cuciurean@analog.com>,
	Alexandru Ardelean <alexandru.ardelean@analog.com>
Subject: [PATCH] iio: stm32-dac: Replace indio_dev->mlock with own device lock
Date: Wed, 26 Aug 2020 09:38:50 +0300	[thread overview]
Message-ID: <20200826063850.47625-1-alexandru.ardelean@analog.com> (raw)

From: Sergiu Cuciurean <sergiu.cuciurean@analog.com>

As part of the general cleanup of indio_dev->mlock, this change replaces
it with a local lock on the device's state structure.

The patch also does a minor whitespace change to align the 'lock' with the
'common' field via tabs.

Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/dac/stm32-dac.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/dac/stm32-dac.c b/drivers/iio/dac/stm32-dac.c
index 092c796fa3d9..fc636812c17e 100644
--- a/drivers/iio/dac/stm32-dac.c
+++ b/drivers/iio/dac/stm32-dac.c
@@ -26,9 +26,11 @@
 /**
  * struct stm32_dac - private data of DAC driver
  * @common:		reference to DAC common data
+ * @lock:		lock to protect the data buffer during regmap ops
  */
 struct stm32_dac {
-	struct stm32_dac_common *common;
+	struct stm32_dac_common	*common;
+	struct mutex		lock;
 };
 
 static int stm32_dac_is_enabled(struct iio_dev *indio_dev, int channel)
@@ -58,10 +60,10 @@ static int stm32_dac_set_enable_state(struct iio_dev *indio_dev, int ch,
 	int ret;
 
 	/* already enabled / disabled ? */
-	mutex_lock(&indio_dev->mlock);
+	mutex_lock(&dac->lock);
 	ret = stm32_dac_is_enabled(indio_dev, ch);
 	if (ret < 0 || enable == !!ret) {
-		mutex_unlock(&indio_dev->mlock);
+		mutex_unlock(&dac->lock);
 		return ret < 0 ? ret : 0;
 	}
 
@@ -69,13 +71,13 @@ static int stm32_dac_set_enable_state(struct iio_dev *indio_dev, int ch,
 		ret = pm_runtime_get_sync(dev);
 		if (ret < 0) {
 			pm_runtime_put_noidle(dev);
-			mutex_unlock(&indio_dev->mlock);
+			mutex_unlock(&dac->lock);
 			return ret;
 		}
 	}
 
 	ret = regmap_update_bits(dac->common->regmap, STM32_DAC_CR, msk, en);
-	mutex_unlock(&indio_dev->mlock);
+	mutex_unlock(&dac->lock);
 	if (ret < 0) {
 		dev_err(&indio_dev->dev, "%s failed\n", en ?
 			"Enable" : "Disable");
@@ -327,6 +329,8 @@ static int stm32_dac_probe(struct platform_device *pdev)
 	indio_dev->info = &stm32_dac_iio_info;
 	indio_dev->modes = INDIO_DIRECT_MODE;
 
+	mutex_init(&dac->lock);
+
 	ret = stm32_dac_chan_of_init(indio_dev);
 	if (ret < 0)
 		return ret;
-- 
2.25.1


WARNING: multiple messages have this Message-ID (diff)
From: Alexandru Ardelean <alexandru.ardelean@analog.com>
To: <linux-iio@vger.kernel.org>,
	<linux-stm32@st-md-mailman.stormreply.com>,
	<linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>
Cc: Sergiu Cuciurean <sergiu.cuciurean@analog.com>,
	Alexandru Ardelean <alexandru.ardelean@analog.com>,
	fabrice.gasnier@st.com, alexandre.torgue@st.com,
	jic23@kernel.org
Subject: [PATCH] iio: stm32-dac: Replace indio_dev->mlock with own device lock
Date: Wed, 26 Aug 2020 09:38:50 +0300	[thread overview]
Message-ID: <20200826063850.47625-1-alexandru.ardelean@analog.com> (raw)

From: Sergiu Cuciurean <sergiu.cuciurean@analog.com>

As part of the general cleanup of indio_dev->mlock, this change replaces
it with a local lock on the device's state structure.

The patch also does a minor whitespace change to align the 'lock' with the
'common' field via tabs.

Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/dac/stm32-dac.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/dac/stm32-dac.c b/drivers/iio/dac/stm32-dac.c
index 092c796fa3d9..fc636812c17e 100644
--- a/drivers/iio/dac/stm32-dac.c
+++ b/drivers/iio/dac/stm32-dac.c
@@ -26,9 +26,11 @@
 /**
  * struct stm32_dac - private data of DAC driver
  * @common:		reference to DAC common data
+ * @lock:		lock to protect the data buffer during regmap ops
  */
 struct stm32_dac {
-	struct stm32_dac_common *common;
+	struct stm32_dac_common	*common;
+	struct mutex		lock;
 };
 
 static int stm32_dac_is_enabled(struct iio_dev *indio_dev, int channel)
@@ -58,10 +60,10 @@ static int stm32_dac_set_enable_state(struct iio_dev *indio_dev, int ch,
 	int ret;
 
 	/* already enabled / disabled ? */
-	mutex_lock(&indio_dev->mlock);
+	mutex_lock(&dac->lock);
 	ret = stm32_dac_is_enabled(indio_dev, ch);
 	if (ret < 0 || enable == !!ret) {
-		mutex_unlock(&indio_dev->mlock);
+		mutex_unlock(&dac->lock);
 		return ret < 0 ? ret : 0;
 	}
 
@@ -69,13 +71,13 @@ static int stm32_dac_set_enable_state(struct iio_dev *indio_dev, int ch,
 		ret = pm_runtime_get_sync(dev);
 		if (ret < 0) {
 			pm_runtime_put_noidle(dev);
-			mutex_unlock(&indio_dev->mlock);
+			mutex_unlock(&dac->lock);
 			return ret;
 		}
 	}
 
 	ret = regmap_update_bits(dac->common->regmap, STM32_DAC_CR, msk, en);
-	mutex_unlock(&indio_dev->mlock);
+	mutex_unlock(&dac->lock);
 	if (ret < 0) {
 		dev_err(&indio_dev->dev, "%s failed\n", en ?
 			"Enable" : "Disable");
@@ -327,6 +329,8 @@ static int stm32_dac_probe(struct platform_device *pdev)
 	indio_dev->info = &stm32_dac_iio_info;
 	indio_dev->modes = INDIO_DIRECT_MODE;
 
+	mutex_init(&dac->lock);
+
 	ret = stm32_dac_chan_of_init(indio_dev);
 	if (ret < 0)
 		return ret;
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

             reply	other threads:[~2020-08-26  6:39 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-26  6:38 Alexandru Ardelean [this message]
2020-08-26  6:38 ` [PATCH] iio: stm32-dac: Replace indio_dev->mlock with own device lock Alexandru Ardelean
2020-08-26  8:57 ` Fabrice Gasnier
2020-08-26  8:57   ` Fabrice Gasnier
2020-08-26 10:01   ` Alexandru Ardelean
2020-08-26 10:01     ` Alexandru Ardelean
2020-08-26 12:00 ` [PATCH v2] " Alexandru Ardelean
2020-08-26 12:00   ` Alexandru Ardelean
2020-08-27  8:55   ` Alexandru Ardelean
2020-08-27  8:55     ` Alexandru Ardelean
2020-08-27  9:03     ` Fabrice Gasnier
2020-08-27  9:03       ` Fabrice Gasnier
2020-08-27 10:00       ` Alexandru Ardelean
2020-08-27 10:00         ` Alexandru Ardelean
2020-08-29 15:46         ` Jonathan Cameron
2020-08-29 15:46           ` Jonathan Cameron
2020-09-02  6:12           ` Alexandru Ardelean
2020-09-02  6:12             ` Alexandru Ardelean
2020-09-16  9:23 ` Alexandru Ardelean
2020-09-16  9:23   ` Alexandru Ardelean
2020-09-16 10:18   ` Fabrice Gasnier
2020-09-16 10:18     ` Fabrice Gasnier
2020-09-16 17:52     ` Jonathan Cameron
2020-09-16 17:52       ` Jonathan Cameron
  -- strict thread matches above, loose matches on Subject: below --
2020-05-14  8:50 [PATCH] " Sergiu Cuciurean
2020-05-14  8:50 ` Sergiu Cuciurean
2020-05-16 15:35 ` Jonathan Cameron
2020-05-16 15:35   ` Jonathan Cameron
2020-05-18  9:22   ` Fabrice Gasnier
2020-05-18  9:22     ` Fabrice Gasnier

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=20200826063850.47625-1-alexandru.ardelean@analog.com \
    --to=alexandru.ardelean@analog.com \
    --cc=alexandre.torgue@st.com \
    --cc=fabrice.gasnier@st.com \
    --cc=jic23@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=sergiu.cuciurean@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.