aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan O'Donoghue <pure.logic@nexus-software.ie>2017-07-28 09:22:57 -0400
committerBoris Brezillon <boris.brezillon@free-electrons.com>2017-08-02 04:26:40 -0400
commit791eccd94965a8029ae09c5530bcb9a76794e408 (patch)
tree0e2d8503a9d657df9a5fed39946d07dde81e1556
parentf7f8c1756e9a5f1258a7cc6b663f8451b724900f (diff)
mtd: nand: sunxi: fix potential divide-by-zero error
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: 2d43457f79e4 ("mtd: nand: sunxi: fix EDO mode selection") Signed-off-by: Bryan O'Donoghue <pure.logic@nexus-software.ie> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
-rw-r--r--drivers/mtd/nand/sunxi_nand.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c
index d0b6f8f9f297..6abd142b1324 100644
--- a/drivers/mtd/nand/sunxi_nand.c
+++ b/drivers/mtd/nand/sunxi_nand.c
@@ -1728,6 +1728,10 @@ static int sunxi_nfc_setup_data_interface(struct mtd_info *mtd, int csline,
1728 */ 1728 */
1729 chip->clk_rate = NSEC_PER_SEC / min_clk_period; 1729 chip->clk_rate = NSEC_PER_SEC / min_clk_period;
1730 real_clk_rate = clk_round_rate(nfc->mod_clk, chip->clk_rate); 1730 real_clk_rate = clk_round_rate(nfc->mod_clk, chip->clk_rate);
1731 if (real_clk_rate <= 0) {
1732 dev_err(nfc->dev, "Unable to round clk %lu\n", chip->clk_rate);
1733 return -EINVAL;
1734 }
1731 1735
1732 /* 1736 /*
1733 * ONFI specification 3.1, paragraph 4.15.2 dictates that EDO data 1737 * ONFI specification 3.1, paragraph 4.15.2 dictates that EDO data