power: supply: charger-manager: Fix a NULL pointer dereference in 'charger_manager_pr...
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sun, 6 Aug 2017 22:37:55 +0000 (00:37 +0200)
committerSebastian Reichel <sebastian.reichel@collabora.co.uk>
Fri, 11 Aug 2017 16:53:18 +0000 (18:53 +0200)
'devm_kzalloc()' can return NULL. Return -ENOMEM in this case in order to
avoid a NULL pointer dereference later on.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
drivers/power/supply/charger-manager.c

index adc3761831e1b433b2f68617892595f06107cea9..52a49857e20fcd33a65bbc9d01eaf4186c27090a 100644 (file)
@@ -1645,6 +1645,8 @@ static int charger_manager_probe(struct platform_device *pdev)
        /* Initialize alarm timer */
        if (alarmtimer_get_rtcdev()) {
                cm_timer = devm_kzalloc(cm->dev, sizeof(*cm_timer), GFP_KERNEL);
+               if (!cm_timer)
+                       return -ENOMEM;
                alarm_init(cm_timer, ALARM_BOOTTIME, cm_timer_func);
        }