Skip to content

Commit ba58115

Browse files
Fei ShaoChun-Kuang Hu
authored andcommitted
drm/mediatek: dp: Support flexible length of DP calibration data
The DP calibration data is stored in nvmem cells, and the data layout is described in the `mtk_dp_efuse_fmt` arrays for each platform. There is no guarantee that the data is always a 4-length u32 cell array. For example, MT8188 has a data length of 3, preventing it from passing the preliminary check and undergoing calibration. Update the logic to support flexible data lengths. Specifically, we validate the length returned from `nvmem_cell_read()` against the platform-specific efuse format. If out-of-bound access is detected, fall back to the default calibration values. This likely indicates an error in either the efuse data length described in DT or the efuse format within the driver. Signed-off-by: Fei Shao <[email protected]> Reviewed-by: CK Hu <[email protected]> Link: https://patchwork.kernel.org/project/dri-devel/patch/[email protected]/ Signed-off-by: Chun-Kuang Hu <[email protected]>
1 parent 4f0d4a8 commit ba58115

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

drivers/gpu/drm/mediatek/mtk_dp.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,17 +1177,25 @@ static void mtk_dp_get_calibration_data(struct mtk_dp *mtk_dp)
11771177
buf = (u32 *)nvmem_cell_read(cell, &len);
11781178
nvmem_cell_put(cell);
11791179

1180-
if (IS_ERR(buf) || ((len / sizeof(u32)) != 4)) {
1180+
if (IS_ERR(buf)) {
11811181
dev_warn(dev, "Failed to read nvmem_cell_read\n");
1182-
1183-
if (!IS_ERR(buf))
1184-
kfree(buf);
1185-
11861182
goto use_default_val;
11871183
}
11881184

1185+
/* The cell length is in bytes. Convert it to be compatible with u32 buffer. */
1186+
len /= sizeof(u32);
1187+
11891188
for (i = 0; i < MTK_DP_CAL_MAX; i++) {
11901189
fmt = &mtk_dp->data->efuse_fmt[i];
1190+
1191+
if (fmt->idx >= len) {
1192+
dev_warn(mtk_dp->dev,
1193+
"Out-of-bound efuse data access, fmt idx = %d, buf len = %zu\n",
1194+
fmt->idx, len);
1195+
kfree(buf);
1196+
goto use_default_val;
1197+
}
1198+
11911199
cal_data[i] = (buf[fmt->idx] >> fmt->shift) & fmt->mask;
11921200

11931201
if (cal_data[i] < fmt->min_val || cal_data[i] > fmt->max_val) {

0 commit comments

Comments
 (0)