]> git.baikalelectronics.ru Git - kernel.git/commitdiff
thermal: mtk: Allocate enough space for mtk_thermal.
authorPi-Hsun Shih <pihsun@chromium.org>
Wed, 9 Jan 2019 05:57:24 +0000 (13:57 +0800)
committerZhang Rui <rui.zhang@intel.com>
Mon, 18 Mar 2019 14:23:10 +0000 (22:23 +0800)
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>
drivers/thermal/mtk_thermal.c

index 5c07a61447d3fc1bb469ab531a876a27fae44739..e4ea7f6aef20e335e160ad11605bc4f318e17739 100644 (file)
@@ -199,6 +199,9 @@ enum {
 #define MT7622_TS1     0
 #define MT7622_NUM_CONTROLLER          1
 
+/* The maximum number of banks */
+#define MAX_NUM_ZONES          8
+
 /* The calibration coefficient of sensor  */
 #define MT7622_CALIBRATION     165
 
@@ -249,7 +252,7 @@ struct mtk_thermal_data {
        const int num_controller;
        const int *controller_offset;
        bool need_switch_bank;
-       struct thermal_bank_cfg bank_data[];
+       struct thermal_bank_cfg bank_data[MAX_NUM_ZONES];
 };
 
 struct mtk_thermal {
@@ -268,7 +271,7 @@ struct mtk_thermal {
        s32 vts[MAX_NUM_VTS];
 
        const struct mtk_thermal_data *conf;
-       struct mtk_thermal_bank banks[];
+       struct mtk_thermal_bank banks[MAX_NUM_ZONES];
 };
 
 /* MT8183 thermal sensor data */