Skip to content

Commit

Permalink
iio: hmc5843: fix potential NULL pointer dereferences
Browse files Browse the repository at this point in the history
[ Upstream commit 536cc27 ]

devm_regmap_init_i2c may fail and return NULL. The fix returns
the error when it fails.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
kengiter authored and gregkh committed May 31, 2019
1 parent d7c7734 commit dd106d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion drivers/iio/magnetometer/hmc5843_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ static const struct regmap_config hmc5843_i2c_regmap_config = {
static int hmc5843_i2c_probe(struct i2c_client *cli,
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,
devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config),
regmap,
id->driver_data, id->name);
}

Expand Down
7 changes: 6 additions & 1 deletion drivers/iio/magnetometer/hmc5843_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ static const struct regmap_config hmc5843_spi_regmap_config = {
static int hmc5843_spi_probe(struct spi_device *spi)
{
int ret;
struct regmap *regmap;
const struct spi_device_id *id = spi_get_device_id(spi);

spi->mode = SPI_MODE_3;
Expand All @@ -67,8 +68,12 @@ static int hmc5843_spi_probe(struct spi_device *spi)
if (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,
devm_regmap_init_spi(spi, &hmc5843_spi_regmap_config),
regmap,
id->driver_data, id->name);
}

Expand Down

0 comments on commit dd106d1

Please sign in to comment.