diff options
author | Sujit Reddy Thumma <sthumma@codeaurora.org> | 2012-12-12 09:16:58 +0530 |
---|---|---|
committer | Subhash Jadavani <subhashj@codeaurora.org> | 2016-05-31 15:25:40 -0700 |
commit | 7a2c9513a1690947f568453f6977a96b62c8c2e6 (patch) | |
tree | f6ab039864c62bdad3305684158ad42e17d63f3f /drivers | |
parent | d98ae31eeefcaf2d0b7ef419f2a9d5028afb0ade (diff) |
mmc: core: claim mmc host while enabling clock scaling from userspace
A race condition can occur while enabling clock scaling and removal
of the card. If the card is removed just after the host->card check
is successful then there could be NULL pointer dereference later.
Claim mmc host before card availability check to avoid this race
condition.
Change-Id: I6339cad5857732ec6b66280940cd6b8b7ed30614
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mmc/core/host.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c index 72eda77a6f3b..b3363212c92e 100644 --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c @@ -633,7 +633,11 @@ static ssize_t store_enable(struct device *dev, unsigned long value, freq; int retval = -EINVAL; - if (!host || !host->card || kstrtoul(buf, 0, &value)) + if (!host) + goto out; + + mmc_claim_host(host); + if (!host->card || kstrtoul(buf, 0, &value)) goto err; if (value && !mmc_can_scale_clk(host)) { @@ -659,8 +663,10 @@ static ssize_t store_enable(struct device *dev, } host->clk_scaling.initialized = false; } - return count; + retval = count; err: + mmc_release_host(host); +out: return retval; } |