* [PATCH] iio: stm32-dac: Replace indio_dev->mlock with own device lock
@ 2020-08-26 6:38 Alexandru Ardelean
2020-08-26 8:57 ` Fabrice Gasnier
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: Alexandru Ardelean @ 2020-08-26 6:38 UTC (permalink / raw)
To: linux-iio, linux-stm32, linux-kernel, linux-arm-kernel
Cc: jic23, alexandre.torgue, fabrice.gasnier, Sergiu Cuciurean,
Alexandru Ardelean
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
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH] iio: stm32-dac: Replace indio_dev->mlock with own device lock
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 10:01 ` Alexandru Ardelean
2020-08-26 12:00 ` [PATCH v2] " Alexandru Ardelean
2020-09-16 9:23 ` Alexandru Ardelean
2 siblings, 1 reply; 12+ messages in thread
From: Fabrice Gasnier @ 2020-08-26 8:57 UTC (permalink / raw)
To: Alexandru Ardelean, linux-iio, linux-stm32, linux-kernel,
linux-arm-kernel
Cc: jic23, alexandre.torgue, Sergiu Cuciurean
On 8/26/20 8:38 AM, Alexandru Ardelean wrote:
> 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
Hi Alexandru,
I think the same patch has been sent by Sergiu already [1].
Jonathan and I had a minor comment at that time: E.g. could you please
update the comment ?
[1] https://lkml.org/lkml/2020/5/18/254
> */
> struct stm32_dac {
> - struct stm32_dac_common *common;
> + struct stm32_dac_common *common;
Is above change needed?
Best Regards,
Fabrice
> + 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;
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] iio: stm32-dac: Replace indio_dev->mlock with own device lock
2020-08-26 8:57 ` Fabrice Gasnier
@ 2020-08-26 10:01 ` Alexandru Ardelean
0 siblings, 0 replies; 12+ messages in thread
From: Alexandru Ardelean @ 2020-08-26 10:01 UTC (permalink / raw)
To: Fabrice Gasnier
Cc: Alexandru Ardelean, linux-iio, linux-stm32, LKML,
linux-arm-kernel, Jonathan Cameron, alexandre.torgue,
Sergiu Cuciurean
On Wed, Aug 26, 2020 at 12:01 PM Fabrice Gasnier <fabrice.gasnier@st.com> wrote:
>
> On 8/26/20 8:38 AM, Alexandru Ardelean wrote:
> > 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
>
> Hi Alexandru,
>
> I think the same patch has been sent by Sergiu already [1].
> Jonathan and I had a minor comment at that time: E.g. could you please
> update the comment ?
Oh.
My bad. I didn't follow the discussion closely.
Will send a V2.
>
> [1] https://lkml.org/lkml/2020/5/18/254
>
> > */
> > struct stm32_dac {
> > - struct stm32_dac_common *common;
> > + struct stm32_dac_common *common;
>
> Is above change needed?
No.
I can remove it.
Thanks
Alex
>
> Best Regards,
> Fabrice
>
> > + 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;
> >
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2] iio: stm32-dac: Replace indio_dev->mlock with own device lock
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 12:00 ` Alexandru Ardelean
2020-08-27 8:55 ` Alexandru Ardelean
2020-09-16 9:23 ` Alexandru Ardelean
2 siblings, 1 reply; 12+ messages in thread
From: Alexandru Ardelean @ 2020-08-26 12:00 UTC (permalink / raw)
To: linux-iio, linux-stm32, linux-kernel, linux-arm-kernel
Cc: jic23, alexandre.torgue, fabrice.gasnier, Sergiu Cuciurean,
Alexandru Ardelean
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. The lock protects against potential races when
reading the CR reg and then updating, so that the state of pm_runtime
is consistent between the two operations.
Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
drivers/iio/dac/stm32-dac.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/dac/stm32-dac.c b/drivers/iio/dac/stm32-dac.c
index 092c796fa3d9..7a8aed476850 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 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
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v2] iio: stm32-dac: Replace indio_dev->mlock with own device lock
2020-08-26 12:00 ` [PATCH v2] " Alexandru Ardelean
@ 2020-08-27 8:55 ` Alexandru Ardelean
2020-08-27 9:03 ` Fabrice Gasnier
0 siblings, 1 reply; 12+ messages in thread
From: Alexandru Ardelean @ 2020-08-27 8:55 UTC (permalink / raw)
To: Alexandru Ardelean
Cc: linux-iio, linux-stm32, LKML, linux-arm-kernel, Jonathan Cameron,
alexandre.torgue, Fabrice Gasnier, Sergiu Cuciurean
On Wed, Aug 26, 2020 at 3:03 PM Alexandru Ardelean
<alexandru.ardelean@analog.com> wrote:
>
> 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. The lock protects against potential races when
> reading the CR reg and then updating, so that the state of pm_runtime
> is consistent between the two operations.
>
> Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> ---
Forgot the changelog here.
Apologies.
Changelog v1 -> v2:
* removed whitespace change for 'common' field
* updated comment about the lock usage
> drivers/iio/dac/stm32-dac.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/dac/stm32-dac.c b/drivers/iio/dac/stm32-dac.c
> index 092c796fa3d9..7a8aed476850 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 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
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2] iio: stm32-dac: Replace indio_dev->mlock with own device lock
2020-08-27 8:55 ` Alexandru Ardelean
@ 2020-08-27 9:03 ` Fabrice Gasnier
2020-08-27 10:00 ` Alexandru Ardelean
0 siblings, 1 reply; 12+ messages in thread
From: Fabrice Gasnier @ 2020-08-27 9:03 UTC (permalink / raw)
To: Alexandru Ardelean, Alexandru Ardelean
Cc: linux-iio, linux-stm32, LKML, linux-arm-kernel, Jonathan Cameron,
alexandre.torgue, Sergiu Cuciurean
On 8/27/20 10:55 AM, Alexandru Ardelean wrote:
> On Wed, Aug 26, 2020 at 3:03 PM Alexandru Ardelean
> <alexandru.ardelean@analog.com> wrote:
>> 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. The lock protects against potential races when
>> reading the CR reg and then updating, so that the state of pm_runtime
>> is consistent between the two operations.
>>
>> Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
>> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
>> ---
> Forgot the changelog here.
> Apologies.
>
> Changelog v1 -> v2:
> * removed whitespace change for 'common' field
> * updated comment about the lock usage
Hi Alexandru,
Sorry if I missed it... is there an update on the comment :-) ?
Best Regards,
Fabrice
>
>> drivers/iio/dac/stm32-dac.c | 12 ++++++++----
>> 1 file changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/iio/dac/stm32-dac.c b/drivers/iio/dac/stm32-dac.c
>> index 092c796fa3d9..7a8aed476850 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 mutex lock;
>> };
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2] iio: stm32-dac: Replace indio_dev->mlock with own device lock
2020-08-27 9:03 ` Fabrice Gasnier
@ 2020-08-27 10:00 ` Alexandru Ardelean
2020-08-29 15:46 ` Jonathan Cameron
0 siblings, 1 reply; 12+ messages in thread
From: Alexandru Ardelean @ 2020-08-27 10:00 UTC (permalink / raw)
To: Fabrice Gasnier
Cc: Alexandru Ardelean, linux-iio, linux-stm32, LKML,
linux-arm-kernel, Jonathan Cameron, alexandre.torgue,
Sergiu Cuciurean
On Thu, Aug 27, 2020 at 12:03 PM Fabrice Gasnier <fabrice.gasnier@st.com> wrote:
>
> On 8/27/20 10:55 AM, Alexandru Ardelean wrote:
> > On Wed, Aug 26, 2020 at 3:03 PM Alexandru Ardelean
> > <alexandru.ardelean@analog.com> wrote:
> >> 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. The lock protects against potential races when
> >> reading the CR reg and then updating, so that the state of pm_runtime
> >> is consistent between the two operations.
> >>
> >> Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
> >> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> >> ---
> > Forgot the changelog here.
> > Apologies.
> >
> > Changelog v1 -> v2:
> > * removed whitespace change for 'common' field
> > * updated comment about the lock usage
>
> Hi Alexandru,
>
> Sorry if I missed it... is there an update on the comment :-) ?
For a moment there, I thought I didn't.
GMail's threading is confusing.
----------------------------------------------------------------------------
As part of the general cleanup of indio_dev->mlock, this change replaces
it with a local lock. The lock protects against potential races when
reading the CR reg and then updating, so that the state of pm_runtime
is consistent between the two operations.
----------------------------------------------------------------------------
>
> Best Regards,
> Fabrice
> >
> >> drivers/iio/dac/stm32-dac.c | 12 ++++++++----
> >> 1 file changed, 8 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/drivers/iio/dac/stm32-dac.c b/drivers/iio/dac/stm32-dac.c
> >> index 092c796fa3d9..7a8aed476850 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 mutex lock;
> >> };
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2] iio: stm32-dac: Replace indio_dev->mlock with own device lock
2020-08-27 10:00 ` Alexandru Ardelean
@ 2020-08-29 15:46 ` Jonathan Cameron
2020-09-02 6:12 ` Alexandru Ardelean
0 siblings, 1 reply; 12+ messages in thread
From: Jonathan Cameron @ 2020-08-29 15:46 UTC (permalink / raw)
To: Alexandru Ardelean
Cc: Fabrice Gasnier, Alexandru Ardelean, linux-iio, linux-stm32,
LKML, linux-arm-kernel, alexandre.torgue, Sergiu Cuciurean
On Thu, 27 Aug 2020 13:00:36 +0300
Alexandru Ardelean <ardeleanalex@gmail.com> wrote:
> On Thu, Aug 27, 2020 at 12:03 PM Fabrice Gasnier <fabrice.gasnier@st.com> wrote:
> >
> > On 8/27/20 10:55 AM, Alexandru Ardelean wrote:
> > > On Wed, Aug 26, 2020 at 3:03 PM Alexandru Ardelean
> > > <alexandru.ardelean@analog.com> wrote:
> > >> 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. The lock protects against potential races when
> > >> reading the CR reg and then updating, so that the state of pm_runtime
> > >> is consistent between the two operations.
> > >>
> > >> Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
> > >> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> > >> ---
> > > Forgot the changelog here.
> > > Apologies.
> > >
> > > Changelog v1 -> v2:
> > > * removed whitespace change for 'common' field
> > > * updated comment about the lock usage
> >
> > Hi Alexandru,
> >
> > Sorry if I missed it... is there an update on the comment :-) ?
>
> For a moment there, I thought I didn't.
> GMail's threading is confusing.
>
> ----------------------------------------------------------------------------
> As part of the general cleanup of indio_dev->mlock, this change replaces
> it with a local lock. The lock protects against potential races when
> reading the CR reg and then updating, so that the state of pm_runtime
> is consistent between the two operations.
> ----------------------------------------------------------------------------
I think this got confused...
see below.
>
> >
> > Best Regards,
> > Fabrice
> > >
> > >> drivers/iio/dac/stm32-dac.c | 12 ++++++++----
> > >> 1 file changed, 8 insertions(+), 4 deletions(-)
> > >>
> > >> diff --git a/drivers/iio/dac/stm32-dac.c b/drivers/iio/dac/stm32-dac.c
> > >> index 092c796fa3d9..7a8aed476850 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
The original comment was:
In this particular case I'm not sure that's what mlock was being used for.
I think it's about avoiding races around checking if powered down and
actually doing it.
And Fabrice's reply:
Hi Sergiu,
Indeed, purpose is to protect against a race here when reading CR, and
updating it via regmap (this also makes the subsequent pm_runtime calls
to be balanced based on this).
(Side note: there is no data buffer involved for the DAC.)
Could you please update the comment ?
Thanks,
Fabrice
> > >> */
> > >> struct stm32_dac {
> > >> struct stm32_dac_common *common;
> > >> + struct mutex lock;
> > >> };
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2] iio: stm32-dac: Replace indio_dev->mlock with own device lock
2020-08-29 15:46 ` Jonathan Cameron
@ 2020-09-02 6:12 ` Alexandru Ardelean
0 siblings, 0 replies; 12+ messages in thread
From: Alexandru Ardelean @ 2020-09-02 6:12 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Fabrice Gasnier, Alexandru Ardelean, linux-iio, linux-stm32,
LKML, linux-arm-kernel, alexandre.torgue, Sergiu Cuciurean
On Sat, Aug 29, 2020 at 6:46 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Thu, 27 Aug 2020 13:00:36 +0300
> Alexandru Ardelean <ardeleanalex@gmail.com> wrote:
>
> > On Thu, Aug 27, 2020 at 12:03 PM Fabrice Gasnier <fabrice.gasnier@st.com> wrote:
> > >
> > > On 8/27/20 10:55 AM, Alexandru Ardelean wrote:
> > > > On Wed, Aug 26, 2020 at 3:03 PM Alexandru Ardelean
> > > > <alexandru.ardelean@analog.com> wrote:
> > > >> 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. The lock protects against potential races when
> > > >> reading the CR reg and then updating, so that the state of pm_runtime
> > > >> is consistent between the two operations.
> > > >>
> > > >> Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
> > > >> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> > > >> ---
> > > > Forgot the changelog here.
> > > > Apologies.
> > > >
> > > > Changelog v1 -> v2:
> > > > * removed whitespace change for 'common' field
> > > > * updated comment about the lock usage
> > >
> > > Hi Alexandru,
> > >
> > > Sorry if I missed it... is there an update on the comment :-) ?
> >
> > For a moment there, I thought I didn't.
> > GMail's threading is confusing.
> >
> > ----------------------------------------------------------------------------
> > As part of the general cleanup of indio_dev->mlock, this change replaces
> > it with a local lock. The lock protects against potential races when
> > reading the CR reg and then updating, so that the state of pm_runtime
> > is consistent between the two operations.
> > ----------------------------------------------------------------------------
> I think this got confused...
>
> see below.
>
>
> >
> > >
> > > Best Regards,
> > > Fabrice
> > > >
> > > >> drivers/iio/dac/stm32-dac.c | 12 ++++++++----
> > > >> 1 file changed, 8 insertions(+), 4 deletions(-)
> > > >>
> > > >> diff --git a/drivers/iio/dac/stm32-dac.c b/drivers/iio/dac/stm32-dac.c
> > > >> index 092c796fa3d9..7a8aed476850 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
oh, silly me;
it's about this comment;
will re-spin
>
> The original comment was:
>
>
> In this particular case I'm not sure that's what mlock was being used for.
> I think it's about avoiding races around checking if powered down and
> actually doing it.
>
> And Fabrice's reply:
>
> Hi Sergiu,
>
> Indeed, purpose is to protect against a race here when reading CR, and
> updating it via regmap (this also makes the subsequent pm_runtime calls
> to be balanced based on this).
> (Side note: there is no data buffer involved for the DAC.)
> Could you please update the comment ?
>
> Thanks,
> Fabrice
>
> > > >> */
> > > >> struct stm32_dac {
> > > >> struct stm32_dac_common *common;
> > > >> + struct mutex lock;
> > > >> };
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2] iio: stm32-dac: Replace indio_dev->mlock with own device lock
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 12:00 ` [PATCH v2] " Alexandru Ardelean
@ 2020-09-16 9:23 ` Alexandru Ardelean
2020-09-16 10:18 ` Fabrice Gasnier
2 siblings, 1 reply; 12+ messages in thread
From: Alexandru Ardelean @ 2020-09-16 9:23 UTC (permalink / raw)
To: linux-iio, linux-stm32, linux-arm-kernel, linux-kernel
Cc: jic23, mcoquelin.stm32, alexandre.torgue, olivier.moysan,
fabrice.gasnier, Sergiu Cuciurean, Alexandru Ardelean
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. The lock protects against potential races when
reading the CR reg and then updating, so that the state of pm_runtime
is consistent between the two operations.
This is part of a bigger cleanup.
Link: https://lore.kernel.org/linux-iio/CA+U=Dsoo6YABe5ODLp+eFNPGFDjk5ZeQEceGkqjxXcVEhLWubw@mail.gmail.com/
Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
drivers/iio/dac/stm32-dac.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/dac/stm32-dac.c b/drivers/iio/dac/stm32-dac.c
index 092c796fa3d9..12dec68c16f7 100644
--- a/drivers/iio/dac/stm32-dac.c
+++ b/drivers/iio/dac/stm32-dac.c
@@ -26,9 +26,12 @@
/**
* struct stm32_dac - private data of DAC driver
* @common: reference to DAC common data
+ * @lock: lock to protect against potential races when reading
+ * and update CR, to keep it in sync with pm_runtime
*/
struct stm32_dac {
struct stm32_dac_common *common;
+ struct mutex lock;
};
static int stm32_dac_is_enabled(struct iio_dev *indio_dev, int channel)
@@ -58,10 +61,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 +72,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 +330,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.17.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v2] iio: stm32-dac: Replace indio_dev->mlock with own device lock
2020-09-16 9:23 ` Alexandru Ardelean
@ 2020-09-16 10:18 ` Fabrice Gasnier
2020-09-16 17:52 ` Jonathan Cameron
0 siblings, 1 reply; 12+ messages in thread
From: Fabrice Gasnier @ 2020-09-16 10:18 UTC (permalink / raw)
To: Alexandru Ardelean, linux-iio, linux-stm32, linux-arm-kernel,
linux-kernel
Cc: jic23, mcoquelin.stm32, alexandre.torgue, olivier.moysan,
Sergiu Cuciurean
On 9/16/20 11:23 AM, Alexandru Ardelean wrote:
> 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. The lock protects against potential races when
> reading the CR reg and then updating, so that the state of pm_runtime
> is consistent between the two operations.
>
> This is part of a bigger cleanup.
> Link: https://lore.kernel.org/linux-iio/CA+U=Dsoo6YABe5ODLp+eFNPGFDjk5ZeQEceGkqjxXcVEhLWubw@mail.gmail.com/
>
> Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> ---
> drivers/iio/dac/stm32-dac.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
Hi Alexandru,
Many thanks for this updated patch,
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@st.com>
Best regards,
Fabrice
>
> diff --git a/drivers/iio/dac/stm32-dac.c b/drivers/iio/dac/stm32-dac.c
> index 092c796fa3d9..12dec68c16f7 100644
> --- a/drivers/iio/dac/stm32-dac.c
> +++ b/drivers/iio/dac/stm32-dac.c
> @@ -26,9 +26,12 @@
> /**
> * struct stm32_dac - private data of DAC driver
> * @common: reference to DAC common data
> + * @lock: lock to protect against potential races when reading
> + * and update CR, to keep it in sync with pm_runtime
> */
> struct stm32_dac {
> struct stm32_dac_common *common;
> + struct mutex lock;
> };
>
> static int stm32_dac_is_enabled(struct iio_dev *indio_dev, int channel)
> @@ -58,10 +61,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 +72,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 +330,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;
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2] iio: stm32-dac: Replace indio_dev->mlock with own device lock
2020-09-16 10:18 ` Fabrice Gasnier
@ 2020-09-16 17:52 ` Jonathan Cameron
0 siblings, 0 replies; 12+ messages in thread
From: Jonathan Cameron @ 2020-09-16 17:52 UTC (permalink / raw)
To: Fabrice Gasnier
Cc: Alexandru Ardelean, linux-iio, linux-stm32, linux-arm-kernel,
linux-kernel, mcoquelin.stm32, alexandre.torgue, olivier.moysan,
Sergiu Cuciurean
On Wed, 16 Sep 2020 12:18:02 +0200
Fabrice Gasnier <fabrice.gasnier@st.com> wrote:
> On 9/16/20 11:23 AM, Alexandru Ardelean wrote:
> > 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. The lock protects against potential races when
> > reading the CR reg and then updating, so that the state of pm_runtime
> > is consistent between the two operations.
> >
> > This is part of a bigger cleanup.
> > Link: https://lore.kernel.org/linux-iio/CA+U=Dsoo6YABe5ODLp+eFNPGFDjk5ZeQEceGkqjxXcVEhLWubw@mail.gmail.com/
> >
> > Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
> > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> > ---
> > drivers/iio/dac/stm32-dac.c | 13 +++++++++----
> > 1 file changed, 9 insertions(+), 4 deletions(-)
>
> Hi Alexandru,
>
> Many thanks for this updated patch,
>
> Reviewed-by: Fabrice Gasnier <fabrice.gasnier@st.com>
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to poke at it.
Thanks,
Jonathan
>
> Best regards,
> Fabrice
>
> >
> > diff --git a/drivers/iio/dac/stm32-dac.c b/drivers/iio/dac/stm32-dac.c
> > index 092c796fa3d9..12dec68c16f7 100644
> > --- a/drivers/iio/dac/stm32-dac.c
> > +++ b/drivers/iio/dac/stm32-dac.c
> > @@ -26,9 +26,12 @@
> > /**
> > * struct stm32_dac - private data of DAC driver
> > * @common: reference to DAC common data
> > + * @lock: lock to protect against potential races when reading
> > + * and update CR, to keep it in sync with pm_runtime
> > */
> > struct stm32_dac {
> > struct stm32_dac_common *common;
> > + struct mutex lock;
> > };
> >
> > static int stm32_dac_is_enabled(struct iio_dev *indio_dev, int channel)
> > @@ -58,10 +61,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 +72,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 +330,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;
> >
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2020-09-16 20:15 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 10:01 ` Alexandru Ardelean
2020-08-26 12:00 ` [PATCH v2] " Alexandru Ardelean
2020-08-27 8:55 ` Alexandru Ardelean
2020-08-27 9:03 ` Fabrice Gasnier
2020-08-27 10:00 ` Alexandru Ardelean
2020-08-29 15:46 ` Jonathan Cameron
2020-09-02 6:12 ` Alexandru Ardelean
2020-09-16 9:23 ` Alexandru Ardelean
2020-09-16 10:18 ` Fabrice Gasnier
2020-09-16 17:52 ` Jonathan Cameron
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).