msm: clock: Enhance sanity checks

If someone passes in an ERR_PTR to clk_enable, the API
will still try to dereference the pointer, leading
to a data abort. Enhance error checking in this and
other clock APIs.

Change-Id: Ibf04c4d7b18c697627c55d47cba41cd4e940c9a9
Signed-off-by: Vikram Mulukutla <markivx@codeaurora.org>
diff --git a/arch/arm/mach-msm/clock.c b/arch/arm/mach-msm/clock.c
index 09bf036..fb5b580 100644
--- a/arch/arm/mach-msm/clock.c
+++ b/arch/arm/mach-msm/clock.c
@@ -132,8 +132,11 @@
 {
 	int ret = 0;
 	struct clk *parent;
+
 	if (!clk)
 		return 0;
+	if (IS_ERR(clk))
+		return -EINVAL;
 
 	mutex_lock(&clk->prepare_lock);
 	if (clk->prepare_count == 0) {
@@ -174,6 +177,8 @@
 
 	if (!clk)
 		return 0;
+	if (IS_ERR(clk))
+		return -EINVAL;
 
 	spin_lock_irqsave(&clk->lock, flags);
 	if (WARN(!clk->warned && !clk->prepare_count,
@@ -230,7 +235,7 @@
 {
 	unsigned long flags;
 
-	if (!clk)
+	if (IS_ERR_OR_NULL(clk))
 		return;
 
 	spin_lock_irqsave(&clk->lock, flags);
@@ -259,7 +264,7 @@
 
 void clk_unprepare(struct clk *clk)
 {
-	if (!clk)
+	if (IS_ERR_OR_NULL(clk))
 		return;
 
 	mutex_lock(&clk->prepare_lock);
@@ -290,6 +295,9 @@
 
 int clk_reset(struct clk *clk, enum clk_reset_action action)
 {
+	if (IS_ERR_OR_NULL(clk))
+		return -EINVAL;
+
 	if (!clk->ops->reset)
 		return -ENOSYS;
 
@@ -299,6 +307,9 @@
 
 unsigned long clk_get_rate(struct clk *clk)
 {
+	if (IS_ERR_OR_NULL(clk))
+		return 0;
+
 	if (!clk->ops->get_rate)
 		return clk->rate;
 
@@ -311,6 +322,9 @@
 	unsigned long start_rate, flags;
 	int rc;
 
+	if (IS_ERR_OR_NULL(clk))
+		return -EINVAL;
+
 	if (!clk->ops->set_rate)
 		return -ENOSYS;
 
@@ -347,6 +361,9 @@
 
 long clk_round_rate(struct clk *clk, unsigned long rate)
 {
+	if (IS_ERR_OR_NULL(clk))
+		return -EINVAL;
+
 	if (!clk->ops->round_rate)
 		return -ENOSYS;
 
@@ -356,6 +373,9 @@
 
 int clk_set_max_rate(struct clk *clk, unsigned long rate)
 {
+	if (IS_ERR_OR_NULL(clk))
+		return -EINVAL;
+
 	if (!clk->ops->set_max_rate)
 		return -ENOSYS;
 
@@ -374,6 +394,9 @@
 
 struct clk *clk_get_parent(struct clk *clk)
 {
+	if (IS_ERR_OR_NULL(clk))
+		return NULL;
+
 	if (!clk->ops->get_parent)
 		return NULL;
 
@@ -383,7 +406,7 @@
 
 int clk_set_flags(struct clk *clk, unsigned long flags)
 {
-	if (clk == NULL || IS_ERR(clk))
+	if (IS_ERR_OR_NULL(clk))
 		return -EINVAL;
 	if (!clk->ops->set_flags)
 		return -ENOSYS;