diff options
author | Anton Vorontsov <cbouatmailru@gmail.com> | 2010-09-07 17:31:49 +0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-10-22 10:16:43 -0700 |
commit | 5cfc64ceb6222aabec640ba76e89529a8fc2c1f0 (patch) | |
tree | cb49e651fbb5ec4192ef650fd5b63c1dba0040f1 /drivers/base | |
parent | 87544653abe4a03324bc85dae32d5bdaabcfccef (diff) | |
download | linux-3.10-5cfc64ceb6222aabec640ba76e89529a8fc2c1f0.tar.gz linux-3.10-5cfc64ceb6222aabec640ba76e89529a8fc2c1f0.tar.bz2 linux-3.10-5cfc64ceb6222aabec640ba76e89529a8fc2c1f0.zip |
base/platform: Safe handling for NULL platform data and resources
Some users of platform_device_add_{data,resources}() assume that
NULL data and resources will be handled specially, i.e. just ignored.
But the platform core ends up calling kmemdup(NULL, 0, ...), which
returns a non-NULL result (i.e. ZERO_SIZE_PTR), which causes drivers
to oops on a valid code, something like:
if (platform_data)
stuff = platform_data->stuff;
This patch makes the platform core a bit more safe for such cases.
Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/platform.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/drivers/base/platform.c b/drivers/base/platform.c index a01abf9ebf7..c794fec1c43 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -192,6 +192,9 @@ int platform_device_add_resources(struct platform_device *pdev, { struct resource *r; + if (!res) + return 0; + r = kmemdup(res, sizeof(struct resource) * num, GFP_KERNEL); if (r) { pdev->resource = r; @@ -215,8 +218,12 @@ EXPORT_SYMBOL_GPL(platform_device_add_resources); int platform_device_add_data(struct platform_device *pdev, const void *data, size_t size) { - void *d = kmemdup(data, size, GFP_KERNEL); + void *d; + + if (!data) + return 0; + d = kmemdup(data, size, GFP_KERNEL); if (d) { pdev->dev.platform_data = d; return 0; |