git diff diff --git a/tools/lib/thermal/commands.c b/tools/lib/thermal/commands.c index 539083780107..b8d933f19909 100644 --- a/tools/lib/thermal/commands.c +++ b/tools/lib/thermal/commands.c @@ -117,6 +117,8 @@ static int parse_tz_get_trip(struct genl_info *info, struct thermal_zone *tz) size_t size = 0; int rem; + tz->trip_count = 0; + nla_for_each_nested(attr, info->attrs[THERMAL_GENL_ATTR_TZ_TRIP], rem) { if (nla_type(attr) == THERMAL_GENL_ATTR_TZ_TRIP_ID) { @@ -140,10 +142,15 @@ static int parse_tz_get_trip(struct genl_info *info, struct thermal_zone *tz) __tt[size - 1].hyst = nla_get_u32(attr); } + if (!size) + return THERMAL_ERROR; + __tt[size].id = -1; tz->trip = __tt; + tz->trip_count = size; + return THERMAL_SUCCESS; } diff --git a/tools/lib/thermal/include/thermal.h b/tools/lib/thermal/include/thermal.h index 1abc560602cf..5cb9ba8c6c0e 100644 --- a/tools/lib/thermal/include/thermal.h +++ b/tools/lib/thermal/include/thermal.h @@ -51,6 +51,7 @@ struct thermal_zone { char name[THERMAL_NAME_LENGTH]; char governor[THERMAL_NAME_LENGTH]; struct thermal_trip *trip; + int trip_count; }; struct thermal_cdev { diff --git a/tools/lib/thermal/thermal.c b/tools/lib/thermal/thermal.c index a80b967ce334..dd4ebfbbf1d0 100644 --- a/tools/lib/thermal/thermal.c +++ b/tools/lib/thermal/thermal.c @@ -19,7 +19,10 @@ int for_each_thermal_trip(struct thermal_trip *tt, cb_tt_t cb, void *arg) { int i, ret = 0; - for (i = 0; tt[i].id != -1; i++) + if (!tt) + return -1; + + for (i = 0; &tt[i] && tt[i].id != -1; i++) ret |= cb(&tt[i], arg); return ret; @@ -29,6 +32,9 @@ int for_each_thermal_zone(struct thermal_zone *tz, cb_tz_t cb, void *arg) { int i, ret = 0; + if (!tz) + return 0; + for (i = 0; tz[i].id != -1; i++) ret |= cb(&tz[i], arg); diff --git a/tools/thermal/thermal-engine/thermal-engine.c b/tools/thermal/thermal-engine/thermal-engine.c index 525520049aa2..4e446aec22b5 100644 --- a/tools/thermal/thermal-engine/thermal-engine.c +++ b/tools/thermal/thermal-engine/thermal-engine.c @@ -68,7 +68,8 @@ static int show_tz(struct thermal_zone *tz, __maybe_unused void *arg) { INFO("thermal zone '%s', id=%d\n", tz->name, tz->id); - for_each_thermal_trip(tz->trip, show_trip, NULL); + if (tz->trip_count) + for_each_thermal_trip(tz->trip, show_trip, NULL); show_temp(tz, arg);