From 18919f504831fce5d19346204c42d26a495cd548 Mon Sep 17 00:00:00 2001 From: Ram Chandrasekar Date: Fri, 27 Mar 2020 11:42:39 -0700 Subject: [PATCH] drivers: of-thermal: Handle krealloc failure correctly Update the krealloc failure check to catch the failure in memory allocation. The existing check triggers a false positive and exits when the allocation has succeeded. Change-Id: If85762cce85139750b7d7385a03b0e0db2100733 Signed-off-by: Ram Chandrasekar --- drivers/thermal/of-thermal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c index 396d4aa68472..7995f433799f 100644 --- a/drivers/thermal/of-thermal.c +++ b/drivers/thermal/of-thermal.c @@ -829,7 +829,7 @@ thermal_zone_of_add_sensor(struct device_node *zone, tz_list_new = krealloc(sens_param->tz_list, sens_param->tz_cnt * sizeof(struct __thermal_zone *), GFP_KERNEL); - if (!tz_list_new[0]) + if (!tz_list_new) goto add_sensor_exit; sens_param->tz_list = tz_list_new; sens_param->tz_list[sens_param->tz_cnt - 1] = tz; @@ -961,7 +961,7 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, of_node_put(sensor_np); of_node_put(np); - if (!sens_param->tz_cnt) { + if (!sens_param->tz_cnt || !sens_param->tz_list) { devm_kfree(dev, sens_param); return ERR_PTR(-ENODEV); }