Commit cf52d9ea authored by Kangjie Lu's avatar Kangjie Lu Committed by Kleber Sacilotto de Souza

iio: hmc5843: fix potential NULL pointer dereferences

BugLink: https://bugs.launchpad.net/bugs/1832661

[ Upstream commit 536cc27d ]

devm_regmap_init_i2c may fail and return NULL. The fix returns
the error when it fails.
Signed-off-by: default avatarKangjie Lu <kjlu@umn.edu>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 59b7bb33
...@@ -59,8 +59,13 @@ static const struct regmap_config hmc5843_i2c_regmap_config = { ...@@ -59,8 +59,13 @@ static const struct regmap_config hmc5843_i2c_regmap_config = {
static int hmc5843_i2c_probe(struct i2c_client *cli, static int hmc5843_i2c_probe(struct i2c_client *cli,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct regmap *regmap = devm_regmap_init_i2c(cli,
&hmc5843_i2c_regmap_config);
if (IS_ERR(regmap))
return PTR_ERR(regmap);
return hmc5843_common_probe(&cli->dev, return hmc5843_common_probe(&cli->dev,
devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config), regmap,
id->driver_data, id->name); id->driver_data, id->name);
} }
......
...@@ -59,6 +59,7 @@ static const struct regmap_config hmc5843_spi_regmap_config = { ...@@ -59,6 +59,7 @@ static const struct regmap_config hmc5843_spi_regmap_config = {
static int hmc5843_spi_probe(struct spi_device *spi) static int hmc5843_spi_probe(struct spi_device *spi)
{ {
int ret; int ret;
struct regmap *regmap;
const struct spi_device_id *id = spi_get_device_id(spi); const struct spi_device_id *id = spi_get_device_id(spi);
spi->mode = SPI_MODE_3; spi->mode = SPI_MODE_3;
...@@ -68,8 +69,12 @@ static int hmc5843_spi_probe(struct spi_device *spi) ...@@ -68,8 +69,12 @@ static int hmc5843_spi_probe(struct spi_device *spi)
if (ret) if (ret)
return ret; return ret;
regmap = devm_regmap_init_spi(spi, &hmc5843_spi_regmap_config);
if (IS_ERR(regmap))
return PTR_ERR(regmap);
return hmc5843_common_probe(&spi->dev, return hmc5843_common_probe(&spi->dev,
devm_regmap_init_spi(spi, &hmc5843_spi_regmap_config), regmap,
id->driver_data, id->name); id->driver_data, id->name);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment