Skip to content

Commit 5cfc64c

Browse files
enomsggregkh
authored andcommitted
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 <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8754465 commit 5cfc64c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/base/platform.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ int platform_device_add_resources(struct platform_device *pdev,
192192
{
193193
struct resource *r;
194194

195+
if (!res)
196+
return 0;
197+
195198
r = kmemdup(res, sizeof(struct resource) * num, GFP_KERNEL);
196199
if (r) {
197200
pdev->resource = r;
@@ -215,8 +218,12 @@ EXPORT_SYMBOL_GPL(platform_device_add_resources);
215218
int platform_device_add_data(struct platform_device *pdev, const void *data,
216219
size_t size)
217220
{
218-
void *d = kmemdup(data, size, GFP_KERNEL);
221+
void *d;
222+
223+
if (!data)
224+
return 0;
219225

226+
d = kmemdup(data, size, GFP_KERNEL);
220227
if (d) {
221228
pdev->dev.platform_data = d;
222229
return 0;

0 commit comments

Comments
 (0)