diff options
author | Wolfram Sang <w.sang@pengutronix.de> | 2010-11-17 07:00:49 -0500 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2010-12-24 04:14:17 -0500 |
commit | 45efe847971e6274a04eea75a0745d8015b54d37 (patch) | |
tree | 62d4ee35aed2c4d36ac0099cd66caedbf9dd42d5 /drivers/misc | |
parent | 9ed030d728f3bd03b6e869357da02725afda19a7 (diff) |
misc/at24: add more sanity checks for parameters
Side-effects happen when passing 0 to either io_limit or page_size. Give
an error in case of this misconfiguration.
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/misc')
-rw-r--r-- | drivers/misc/eeprom/at24.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 3a53efc28821..ab1ad41786d1 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c | |||
@@ -517,6 +517,11 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
517 | if (!is_power_of_2(chip.byte_len)) | 517 | if (!is_power_of_2(chip.byte_len)) |
518 | dev_warn(&client->dev, | 518 | dev_warn(&client->dev, |
519 | "byte_len looks suspicious (no power of 2)!\n"); | 519 | "byte_len looks suspicious (no power of 2)!\n"); |
520 | if (!chip.page_size) { | ||
521 | dev_err(&client->dev, "page_size must not be 0!\n"); | ||
522 | err = -EINVAL; | ||
523 | goto err_out; | ||
524 | } | ||
520 | if (!is_power_of_2(chip.page_size)) | 525 | if (!is_power_of_2(chip.page_size)) |
521 | dev_warn(&client->dev, | 526 | dev_warn(&client->dev, |
522 | "page_size looks suspicious (no power of 2)!\n"); | 527 | "page_size looks suspicious (no power of 2)!\n"); |
@@ -681,6 +686,11 @@ static struct i2c_driver at24_driver = { | |||
681 | 686 | ||
682 | static int __init at24_init(void) | 687 | static int __init at24_init(void) |
683 | { | 688 | { |
689 | if (!io_limit) { | ||
690 | pr_err("at24: io_limit must not be 0!\n"); | ||
691 | return -EINVAL; | ||
692 | } | ||
693 | |||
684 | io_limit = rounddown_pow_of_two(io_limit); | 694 | io_limit = rounddown_pow_of_two(io_limit); |
685 | return i2c_add_driver(&at24_driver); | 695 | return i2c_add_driver(&at24_driver); |
686 | } | 696 | } |