mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
iio: dac: mcp4821: reject devices without match data
A device bound through driver_override need not match an entry in the
driver tables. In that case spi_get_device_match_data() returns NULL,
but mcp4821_probe() dereferences the result while configuring the IIO
device.
Reject devices without match data before using the chip information.
Fixes: cdf3ecb0d8 ("iio: dac: driver for MCP4821")
Signed-off-by: Jiale Yao <yaojiale02@163.com>
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
This commit is contained in:
parent
85e2c8ca7a
commit
6ac1faf4de
|
|
@ -255,9 +255,13 @@ static const struct iio_info mcp4821_info = {
|
|||
|
||||
static int mcp4821_probe(struct spi_device *spi)
|
||||
{
|
||||
const struct mcp4821_chip_info *info;
|
||||
struct iio_dev *indio_dev;
|
||||
struct mcp4821_state *state;
|
||||
const struct mcp4821_chip_info *info;
|
||||
|
||||
info = spi_get_device_match_data(spi);
|
||||
if (!info)
|
||||
return -ENODATA;
|
||||
|
||||
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*state));
|
||||
if (indio_dev == NULL)
|
||||
|
|
@ -268,7 +272,6 @@ static int mcp4821_probe(struct spi_device *spi)
|
|||
|
||||
/* default gain is 2x */
|
||||
state->gain = 2;
|
||||
info = spi_get_device_match_data(spi);
|
||||
indio_dev->name = info->name;
|
||||
indio_dev->info = &mcp4821_info;
|
||||
indio_dev->modes = INDIO_DIRECT_MODE;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user