compal-laptop: Check return value of power_supply_register
authorKrzysztof Kozlowski <k.kozlowski@samsung.com>
Thu, 12 Mar 2015 07:44:00 +0000 (08:44 +0100)
committerSasha Levin <sasha.levin@oracle.com>
Sun, 17 May 2015 23:11:55 +0000 (19:11 -0400)
commitebc00a2053b4b92a32deaf7a0221bf510abbe50e
tree9835a8ebe1e7c68d27f3ff75183d2d1e624f23c4
parent29037bcf2d8bf828d253a2e31339c3c04a172a9c
compal-laptop: Check return value of power_supply_register

[ Upstream commit 1915a718b1872edffcb13e5436a9f7302d3d36f0 ]

The return value of power_supply_register() call was not checked and
even on error probe() function returned 0. If registering failed then
during unbind the driver tried to unregister power supply which was not
actually registered.

This could lead to memory corruption because power_supply_unregister()
unconditionally cleans up given power supply.

Fix this by checking return status of power_supply_register() call. In
case of failure, clean up sysfs entries and fail the probe.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Fixes: 9be0fcb5ed46 ("compal-laptop: add JHL90, battery & hwmon interface")
Cc: <stable@vger.kernel.org>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
drivers/platform/x86/compal-laptop.c