From: Meiyou Chen Date: Fri, 11 Sep 2015 02:30:54 +0000 (+0800) Subject: of/device: Fix platform_device.name point to an freed memory after X-Git-Tag: firefly_0821_release~3792 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=firefly-linux-kernel-4.4.55.git;a=commitdiff_plain;h=a51927d3ac36b6f5ec741040d7b694e73f0fbeaf of/device: Fix platform_device.name point to an freed memory after dev_set_name() When we use of_device_add() to create platform_device and add it to device hierarchy, the platform_device.name and device's name will point to the same memory. Later we use dev_set_name() to change the device's name, it will alloc new memory to store name and free old device's name. After it, the platform_device.name will point to an freed memory, access platform_device.name maybe lead to unpredictable exceptions. So, we alloc new memory for platform_device.name in of_device_add() Change-Id: I59bf0941ee4e094053971d41d386206e47fddcaa Signed-off-by: Meiyou Chen --- diff --git a/drivers/of/device.c b/drivers/of/device.c index 4f942b56fab9..3f447474414e 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -54,7 +54,11 @@ int of_device_add(struct platform_device *ofdev) /* name and id have to be set so that the platform bus doesn't get * confused on matching */ +#ifdef CONFIG_ARCH_ROCKCHIP + ofdev->name = kasprintf(GFP_KERNEL, "%s", dev_name(&ofdev->dev)); +#else ofdev->name = dev_name(&ofdev->dev); +#endif ofdev->id = -1; /* device_add will assume that this device is on the same node as