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>
This commit is contained in:
parent
d98ae31eee
commit
7a2c9513a1
1 changed files with 8 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue