Skip to content

Commit

Permalink
mtd: nand: sunxi: fix potential divide-by-zero error
Browse files Browse the repository at this point in the history
clk_round_rate() can return <= 0. Currently the value returned by
clk_round_rate() is used directly for a division. This patch introduces a
guard to ensure a divide-by-zero or a divide by a negative number for that
matter can't happen by bugging out returning -EINVAL if clk_round_rate()
returns <= 0.

Fixes: 2d43457 ("mtd: nand: sunxi: fix EDO mode selection")
Signed-off-by: Bryan O'Donoghue <[email protected]>
Signed-off-by: Boris Brezillon <[email protected]>
  • Loading branch information
0xB0D authored and Boris Brezillon committed Aug 2, 2017
1 parent f7f8c17 commit 791eccd
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/mtd/nand/sunxi_nand.c
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,10 @@ static int sunxi_nfc_setup_data_interface(struct mtd_info *mtd, int csline,
*/
chip->clk_rate = NSEC_PER_SEC / min_clk_period;
real_clk_rate = clk_round_rate(nfc->mod_clk, chip->clk_rate);
if (real_clk_rate <= 0) {
dev_err(nfc->dev, "Unable to round clk %lu\n", chip->clk_rate);
return -EINVAL;
}

/*
* ONFI specification 3.1, paragraph 4.15.2 dictates that EDO data
Expand Down

0 comments on commit 791eccd

Please sign in to comment.