Skip to content

Commit

Permalink
gpio: max732x: Fix possible NULL pointer dereference on i2c_new_dummy…
Browse files Browse the repository at this point in the history
… error

In max732x_probe() driver allocates dummy I2C device (if number of ports
is greater than 8) with i2c_new_dummy() but it does not check the return
value of this call.

In case of error (i2c_new_device(): memory allocation failure or I2C
address cannot be used) this function returns NULL which is later
dereferenced by i2c_smbus_read_byte() (called from max732x_readb()).

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Krzysztof Kozlowski authored and Linus Walleij committed Mar 12, 2014
1 parent c75793d commit f561b42
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions drivers/gpio/gpio-max732x.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,13 @@ static int max732x_probe(struct i2c_client *client,
goto out_failed;
}

if (nr_port > 8 && !chip->client_dummy) {
dev_err(&client->dev,
"Failed to allocate second group I2C device\n");
ret = -ENODEV;
goto out_failed;
}

mutex_init(&chip->lock);

max732x_readb(chip, is_group_a(chip, 0), &chip->reg_out[0]);
Expand Down

0 comments on commit f561b42

Please sign in to comment.