]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iio: hmc5843: fix potential NULL pointer dereferences
authorKangjie Lu <kjlu@umn.edu>
Sat, 16 Mar 2019 22:08:33 +0000 (17:08 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 11 Jun 2019 10:24:02 +0000 (12:24 +0200)
[ Upstream commit 536cc27deade8f1ec3c1beefa60d5fbe0f6fcb28 ]

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>
drivers/staging/iio/magnetometer/hmc5843_i2c.c
drivers/staging/iio/magnetometer/hmc5843_spi.c

index 3e06ceb32059663d1f62ce0daa209108c228d942..676a8e329eeb61074f992fa7ada19c395a6a31b6 100644 (file)
@@ -59,8 +59,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);
 }
 
index 8be198058ea20452cd3623d6e3564c58537b8d15..fded442a3c1d1e099f0b59bdf5c98ffbebce006e 100644 (file)
@@ -59,6 +59,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;
@@ -68,8 +69,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);
 }