diff mbox series

[v2,1/3] iio: adc: ad7192: Fix null pointer dereference on probe

Message ID CAPJMGm4bv3PHiGa7B8uH+izmVOWVJnibmuZ-9GwnAGeGHmpN5w@mail.gmail.com (mailing list archive)
State Changes Requested
Headers show
Series iio: adc: ad7192: Functional fixes | expand

Commit Message

Fabrizio Lamarque April 13, 2023, 8:28 a.m. UTC
Pointer to indio_dev structure is obtained via spi_get_drvdata() at
the beginning of function ad7192_setup(), but the spi->dev->driver_data
member is not initialized, hence a NULL pointer is returned.

Fixed by changing ad7192_setup() signature to take pointer to struct
iio_dev, and get ad7192_state pointer via st = iio_priv(indio_dev);

Fixes: bd5dcdeb3fd0 iio: adc: ad7192: convert to device-managed functions
Signed-off-by: Fabrizio Lamarque <fl.scratchpad@gmail.com>
---
Changes in v2: obtained ad7192_state from iio_dev pointer as suggested
by Jonathan, removed Reviewed-by since the entire patch changed its
content.

 drivers/iio/adc/ad7192.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--
2.34.1

Comments

Nuno Sá April 13, 2023, 10:03 a.m. UTC | #1
On Thu, 2023-04-13 at 10:28 +0200, Fabrizio Lamarque wrote:
> Pointer to indio_dev structure is obtained via spi_get_drvdata() at
> the beginning of function ad7192_setup(), but the spi->dev->driver_data
> member is not initialized, hence a NULL pointer is returned.
> 
> Fixed by changing ad7192_setup() signature to take pointer to struct
> iio_dev, and get ad7192_state pointer via st = iio_priv(indio_dev);
> 
> Fixes: bd5dcdeb3fd0 iio: adc: ad7192: convert to device-managed functions

This should be:
Fixes: bd5dcdeb3fd0 ("iio: adc: ad7192: convert to device-managed functions")

(applies to the other patches in the series).
> Signed-off-by: Fabrizio Lamarque <fl.scratchpad@gmail.com>
> ---

With the above fixed:

Reviewed-by: Nuno Sa <nuno.sa@analog.com>

> Changes in v2: obtained ad7192_state from iio_dev pointer as suggested
> by Jonathan, removed Reviewed-by since the entire patch changed its
> content.
> 
>  drivers/iio/adc/ad7192.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c
> index 55a6ab591016..94a9cf34a255 100644
> --- a/drivers/iio/adc/ad7192.c
> +++ b/drivers/iio/adc/ad7192.c
> @@ -380,9 +380,9 @@ static int ad7192_of_clock_select(struct ad7192_state *st)
>   return clock_sel;
>  }
> 
> -static int ad7192_setup(struct ad7192_state *st, struct device_node *np)
> +static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np)
>  {
> - struct iio_dev *indio_dev = spi_get_drvdata(st->sd.spi);
> + struct ad7192_state *st = iio_priv(indio_dev);
>   bool rej60_en, refin2_en;
>   bool buf_en, bipolar, burnout_curr_en;
>   unsigned long long scale_uv;
> @@ -1073,7 +1073,7 @@ static int ad7192_probe(struct spi_device *spi)
>   }
>   }
> 
> - ret = ad7192_setup(st, spi->dev.of_node);
> + ret = ad7192_setup(indio_dev, spi->dev.of_node);
>   if (ret)
>   return ret;
> 
> --
> 2.34.1
Jonathan Cameron April 15, 2023, 4:41 p.m. UTC | #2
On Thu, 13 Apr 2023 10:28:11 +0200
Fabrizio Lamarque <fl.scratchpad@gmail.com> wrote:

> Pointer to indio_dev structure is obtained via spi_get_drvdata() at
> the beginning of function ad7192_setup(), but the spi->dev->driver_data
> member is not initialized, hence a NULL pointer is returned.
> 
> Fixed by changing ad7192_setup() signature to take pointer to struct
> iio_dev, and get ad7192_state pointer via st = iio_priv(indio_dev);
> 
> Fixes: bd5dcdeb3fd0 iio: adc: ad7192: convert to device-managed functions
> Signed-off-by: Fabrizio Lamarque <fl.scratchpad@gmail.com>
> ---
> Changes in v2: obtained ad7192_state from iio_dev pointer as suggested
> by Jonathan, removed Reviewed-by since the entire patch changed its
> content.

Great. Please just tidy up the Fixes tag formatting and send a v3.

Note that we are very late in current cycle, so I'll only queue these
up now for after 6.4-rc1 is available.  They'll get pulled back into stable
trees after that (in about 3-4 weeks time).

Thanks,

Jonathan

> 
>  drivers/iio/adc/ad7192.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c
> index 55a6ab591016..94a9cf34a255 100644
> --- a/drivers/iio/adc/ad7192.c
> +++ b/drivers/iio/adc/ad7192.c
> @@ -380,9 +380,9 @@ static int ad7192_of_clock_select(struct ad7192_state *st)
>   return clock_sel;
>  }
> 
> -static int ad7192_setup(struct ad7192_state *st, struct device_node *np)
> +static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np)
>  {
> - struct iio_dev *indio_dev = spi_get_drvdata(st->sd.spi);
> + struct ad7192_state *st = iio_priv(indio_dev);
>   bool rej60_en, refin2_en;
>   bool buf_en, bipolar, burnout_curr_en;
>   unsigned long long scale_uv;
> @@ -1073,7 +1073,7 @@ static int ad7192_probe(struct spi_device *spi)
>   }
>   }
> 
> - ret = ad7192_setup(st, spi->dev.of_node);
> + ret = ad7192_setup(indio_dev, spi->dev.of_node);
>   if (ret)
>   return ret;
> 
> --
> 2.34.1
diff mbox series

Patch

diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c
index 55a6ab591016..94a9cf34a255 100644
--- a/drivers/iio/adc/ad7192.c
+++ b/drivers/iio/adc/ad7192.c
@@ -380,9 +380,9 @@  static int ad7192_of_clock_select(struct ad7192_state *st)
  return clock_sel;
 }

-static int ad7192_setup(struct ad7192_state *st, struct device_node *np)
+static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np)
 {
- struct iio_dev *indio_dev = spi_get_drvdata(st->sd.spi);
+ struct ad7192_state *st = iio_priv(indio_dev);
  bool rej60_en, refin2_en;
  bool buf_en, bipolar, burnout_curr_en;
  unsigned long long scale_uv;
@@ -1073,7 +1073,7 @@  static int ad7192_probe(struct spi_device *spi)
  }
  }

- ret = ad7192_setup(st, spi->dev.of_node);
+ ret = ad7192_setup(indio_dev, spi->dev.of_node);
  if (ret)
  return ret;