[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20211118123952.15383-1-olivier.moysan@foss.st.com>
Date: Thu, 18 Nov 2021 13:39:52 +0100
From: Olivier Moysan <olivier.moysan@...s.st.com>
To: Ahmad Fatoum <a.fatoum@...gutronix.de>,
Alexandre Torgue <alexandre.torgue@...s.st.com>,
Fabrice Gasnier <fabrice.gasnier@...s.st.com>,
Jonathan Cameron <jic23@...nel.org>,
Lars-Peter Clausen <lars@...afoo.de>,
Mauro Carvalho Chehab <mchehab+huawei@...nel.org>,
Maxime Coquelin <mcoquelin.stm32@...il.com>,
Olivier Moysan <olivier.moysan@...s.st.com>,
Wan Jiabing <wanjiabing@...o.com>, Xu Wang <vulab@...as.ac.cn>
CC: <linux-arm-kernel@...ts.infradead.org>,
<linux-iio@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<linux-stm32@...md-mailman.stormreply.com>
Subject: [PATCH] iio: adc: stm32: fix null pointer on defer_probe error
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@...s.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
Powered by blists - more mailing lists