drivers/thermal/thermal_helpers.c:123 thermal_zone_get_temp() error: testing array offset 'tz->id' after use.
PATCH 65/71 drivers/thermal/thermal_helpers.c:123 thermal_zone_get_temp() error: testing array offset 'tz->id' after use.
tree: https://github.com/tobetter/linux odroid-5.9.y head: 2189c37332c364084ef11d5aaeb2d79860f60715 commit: ef568bba078a984f85e4ae4d909793c7403415c6 [65/71] ODROID-XU4: Update hack avoiding the invalid temperature by TMU broken config: i386-randconfig-m021-20201008 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>
Reported-by Dan Carpenter <[email protected]>
smatch warnings:drivers/thermal/thermal_helpers.c:123 thermal_zone_get_temp() error: testing array offset 'tz->id' after use.
vim +123 drivers/thermal/thermal_helpers.c
cd221c7b638f831 Eduardo Valentin 2016-11-07 82 int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
cd221c7b638f831 Eduardo Valentin 2016-11-07 83 {
cd221c7b638f831 Eduardo Valentin 2016-11-07 84 int ret = -EINVAL;
cd221c7b638f831 Eduardo Valentin 2016-11-07 85 int count;
cd221c7b638f831 Eduardo Valentin 2016-11-07 86 int crit_temp = INT_MAX;
cd221c7b638f831 Eduardo Valentin 2016-11-07 87 enum thermal_trip_type type;
cd221c7b638f831 Eduardo Valentin 2016-11-07 88
cd221c7b638f831 Eduardo Valentin 2016-11-07 89 if (!tz || IS_ERR(tz) || !tz->ops->get_temp)
cd221c7b638f831 Eduardo Valentin 2016-11-07 90 goto exit;
cd221c7b638f831 Eduardo Valentin 2016-11-07 91
cd221c7b638f831 Eduardo Valentin 2016-11-07 92 mutex_lock(&tz->lock);
cd221c7b638f831 Eduardo Valentin 2016-11-07 93
cd221c7b638f831 Eduardo Valentin 2016-11-07 94 ret = tz->ops->get_temp(tz, temp);
cd221c7b638f831 Eduardo Valentin 2016-11-07 95
cd221c7b638f831 Eduardo Valentin 2016-11-07 96 if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz->emul_temperature) {
cd221c7b638f831 Eduardo Valentin 2016-11-07 97 for (count = 0; count < tz->trips; count++) {
cd221c7b638f831 Eduardo Valentin 2016-11-07 98 ret = tz->ops->get_trip_type(tz, count, &type);
cd221c7b638f831 Eduardo Valentin 2016-11-07 99 if (!ret && type == THERMAL_TRIP_CRITICAL) {
cd221c7b638f831 Eduardo Valentin 2016-11-07 100 ret = tz->ops->get_trip_temp(tz, count,
cd221c7b638f831 Eduardo Valentin 2016-11-07 101 &crit_temp);
cd221c7b638f831 Eduardo Valentin 2016-11-07 102 break;
cd221c7b638f831 Eduardo Valentin 2016-11-07 103 }
cd221c7b638f831 Eduardo Valentin 2016-11-07 104 }
cd221c7b638f831 Eduardo Valentin 2016-11-07 105
cd221c7b638f831 Eduardo Valentin 2016-11-07 106 /*
cd221c7b638f831 Eduardo Valentin 2016-11-07 107 * Only allow emulating a temperature when the real temperature
cd221c7b638f831 Eduardo Valentin 2016-11-07 108 * is below the critical temperature so that the emulation code
cd221c7b638f831 Eduardo Valentin 2016-11-07 109 * cannot hide critical conditions.
cd221c7b638f831 Eduardo Valentin 2016-11-07 110 */
cd221c7b638f831 Eduardo Valentin 2016-11-07 111 if (!ret && *temp < crit_temp)
cd221c7b638f831 Eduardo Valentin 2016-11-07 112 *temp = tz->emul_temperature;
cd221c7b638f831 Eduardo Valentin 2016-11-07 113 }
cd221c7b638f831 Eduardo Valentin 2016-11-07 114
ef568bba078a984 charles.park 2018-06-01 115 /* save thermal_zone data */
ef568bba078a984 charles.park 2018-06-01 116 if (!ret)
ef568bba078a984 charles.park 2018-06-01 117 thermal_zone_data[tz->id] = *temp;
ef568bba078a984 charles.park 2018-06-01 118 /*
ef568bba078a984 charles.park 2018-06-01 119 * This case is that the thermal sensor is broken.
ef568bba078a984 charles.park 2018-06-01 120 * That's not real temperature. Set the fake temperature value in order to
ef568bba078a984 charles.park 2018-06-01 121 * avoid reaching the ciritical temperature.
ef568bba078a984 charles.park 2018-06-01 122 */
ef568bba078a984 charles.park 2018-06-01 @123 if ((thermal_zone_data[tz->id] > CRITICAL_TEMP) && (tz->id != 4)) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^If "tz->id == 4" then the "thermal_zone_data[tz->id] > CRITICAL_TEMP" check is reading out of bounds.
ef568bba078a984 charles.park 2018-06-01 124 int i, broken_sensor = 0, correct_temp = 0;
ef568bba078a984 charles.park 2018-06-01 125 for (i = 0; i < 4; i++) {
ef568bba078a984 charles.park 2018-06-01 126 if ((thermal_zone_data[i] <= CRITICAL_TEMP) &&
ef568bba078a984 charles.park 2018-06-01 127 (correct_temp <= thermal_zone_data[i]))
ef568bba078a984 charles.park 2018-06-01 128 correct_temp = thermal_zone_data[i];
ef568bba078a984 charles.park 2018-06-01 129 if (thermal_zone_data[i] > CRITICAL_TEMP)
ef568bba078a984 charles.park 2018-06-01 130 broken_sensor++;
ef568bba078a984 charles.park 2018-06-01 131 }
ef568bba078a984 charles.park 2018-06-01 132 /*
ef568bba078a984 charles.park 2018-06-01 133 * if all thermal sensor broken then critical temperature data send
ef568bba078a984 charles.park 2018-06-01 134 * for system poweroff.
ef568bba078a984 charles.park 2018-06-01 135 */
ef568bba078a984 charles.park 2018-06-01 136 *temp = (broken_sensor == 4) ? CRITICAL_TEMP : correct_temp;
ef568bba078a984 charles.park 2018-06-01 137 }
ef568bba078a984 charles.park 2018-06-01 138
cd221c7b638f831 Eduardo Valentin 2016-11-07 139 mutex_unlock(&tz->lock);
cd221c7b638f831 Eduardo Valentin 2016-11-07 140 exit:
cd221c7b638f831 Eduardo Valentin 2016-11-07 141 return ret;
cd221c7b638f831 Eduardo Valentin 2016-11-07 142 }---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org