Use platform_device_put() instead of platform_device_unregister() if
platform_device_add() fails, and also add the return value check of
platform_device_add_data().
Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
Cc: Evgeniy Polyakov <zbr@ioremap.net>
Cc: Greg KH <greg@kroah.com>
Cc: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
        ret = platform_device_add_data(pdev,
                                       &bq27000_battery_info,
                                       sizeof(bq27000_battery_info));
+       if (ret)
+               goto pdev_add_failed;
        pdev->dev.parent = &sl->dev;
 
        ret = platform_device_add(pdev);
        goto success;
 
 pdev_add_failed:
-       platform_device_unregister(pdev);
+       platform_device_put(pdev);
 success:
        return ret;
 }