linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: fengguang.wu@intel.com (Fengguang Wu)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] clk: validate pointer in __clk_disable()
Date: Thu, 7 Jun 2012 13:52:59 +0900	[thread overview]
Message-ID: <20120607045259.GA16232@localhost> (raw)
In-Reply-To: <20120606235438.GB20538@n2100.arm.linux.org.uk>

clk_get() returns -ENOENT on error and some careless caller might
dereference it without error checking:

In mxc_rnga_remove():

        struct clk *clk = clk_get(&pdev->dev, "rng");

	// ...

        clk_disable(clk);

Since it's insane to audit the lots of existing and future clk users,
let's add a check in the callee to avoid kernel panic and warn about
any buggy user.
---
 drivers/clk/clk.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 687b00d..7bd795bf9 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -464,6 +464,9 @@ static void __clk_disable(struct clk *clk)
 	if (!clk)
 		return;
 
+	if (WARN_ON(IS_ERR(clk)))
+		return;
+
 	if (WARN_ON(clk->enable_count == 0))
 		return;
 
-- 
1.7.10

  reply	other threads:[~2012-06-07  4:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20120606214621.GA8892@localhost>
     [not found] ` <20120606145113.f0c8ddcf.akpm@linux-foundation.org>
     [not found]   ` <20120606215951.GA9123@localhost>
     [not found]     ` <20120606150619.8567afb4.akpm@linux-foundation.org>
2012-06-06 22:42       ` Fwd: + clk-add-non-config_have_clk-routines.patch added to -mm tree Fengguang Wu
2012-06-06 22:49         ` Russell King - ARM Linux
2012-06-06 23:03           ` Fengguang Wu
2012-06-06 23:54             ` Russell King - ARM Linux
2012-06-07  4:52               ` Fengguang Wu [this message]
2012-06-08 22:37                 ` [PATCH] clk: validate pointer in __clk_disable() Andrew Morton
2012-06-06 22:47       ` Fwd: + clk-add-non-config_have_clk-routines.patch added to -mm tree Fengguang Wu

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=20120607045259.GA16232@localhost \
    --to=fengguang.wu@intel.com \
    --cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).