Message ID | 20221004134909.1692021-4-nuno.sa@analog.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Make 'mlock' really private | expand |
> -----Original Message----- > From: Nuno Sá <nuno.sa@analog.com> > Sent: 2022年10月4日 21:49 > To: linux-amlogic@lists.infradead.org; dl-linux-imx <linux-imx@nxp.com>; > linux-iio@vger.kernel.org; linux-arm-kernel@lists.infradead.org; > linux-rockchip@lists.infradead.org > Cc: Heiko Stuebner <heiko@sntech.de>; Martin Blumenstingl > <martin.blumenstingl@googlemail.com>; Neil Armstrong > <narmstrong@baylibre.com>; Shawn Guo <shawnguo@kernel.org>; Lars-Peter > Clausen <lars@metafoo.de>; Jyoti Bhayana <jbhayana@google.com>; Hans de > Goede <hdegoede@redhat.com>; Andriy Tryshnivskyy > <andriy.tryshnivskyy@opensynergy.com>; Pengutronix Kernel Team > <kernel@pengutronix.de>; Miquel Raynal <miquel.raynal@bootlin.com>; Cixi > Geng <cixi.geng1@unisoc.com>; Baolin Wang > <baolin.wang@linux.alibaba.com>; Ciprian Regus <ciprian.regus@analog.com>; > Fabio Estevam <festevam@gmail.com>; Nuno Sá <nuno.sa@analog.com>; > Sascha Hauer <s.hauer@pengutronix.de>; Alexandru Ardelean > <aardelean@deviqon.com>; Florian Boor <florian.boor@kernelconcepts.de>; > Michael Hennerich <Michael.Hennerich@analog.com>; Orson Zhai > <orsonzhai@gmail.com>; Chen-Yu Tsai <wens@csie.org>; Chunyan Zhang > <zhang.lyra@gmail.com>; Vladimir Zapolskiy <vz@mleia.com>; Andy > Shevchenko <andy.shevchenko@gmail.com>; Jerome Brunet > <jbrunet@baylibre.com>; Bough Chen <haibo.chen@nxp.com>; Kevin Hilman > <khilman@baylibre.com>; Jonathan Cameron <jic23@kernel.org> > Subject: [PATCH v2 03/16] iio: adc: imx7d_adc: do not use internal iio_dev lock > > The iio_device lock is only meant for internal use. Hence define a device local > lock to protect against concurrent accesses. > > While at it, properly include "mutex.h" for mutex related APIs. > > Signed-off-by: Nuno Sá <nuno.sa@analog.com> Reviewed-by: Haibo Chen <haibo.chen@nxp.com> Thanks! Best Regards Haibo Chen > --- > drivers/iio/adc/imx7d_adc.c | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c index > 86caff1d006b..22da81bac97f 100644 > --- a/drivers/iio/adc/imx7d_adc.c > +++ b/drivers/iio/adc/imx7d_adc.c > @@ -13,6 +13,7 @@ > #include <linux/kernel.h> > #include <linux/mod_devicetable.h> > #include <linux/module.h> > +#include <linux/mutex.h> > #include <linux/platform_device.h> > #include <linux/regulator/consumer.h> > > @@ -108,7 +109,8 @@ struct imx7d_adc { > struct device *dev; > void __iomem *regs; > struct clk *clk; > - > + /* lock to protect against multiple access to the device */ > + struct mutex lock; > u32 vref_uv; > u32 value; > u32 channel; > @@ -293,7 +295,7 @@ static int imx7d_adc_read_raw(struct iio_dev > *indio_dev, > > switch (mask) { > case IIO_CHAN_INFO_RAW: > - mutex_lock(&indio_dev->mlock); > + mutex_lock(&info->lock); > reinit_completion(&info->completion); > > channel = chan->channel & 0x03; > @@ -303,16 +305,16 @@ static int imx7d_adc_read_raw(struct iio_dev > *indio_dev, > ret = wait_for_completion_interruptible_timeout > (&info->completion, IMX7D_ADC_TIMEOUT); > if (ret == 0) { > - mutex_unlock(&indio_dev->mlock); > + mutex_unlock(&info->lock); > return -ETIMEDOUT; > } > if (ret < 0) { > - mutex_unlock(&indio_dev->mlock); > + mutex_unlock(&info->lock); > return ret; > } > > *val = info->value; > - mutex_unlock(&indio_dev->mlock); > + mutex_unlock(&info->lock); > return IIO_VAL_INT; > > case IIO_CHAN_INFO_SCALE: > @@ -531,6 +533,8 @@ static int imx7d_adc_probe(struct platform_device > *pdev) > if (ret) > return ret; > > + mutex_init(&info->lock); > + > ret = devm_iio_device_register(dev, indio_dev); > if (ret) { > dev_err(&pdev->dev, "Couldn't register the device.\n"); > -- > 2.37.3
On Sun, 9 Oct 2022 02:00:22 +0000 Bough Chen <haibo.chen@nxp.com> wrote: > > -----Original Message----- > > From: Nuno Sá <nuno.sa@analog.com> > > Sent: 2022年10月4日 21:49 > > To: linux-amlogic@lists.infradead.org; dl-linux-imx <linux-imx@nxp.com>; > > linux-iio@vger.kernel.org; linux-arm-kernel@lists.infradead.org; > > linux-rockchip@lists.infradead.org > > Cc: Heiko Stuebner <heiko@sntech.de>; Martin Blumenstingl > > <martin.blumenstingl@googlemail.com>; Neil Armstrong > > <narmstrong@baylibre.com>; Shawn Guo <shawnguo@kernel.org>; Lars-Peter > > Clausen <lars@metafoo.de>; Jyoti Bhayana <jbhayana@google.com>; Hans de > > Goede <hdegoede@redhat.com>; Andriy Tryshnivskyy > > <andriy.tryshnivskyy@opensynergy.com>; Pengutronix Kernel Team > > <kernel@pengutronix.de>; Miquel Raynal <miquel.raynal@bootlin.com>; Cixi > > Geng <cixi.geng1@unisoc.com>; Baolin Wang > > <baolin.wang@linux.alibaba.com>; Ciprian Regus <ciprian.regus@analog.com>; > > Fabio Estevam <festevam@gmail.com>; Nuno Sá <nuno.sa@analog.com>; > > Sascha Hauer <s.hauer@pengutronix.de>; Alexandru Ardelean > > <aardelean@deviqon.com>; Florian Boor <florian.boor@kernelconcepts.de>; > > Michael Hennerich <Michael.Hennerich@analog.com>; Orson Zhai > > <orsonzhai@gmail.com>; Chen-Yu Tsai <wens@csie.org>; Chunyan Zhang > > <zhang.lyra@gmail.com>; Vladimir Zapolskiy <vz@mleia.com>; Andy > > Shevchenko <andy.shevchenko@gmail.com>; Jerome Brunet > > <jbrunet@baylibre.com>; Bough Chen <haibo.chen@nxp.com>; Kevin Hilman > > <khilman@baylibre.com>; Jonathan Cameron <jic23@kernel.org> > > Subject: [PATCH v2 03/16] iio: adc: imx7d_adc: do not use internal iio_dev lock > > > > The iio_device lock is only meant for internal use. Hence define a device local > > lock to protect against concurrent accesses. > > > > While at it, properly include "mutex.h" for mutex related APIs. > > > > Signed-off-by: Nuno Sá <nuno.sa@analog.com> > > Reviewed-by: Haibo Chen <haibo.chen@nxp.com> Applied to the togreg branch of iio.git and pushed out as testing for 0-day to take a look at it. Note I'll be rebasing on rc1 once available. Thanks, Jonathan
diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c index 86caff1d006b..22da81bac97f 100644 --- a/drivers/iio/adc/imx7d_adc.c +++ b/drivers/iio/adc/imx7d_adc.c @@ -13,6 +13,7 @@ #include <linux/kernel.h> #include <linux/mod_devicetable.h> #include <linux/module.h> +#include <linux/mutex.h> #include <linux/platform_device.h> #include <linux/regulator/consumer.h> @@ -108,7 +109,8 @@ struct imx7d_adc { struct device *dev; void __iomem *regs; struct clk *clk; - + /* lock to protect against multiple access to the device */ + struct mutex lock; u32 vref_uv; u32 value; u32 channel; @@ -293,7 +295,7 @@ static int imx7d_adc_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - mutex_lock(&indio_dev->mlock); + mutex_lock(&info->lock); reinit_completion(&info->completion); channel = chan->channel & 0x03; @@ -303,16 +305,16 @@ static int imx7d_adc_read_raw(struct iio_dev *indio_dev, ret = wait_for_completion_interruptible_timeout (&info->completion, IMX7D_ADC_TIMEOUT); if (ret == 0) { - mutex_unlock(&indio_dev->mlock); + mutex_unlock(&info->lock); return -ETIMEDOUT; } if (ret < 0) { - mutex_unlock(&indio_dev->mlock); + mutex_unlock(&info->lock); return ret; } *val = info->value; - mutex_unlock(&indio_dev->mlock); + mutex_unlock(&info->lock); return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: @@ -531,6 +533,8 @@ static int imx7d_adc_probe(struct platform_device *pdev) if (ret) return ret; + mutex_init(&info->lock); + ret = devm_iio_device_register(dev, indio_dev); if (ret) { dev_err(&pdev->dev, "Couldn't register the device.\n");
The iio_device lock is only meant for internal use. Hence define a device local lock to protect against concurrent accesses. While at it, properly include "mutex.h" for mutex related APIs. Signed-off-by: Nuno Sá <nuno.sa@analog.com> --- drivers/iio/adc/imx7d_adc.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)