Skip to content

Commit ebc00a2

Browse files
krzksashalevin
authored andcommitted
compal-laptop: Check return value of power_supply_register
[ Upstream commit 1915a71 ] 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: 9be0fcb ("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>
1 parent 29037bc commit ebc00a2

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎drivers/platform/x86/compal-laptop.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,9 @@ static int compal_probe(struct platform_device *pdev)
10371037

10381038
/* Power supply */
10391039
initialize_power_supply_data(data);
1040-
power_supply_register(&compal_device->dev, &data->psy);
1040+
err = power_supply_register(&compal_device->dev, &data->psy);
1041+
if (err < 0)
1042+
goto remove;
10411043

10421044
platform_set_drvdata(pdev, data);
10431045

0 commit comments

Comments
 (0)