From: Fabrice Gasnier <fabrice.gasnier@st.com>
To: Jonathan Cameron <jic23@kernel.org>,
Sergiu Cuciurean <sergiu.cuciurean@analog.com>
Cc: <linux-kernel@vger.kernel.org>, <linux-iio@vger.kernel.org>,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@st.com>,
<linux-stm32@st-md-mailman.stormreply.com>,
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH] iio: stm32-dac: Replace indio_dev->mlock with own device lock
Date: Mon, 18 May 2020 11:22:40 +0200 [thread overview]
Message-ID: <9f271d8d-4ee9-1633-fb90-faca53072716@st.com> (raw)
In-Reply-To: <20200516163521.2812cf86@archlinux>
On 5/16/20 5:35 PM, Jonathan Cameron wrote:
> On Thu, 14 May 2020 11:50:12 +0300
> Sergiu Cuciurean <sergiu.cuciurean@analog.com> wrote:
>
>> As part of the general cleanup of indio_dev->mlock, this change replaces
>> it with a local lock on the device's state structure.
>>
>> Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@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 f22c1d9129b2..74b9474c8590 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
>
> 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.
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;
>> };
>>
>> 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");
>> @@ -328,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;
>
next prev parent reply other threads:[~2020-05-18 9:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-14 8:50 [PATCH] iio: stm32-dac: Replace indio_dev->mlock with own device lock Sergiu Cuciurean
2020-05-16 15:35 ` Jonathan Cameron
2020-05-18 9:22 ` Fabrice Gasnier [this message]
2020-08-26 6:38 Alexandru Ardelean
2020-08-26 8:57 ` Fabrice Gasnier
2020-08-26 10:01 ` Alexandru Ardelean
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=9f271d8d-4ee9-1633-fb90-faca53072716@st.com \
--to=fabrice.gasnier@st.com \
--cc=alexandre.torgue@st.com \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--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=mcoquelin.stm32@gmail.com \
--cc=pmeerw@pmeerw.net \
--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 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).