Merge branch 'driver-core-next' of git://git.kernel.org/pub/scm/linux/kernel/git...
[firefly-linux-kernel-4.4.55.git] / drivers / base / platform.c
index 48425f1830299de51e4e549c834a4d5cb470138c..1c291af637b3582e1419e665ee81e07ab6bdb019 100644 (file)
@@ -192,18 +192,18 @@ EXPORT_SYMBOL_GPL(platform_device_alloc);
 int platform_device_add_resources(struct platform_device *pdev,
                                  const struct resource *res, unsigned int num)
 {
-       struct resource *r;
+       struct resource *r = NULL;
 
-       if (!res)
-               return 0;
-
-       r = kmemdup(res, sizeof(struct resource) * num, GFP_KERNEL);
-       if (r) {
-               pdev->resource = r;
-               pdev->num_resources = num;
-               return 0;
+       if (res) {
+               r = kmemdup(res, sizeof(struct resource) * num, GFP_KERNEL);
+               if (!r)
+                       return -ENOMEM;
        }
-       return -ENOMEM;
+
+       kfree(pdev->resource);
+       pdev->resource = r;
+       pdev->num_resources = num;
+       return 0;
 }
 EXPORT_SYMBOL_GPL(platform_device_add_resources);
 
@@ -220,17 +220,17 @@ EXPORT_SYMBOL_GPL(platform_device_add_resources);
 int platform_device_add_data(struct platform_device *pdev, const void *data,
                             size_t size)
 {
-       void *d;
+       void *d = NULL;
 
-       if (!data)
-               return 0;
-
-       d = kmemdup(data, size, GFP_KERNEL);
-       if (d) {
-               pdev->dev.platform_data = d;
-               return 0;
+       if (data) {
+               d = kmemdup(data, size, GFP_KERNEL);
+               if (!d)
+                       return -ENOMEM;
        }
-       return -ENOMEM;
+
+       kfree(pdev->dev.platform_data);
+       pdev->dev.platform_data = d;
+       return 0;
 }
 EXPORT_SYMBOL_GPL(platform_device_add_data);