]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
iio: adc: ad7192: Fix null ad7192_state pointer access
authorFabrizio Lamarque <fl.scratchpad@gmail.com>
Tue, 30 May 2023 07:53:07 +0000 (09:53 +0200)
committerRoxana Nicolescu <roxana.nicolescu@canonical.com>
Mon, 2 Oct 2023 15:19:53 +0000 (17:19 +0200)
BugLink: https://bugs.launchpad.net/bugs/2034469
commit 9e58e3a6f8e1c483c86a04903b7b7aa0923e4426 upstream.

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.

Fix 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>
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Cc: <Stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20230530075311.400686-2-fl.scratchpad@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/iio/adc/ad7192.c

index 99bb604b78c8cf904271b1832bde8a91a1c13bc3..55a26dbd61089b13c2e58a4dea42777c56753b29 100644 (file)
@@ -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;
@@ -1069,7 +1069,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;