mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Mike Turquette <mturquette@linaro.org>,
	Stephen Boyd <sboyd@codeaurora.org>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] clk: fractional-divider: prevent division by zero
Date: Fri, 16 Jan 2015 14:37:50 +0200	[thread overview]
Message-ID: <1421411870-115195-1-git-send-email-heikki.krogerus@linux.intel.com> (raw)

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


             reply	other threads:[~2015-01-16 12:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-16 12:37 Heikki Krogerus [this message]
2015-01-16 22:29 ` Stephen Boyd
2015-01-19 11:56   ` Heikki Krogerus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1421411870-115195-1-git-send-email-heikki.krogerus@linux.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=mturquette@linaro.org \
    --cc=sboyd@codeaurora.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®