From 0d9f1a7c9818153b0729c562d41c40e9305788dd Mon Sep 17 00:00:00 2001 From: Ram Chandrasekar Date: Wed, 20 May 2020 13:26:01 -0700 Subject: [PATCH] thermal: core: Add appropriate error checks Add error checks in place to catch the errors returned by the API, instead of assuming success and proceeding. Change-Id: I8cd8b826f22a9406e934afaedc88e630695fb187 Signed-off-by: Ram Chandrasekar --- drivers/thermal/thermal_debugfs.c | 2 ++ drivers/thermal/thermal_sysfs.c | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/drivers/thermal/thermal_debugfs.c b/drivers/thermal/thermal_debugfs.c index cf4e4c94df47..30a040d7f489 100644 --- a/drivers/thermal/thermal_debugfs.c +++ b/drivers/thermal/thermal_debugfs.c @@ -150,6 +150,8 @@ static int parse_threshold(struct thermal_zone_device *tz, char *buf_ptr, int ret; trip_buf = strnstr(buf, "trip", count); + if (!trip_buf) + return -EINVAL; trip_buf_end = strnchr(trip_buf, buf_ptr + count - trip_buf, '\n'); if (!trip_buf_end) return -EINVAL; diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index 21736dc3af95..0efb21186a0b 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -70,6 +70,12 @@ config_show(struct device *dev, struct device_attribute *attr, char *buf) buf_temp = kzalloc(buf_size, GFP_KERNEL); buf_hyst = kzalloc(buf_size, GFP_KERNEL); buf_trip = kzalloc(buf_size, GFP_KERNEL); + if (!buf_trip || !buf_hyst || !buf_temp) { + kfree(buf_temp); + kfree(buf_hyst); + kfree(buf_trip); + return -ENOMEM; + } for (i = 0; i < tz->trips; i++) { buf_offset = scnprintf(buf_trip + buf_offset, buf_size - buf_offset, "%d ", i);