summaryrefslogtreecommitdiff
path: root/drivers/base
diff options
context:
space:
mode:
authorAdrian Salido <salidoa@google.com>2017-04-25 16:55:26 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-07-15 11:57:44 +0200
commitc01ace719ebe6353f0c96e56f6c75c22ad3f67b0 (patch)
tree8d7f40c3063789322736e237b929920c735d2573 /drivers/base
parent4043d5bca587eab2dfcca5e2da7e770d16b127c8 (diff)
driver core: platform: fix race condition with driver_override
commit 6265539776a0810b7ce6398c27866ddb9c6bd154 upstream. The driver_override implementation is susceptible to race condition when different threads are reading vs storing a different driver override. Add locking to avoid race condition. Fixes: 3d713e0e382e ("driver core: platform: add device binding path 'driver_override'") Cc: stable@vger.kernel.org Signed-off-by: Adrian Salido <salidoa@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/platform.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index ba66330cea67..cb4ad6e98b28 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -807,7 +807,7 @@ static ssize_t driver_override_store(struct device *dev,
const char *buf, size_t count)
{
struct platform_device *pdev = to_platform_device(dev);
- char *driver_override, *old = pdev->driver_override, *cp;
+ char *driver_override, *old, *cp;
if (count > PATH_MAX)
return -EINVAL;
@@ -820,12 +820,15 @@ static ssize_t driver_override_store(struct device *dev,
if (cp)
*cp = '\0';
+ device_lock(dev);
+ old = pdev->driver_override;
if (strlen(driver_override)) {
pdev->driver_override = driver_override;
} else {
kfree(driver_override);
pdev->driver_override = NULL;
}
+ device_unlock(dev);
kfree(old);
@@ -836,8 +839,12 @@ static ssize_t driver_override_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct platform_device *pdev = to_platform_device(dev);
+ ssize_t len;
- return sprintf(buf, "%s\n", pdev->driver_override);
+ device_lock(dev);
+ len = sprintf(buf, "%s\n", pdev->driver_override);
+ device_unlock(dev);
+ return len;
}
static DEVICE_ATTR_RW(driver_override);