Skip to content

Commit fb4d83f

Browse files
peter50216zhang-rui
authored andcommitted
thermal: mtk: Allocate enough space for mtk_thermal.
The mtk_thermal struct contains a 'struct mtk_thermal_bank banks[];', but the allocation only allocates sizeof(struct mtk_thermal) bytes, which cause out of bound access with the ->banks[] member. Change it to a fixed size array instead. Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org> Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
1 parent e0fda73 commit fb4d83f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/thermal/mtk_thermal.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ enum {
199199
#define MT7622_TS1 0
200200
#define MT7622_NUM_CONTROLLER 1
201201

202+
/* The maximum number of banks */
203+
#define MAX_NUM_ZONES 8
204+
202205
/* The calibration coefficient of sensor */
203206
#define MT7622_CALIBRATION 165
204207

@@ -249,7 +252,7 @@ struct mtk_thermal_data {
249252
const int num_controller;
250253
const int *controller_offset;
251254
bool need_switch_bank;
252-
struct thermal_bank_cfg bank_data[];
255+
struct thermal_bank_cfg bank_data[MAX_NUM_ZONES];
253256
};
254257

255258
struct mtk_thermal {
@@ -268,7 +271,7 @@ struct mtk_thermal {
268271
s32 vts[MAX_NUM_VTS];
269272

270273
const struct mtk_thermal_data *conf;
271-
struct mtk_thermal_bank banks[];
274+
struct mtk_thermal_bank banks[MAX_NUM_ZONES];
272275
};
273276

274277
/* MT8183 thermal sensor data */

0 commit comments

Comments
 (0)