* [PATCH] iio: adc: stm32: fix null pointer on defer_probe error
@ 2021-11-18 12:39 Olivier Moysan
2021-11-18 12:51 ` Ahmad Fatoum
0 siblings, 1 reply; 3+ messages in thread
From: Olivier Moysan @ 2021-11-18 12:39 UTC (permalink / raw)
To: Ahmad Fatoum, Alexandre Torgue, Fabrice Gasnier,
Jonathan Cameron, Lars-Peter Clausen, Mauro Carvalho Chehab,
Maxime Coquelin, Olivier Moysan, Wan Jiabing, Xu Wang
Cc: linux-arm-kernel, linux-iio, linux-kernel, linux-stm32
dev_err_probe() calls __device_set_deferred_probe_reason()
on -EPROBE_DEFER error.
If device pointer to driver core private structure is not initialized,
a null pointer error occurs.
This pointer is set too late on iio_device_register() call, for iio device.
So use parent device instead for dev_err_probe() call.
Fixes: 0e346b2cfa85 ("iio: adc: stm32-adc: add vrefint calibration support")
Signed-off-by: Olivier Moysan <olivier.moysan@foss.st.com>
---
drivers/iio/adc/stm32-adc.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
index 7f1fb36c747c..14c7c9d390e8 100644
--- a/drivers/iio/adc/stm32-adc.c
+++ b/drivers/iio/adc/stm32-adc.c
@@ -217,6 +217,7 @@ struct stm32_adc_cfg {
/**
* struct stm32_adc - private data of each ADC IIO instance
+ * dev: parent device
* @common: reference to ADC block common data
* @offset: ADC instance register offset in ADC block
* @cfg: compatible configuration data
@@ -243,6 +244,7 @@ struct stm32_adc_cfg {
* @int_ch: internal channel indexes array
*/
struct stm32_adc {
+ struct device *dev;
struct stm32_adc_common *common;
u32 offset;
const struct stm32_adc_cfg *cfg;
@@ -1986,8 +1988,7 @@ static int stm32_adc_populate_int_ch(struct iio_dev *indio_dev, const char *ch_n
/* Get calibration data for vrefint channel */
ret = nvmem_cell_read_u16(&indio_dev->dev, "vrefint", &vrefint);
if (ret && ret != -ENOENT) {
- return dev_err_probe(&indio_dev->dev, ret,
- "nvmem access error\n");
+ return dev_err_probe(adc->dev, ret, "nvmem access error\n");
}
if (ret == -ENOENT)
dev_dbg(&indio_dev->dev, "vrefint calibration not found\n");
@@ -2221,6 +2222,7 @@ static int stm32_adc_probe(struct platform_device *pdev)
init_completion(&adc->completion);
adc->cfg = (const struct stm32_adc_cfg *)
of_match_device(dev->driver->of_match_table, dev)->data;
+ adc->dev = &pdev->dev;
indio_dev->name = dev_name(&pdev->dev);
indio_dev->dev.of_node = pdev->dev.of_node;
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: adc: stm32: fix null pointer on defer_probe error
2021-11-18 12:39 [PATCH] iio: adc: stm32: fix null pointer on defer_probe error Olivier Moysan
@ 2021-11-18 12:51 ` Ahmad Fatoum
2021-11-18 18:11 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Ahmad Fatoum @ 2021-11-18 12:51 UTC (permalink / raw)
To: Olivier Moysan, Alexandre Torgue, Fabrice Gasnier,
Jonathan Cameron, Lars-Peter Clausen, Mauro Carvalho Chehab,
Maxime Coquelin, Wan Jiabing, Xu Wang
Cc: linux-arm-kernel, linux-iio, linux-kernel, linux-stm32
Hello Olivier,
On 18.11.21 13:39, Olivier Moysan wrote:
> dev_err_probe() calls __device_set_deferred_probe_reason()
> on -EPROBE_DEFER error.
> If device pointer to driver core private structure is not initialized,
> a null pointer error occurs.
> This pointer is set too late on iio_device_register() call, for iio device.
Even if it were set earlier, you should call dev_err_probe with the dev of
the probe that's currently running. Not any other devices you created since
then.
> So use parent device instead for dev_err_probe() call.
>
> Fixes: 0e346b2cfa85 ("iio: adc: stm32-adc: add vrefint calibration support")
>
> Signed-off-by: Olivier Moysan <olivier.moysan@foss.st.com>
> ---
> drivers/iio/adc/stm32-adc.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
> index 7f1fb36c747c..14c7c9d390e8 100644
> --- a/drivers/iio/adc/stm32-adc.c
> +++ b/drivers/iio/adc/stm32-adc.c
> @@ -217,6 +217,7 @@ struct stm32_adc_cfg {
>
> /**
> * struct stm32_adc - private data of each ADC IIO instance
> + * dev: parent device
> * @common: reference to ADC block common data
> * @offset: ADC instance register offset in ADC block
> * @cfg: compatible configuration data
> @@ -243,6 +244,7 @@ struct stm32_adc_cfg {
> * @int_ch: internal channel indexes array
> */
> struct stm32_adc {
> + struct device *dev;
Can't you use the parent pointer of the indio_dev?
> struct stm32_adc_common *common;
> u32 offset;
> const struct stm32_adc_cfg *cfg;
> @@ -1986,8 +1988,7 @@ static int stm32_adc_populate_int_ch(struct iio_dev *indio_dev, const char *ch_n
> /* Get calibration data for vrefint channel */
> ret = nvmem_cell_read_u16(&indio_dev->dev, "vrefint", &vrefint);
> if (ret && ret != -ENOENT) {
> - return dev_err_probe(&indio_dev->dev, ret,
> - "nvmem access error\n");
> + return dev_err_probe(adc->dev, ret, "nvmem access error\n");
> }
> if (ret == -ENOENT)
> dev_dbg(&indio_dev->dev, "vrefint calibration not found\n");
> @@ -2221,6 +2222,7 @@ static int stm32_adc_probe(struct platform_device *pdev)
> init_completion(&adc->completion);
> adc->cfg = (const struct stm32_adc_cfg *)
> of_match_device(dev->driver->of_match_table, dev)->data;
> + adc->dev = &pdev->dev;
There's struct device *dev = &pdev->dev; defined earlier, so you can use dev instead.
>
> indio_dev->name = dev_name(&pdev->dev);
> indio_dev->dev.of_node = pdev->dev.of_node;
>
Cheers,
Ahmad
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: adc: stm32: fix null pointer on defer_probe error
2021-11-18 12:51 ` Ahmad Fatoum
@ 2021-11-18 18:11 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2021-11-18 18:11 UTC (permalink / raw)
To: Ahmad Fatoum
Cc: Olivier Moysan, Alexandre Torgue, Fabrice Gasnier,
Jonathan Cameron, Lars-Peter Clausen, Mauro Carvalho Chehab,
Maxime Coquelin, Wan Jiabing, Xu Wang, linux-arm-kernel,
linux-iio, linux-kernel, linux-stm32
On Thu, 18 Nov 2021 13:51:44 +0100
Ahmad Fatoum <a.fatoum@pengutronix.de> wrote:
> Hello Olivier,
>
> On 18.11.21 13:39, Olivier Moysan wrote:
> > dev_err_probe() calls __device_set_deferred_probe_reason()
> > on -EPROBE_DEFER error.
> > If device pointer to driver core private structure is not initialized,
> > a null pointer error occurs.
> > This pointer is set too late on iio_device_register() call, for iio device.
>
> Even if it were set earlier, you should call dev_err_probe with the dev of
> the probe that's currently running. Not any other devices you created since
> then.
+1 on that
>
> > So use parent device instead for dev_err_probe() call.
> >
> > Fixes: 0e346b2cfa85 ("iio: adc: stm32-adc: add vrefint calibration support")
> >
No line break between these two tags. Greg will reject a pull if there
is one (and 0-day probably complain about it...)
Jonathan
> > Signed-off-by: Olivier Moysan <olivier.moysan@foss.st.com>
> > ---
> > drivers/iio/adc/stm32-adc.c | 6 ++++--
> > 1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
> > index 7f1fb36c747c..14c7c9d390e8 100644
> > --- a/drivers/iio/adc/stm32-adc.c
> > +++ b/drivers/iio/adc/stm32-adc.c
> > @@ -217,6 +217,7 @@ struct stm32_adc_cfg {
> >
> > /**
> > * struct stm32_adc - private data of each ADC IIO instance
> > + * dev: parent device
> > * @common: reference to ADC block common data
> > * @offset: ADC instance register offset in ADC block
> > * @cfg: compatible configuration data
> > @@ -243,6 +244,7 @@ struct stm32_adc_cfg {
> > * @int_ch: internal channel indexes array
> > */
> > struct stm32_adc {
> > + struct device *dev;
>
> Can't you use the parent pointer of the indio_dev?
>
> > struct stm32_adc_common *common;
> > u32 offset;
> > const struct stm32_adc_cfg *cfg;
> > @@ -1986,8 +1988,7 @@ static int stm32_adc_populate_int_ch(struct iio_dev *indio_dev, const char *ch_n
> > /* Get calibration data for vrefint channel */
> > ret = nvmem_cell_read_u16(&indio_dev->dev, "vrefint", &vrefint);
> > if (ret && ret != -ENOENT) {
> > - return dev_err_probe(&indio_dev->dev, ret,
> > - "nvmem access error\n");
> > + return dev_err_probe(adc->dev, ret, "nvmem access error\n");
> > }
> > if (ret == -ENOENT)
> > dev_dbg(&indio_dev->dev, "vrefint calibration not found\n");
> > @@ -2221,6 +2222,7 @@ static int stm32_adc_probe(struct platform_device *pdev)
> > init_completion(&adc->completion);
> > adc->cfg = (const struct stm32_adc_cfg *)
> > of_match_device(dev->driver->of_match_table, dev)->data;
> > + adc->dev = &pdev->dev;
>
> There's struct device *dev = &pdev->dev; defined earlier, so you can use dev instead.
>
> >
> > indio_dev->name = dev_name(&pdev->dev);
> > indio_dev->dev.of_node = pdev->dev.of_node;
> >
>
> Cheers,
> Ahmad
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-18 18:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-18 12:39 [PATCH] iio: adc: stm32: fix null pointer on defer_probe error Olivier Moysan
2021-11-18 12:51 ` Ahmad Fatoum
2021-11-18 18:11 ` 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).