Commit 45efe847971e6274a04eea75a0745d8015b54d37
Committed by
Grant Likely
1 parent
9ed030d728
Exists in
master
and in
7 other branches
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>
Showing 1 changed file with 10 additions and 0 deletions Side-by-side Diff
drivers/misc/eeprom/at24.c
... | ... | @@ -517,6 +517,11 @@ |
517 | 517 | if (!is_power_of_2(chip.byte_len)) |
518 | 518 | dev_warn(&client->dev, |
519 | 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 | 525 | if (!is_power_of_2(chip.page_size)) |
521 | 526 | dev_warn(&client->dev, |
522 | 527 | "page_size looks suspicious (no power of 2)!\n"); |
... | ... | @@ -681,6 +686,11 @@ |
681 | 686 | |
682 | 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 | 694 | io_limit = rounddown_pow_of_two(io_limit); |
685 | 695 | return i2c_add_driver(&at24_driver); |
686 | 696 | } |