Skip to content

Commit daa4122

Browse files
akpm00gregkh
authored andcommitted
driver core: platform_device_add_data(): use kmemdup()
Instead of open-coding it. Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 4622709 commit daa4122

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎drivers/base/platform.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* information.
1111
*/
1212

13+
#include <linux/string.h>
1314
#include <linux/platform_device.h>
1415
#include <linux/module.h>
1516
#include <linux/init.h>
@@ -213,14 +214,13 @@ EXPORT_SYMBOL_GPL(platform_device_add_resources);
213214
int platform_device_add_data(struct platform_device *pdev, const void *data,
214215
size_t size)
215216
{
216-
void *d;
217+
void *d = kmemdup(data, size, GFP_KERNEL);
217218

218-
d = kmalloc(size, GFP_KERNEL);
219219
if (d) {
220-
memcpy(d, data, size);
221220
pdev->dev.platform_data = d;
221+
return 0;
222222
}
223-
return d ? 0 : -ENOMEM;
223+
return -ENOMEM;
224224
}
225225
EXPORT_SYMBOL_GPL(platform_device_add_data);
226226

0 commit comments

Comments
 (0)