public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: fractional-divider: prevent division by zero
@ 2015-01-16 12:37 Heikki Krogerus
  2015-01-16 22:29 ` Stephen Boyd
  0 siblings, 1 reply; 3+ messages in thread
From: Heikki Krogerus @ 2015-01-16 12:37 UTC (permalink / raw)
  To: Mike Turquette, Stephen Boyd
  Cc: Mika Westerberg, Andy Shevchenko, linux-kernel

Preventing division by zero condition by making sure that
the initial n and m values are not 0.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
 drivers/clk/clk-fractional-divider.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c
index 82a59d0..dc91da7 100644
--- a/drivers/clk/clk-fractional-divider.c
+++ b/drivers/clk/clk-fractional-divider.c
@@ -104,6 +104,7 @@ struct clk *clk_register_fractional_divider(struct device *dev,
 	struct clk_fractional_divider *fd;
 	struct clk_init_data init;
 	struct clk *clk;
+	u32 val;
 
 	fd = kzalloc(sizeof(*fd), GFP_KERNEL);
 	if (!fd) {
@@ -126,6 +127,14 @@ struct clk *clk_register_fractional_divider(struct device *dev,
 	fd->lock = lock;
 	fd->hw.init = &init;
 
+	/* Prevent division by zero */
+	val = clk_readl(fd->reg);
+	if (!(val & fd->nmask))
+		val |= 1 << fd->nshift;
+	if (!(val & fd->mmask))
+		val |= 1 << fd->mshift;
+	clk_writel(val, fd->reg);
+
 	clk = clk_register(dev, &fd->hw);
 	if (IS_ERR(clk))
 		kfree(fd);
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-01-19 11:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-16 12:37 [PATCH] clk: fractional-divider: prevent division by zero Heikki Krogerus
2015-01-16 22:29 ` Stephen Boyd
2015-01-19 11:56   ` Heikki Krogerus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox