Skip to content

Commit b66c079

Browse files
jpanisbldlezcano
authored andcommitted
thermal/drivers/mediatek/lvts_thermal: Fix wrong lvts_ctrl index
In 'lvts_should_update_thresh()' and 'lvts_ctrl_start()' functions, the parameter passed to 'lvts_for_each_valid_sensor()' macro is always 'lvts_ctrl->lvts_data->lvts_ctrl'. In other words, the array index 0 is systematically passed as 'struct lvts_ctrl_data' type item, even when another item should be consumed instead. Hence, the 'valid_sensor_mask' value which is selected can be wrong because unrelated to the 'struct lvts_ctrl_data' type item that should be used. Hence, some thermal zone can be registered for a sensor 'i' that does not actually exist. Because of the invalid address used as 'lvts_sensor[i].msr', this situation ends up with a crash in 'lvts_get_temp()' function, where this 'msr' pointer is passed to 'readl_poll_timeout()' function. The following message is output: "Unable to handle kernel NULL pointer dereference at virtual address <msr>", with <msr> = 0. This patch fixes the issue. Fixes: 11e6f4c ("thermal/drivers/mediatek/lvts_thermal: Allow early empty sensor slots") Signed-off-by: Julien Panis <jpanis@baylibre.com> Reviewed-by: Nicolas Pitre <npitre@baylibre.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Link: https://lore.kernel.org/r/20240503-mtk-thermal-lvts-ctrl-idx-fix-v1-2-f605c50ca117@baylibre.com
1 parent e2d2266 commit b66c079

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

drivers/thermal/mediatek/lvts_thermal.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ struct lvts_ctrl_data {
116116
((s2) ? BIT(2) : 0) | \
117117
((s3) ? BIT(3) : 0))
118118

119-
#define lvts_for_each_valid_sensor(i, lvts_ctrl_data) \
119+
#define lvts_for_each_valid_sensor(i, lvts_ctrl) \
120120
for ((i) = 0; (i) < LVTS_SENSOR_MAX; (i)++) \
121-
if (!((lvts_ctrl_data)->valid_sensor_mask & BIT(i))) \
121+
if (!((lvts_ctrl)->valid_sensor_mask & BIT(i))) \
122122
continue; \
123123
else
124124

@@ -145,6 +145,7 @@ struct lvts_ctrl {
145145
const struct lvts_data *lvts_data;
146146
u32 calibration[LVTS_SENSOR_MAX];
147147
u32 hw_tshut_raw_temp;
148+
u8 valid_sensor_mask;
148149
int mode;
149150
void __iomem *base;
150151
int low_thresh;
@@ -356,7 +357,7 @@ static bool lvts_should_update_thresh(struct lvts_ctrl *lvts_ctrl, int high)
356357
if (high > lvts_ctrl->high_thresh)
357358
return true;
358359

359-
lvts_for_each_valid_sensor(i, lvts_ctrl->lvts_data->lvts_ctrl)
360+
lvts_for_each_valid_sensor(i, lvts_ctrl)
360361
if (lvts_ctrl->sensors[i].high_thresh == lvts_ctrl->high_thresh
361362
&& lvts_ctrl->sensors[i].low_thresh == lvts_ctrl->low_thresh)
362363
return false;
@@ -617,6 +618,8 @@ static int lvts_sensor_init(struct device *dev, struct lvts_ctrl *lvts_ctrl,
617618
lvts_sensor[i].high_thresh = INT_MIN;
618619
};
619620

621+
lvts_ctrl->valid_sensor_mask = lvts_ctrl_data->valid_sensor_mask;
622+
620623
return 0;
621624
}
622625

@@ -1112,7 +1115,7 @@ static int lvts_ctrl_start(struct device *dev, struct lvts_ctrl *lvts_ctrl)
11121115
u32 *sensor_bitmap = lvts_ctrl->mode == LVTS_MSR_IMMEDIATE_MODE ?
11131116
sensor_imm_bitmap : sensor_filt_bitmap;
11141117

1115-
lvts_for_each_valid_sensor(i, lvts_ctrl->lvts_data->lvts_ctrl) {
1118+
lvts_for_each_valid_sensor(i, lvts_ctrl) {
11161119

11171120
int dt_id = lvts_sensors[i].dt_id;
11181121

0 commit comments

Comments
 (0)