* [PATCH v2] drm/mediatek: dp: Support flexible length of DP calibration data
@ 2024-12-04 14:25 Fei Shao
2024-12-31 3:32 ` CK Hu (胡俊光)
2025-01-02 13:43 ` Chun-Kuang Hu
0 siblings, 2 replies; 3+ messages in thread
From: Fei Shao @ 2024-12-04 14:25 UTC (permalink / raw)
To: Chun-Kuang Hu
Cc: Fei Shao, AngeloGioacchino Del Regno, Matthias Brugger,
dri-devel, linux-arm-kernel, linux-kernel, linux-mediatek
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 <fshao@chromium.org>
---
Changes in v2:
- use %zu identifier for size_t in dev_warn()
drivers/gpu/drm/mediatek/mtk_dp.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c
index 36713c176cfc..55671701459a 100644
--- a/drivers/gpu/drm/mediatek/mtk_dp.c
+++ b/drivers/gpu/drm/mediatek/mtk_dp.c
@@ -1165,17 +1165,25 @@ static void mtk_dp_get_calibration_data(struct mtk_dp *mtk_dp)
buf = (u32 *)nvmem_cell_read(cell, &len);
nvmem_cell_put(cell);
- if (IS_ERR(buf) || ((len / sizeof(u32)) != 4)) {
+ if (IS_ERR(buf)) {
dev_warn(dev, "Failed to read nvmem_cell_read\n");
-
- if (!IS_ERR(buf))
- kfree(buf);
-
goto use_default_val;
}
+ /* The cell length is in bytes. Convert it to be compatible with u32 buffer. */
+ len /= sizeof(u32);
+
for (i = 0; i < MTK_DP_CAL_MAX; i++) {
fmt = &mtk_dp->data->efuse_fmt[i];
+
+ if (fmt->idx >= len) {
+ dev_warn(mtk_dp->dev,
+ "Out-of-bound efuse data access, fmt idx = %d, buf len = %zu\n",
+ fmt->idx, len);
+ kfree(buf);
+ goto use_default_val;
+ }
+
cal_data[i] = (buf[fmt->idx] >> fmt->shift) & fmt->mask;
if (cal_data[i] < fmt->min_val || cal_data[i] > fmt->max_val) {
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] drm/mediatek: dp: Support flexible length of DP calibration data
2024-12-04 14:25 [PATCH v2] drm/mediatek: dp: Support flexible length of DP calibration data Fei Shao
@ 2024-12-31 3:32 ` CK Hu (胡俊光)
2025-01-02 13:43 ` Chun-Kuang Hu
1 sibling, 0 replies; 3+ messages in thread
From: CK Hu (胡俊光) @ 2024-12-31 3:32 UTC (permalink / raw)
To: fshao, chunkuang.hu
Cc: dri-devel, linux-arm-kernel, AngeloGioacchino Del Regno,
matthias.bgg, linux-kernel, linux-mediatek
Hi, Fei:
On Wed, 2024-12-04 at 22:25 +0800, Fei Shao wrote:
> External email : Please do not click links or open attachments until you have verified the sender or the content.
>
>
> 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.
Reviewed-by: CK Hu <ck.hu@mediatek.com>
>
> Signed-off-by: Fei Shao <fshao@chromium.org>
> ---
>
> Changes in v2:
> - use %zu identifier for size_t in dev_warn()
>
> drivers/gpu/drm/mediatek/mtk_dp.c | 18 +++++++++++++-----
> 1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c
> index 36713c176cfc..55671701459a 100644
> --- a/drivers/gpu/drm/mediatek/mtk_dp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_dp.c
> @@ -1165,17 +1165,25 @@ static void mtk_dp_get_calibration_data(struct mtk_dp *mtk_dp)
> buf = (u32 *)nvmem_cell_read(cell, &len);
> nvmem_cell_put(cell);
>
> - if (IS_ERR(buf) || ((len / sizeof(u32)) != 4)) {
> + if (IS_ERR(buf)) {
> dev_warn(dev, "Failed to read nvmem_cell_read\n");
> -
> - if (!IS_ERR(buf))
> - kfree(buf);
> -
> goto use_default_val;
> }
>
> + /* The cell length is in bytes. Convert it to be compatible with u32 buffer. */
> + len /= sizeof(u32);
> +
> for (i = 0; i < MTK_DP_CAL_MAX; i++) {
> fmt = &mtk_dp->data->efuse_fmt[i];
> +
> + if (fmt->idx >= len) {
> + dev_warn(mtk_dp->dev,
> + "Out-of-bound efuse data access, fmt idx = %d, buf len = %zu\n",
> + fmt->idx, len);
> + kfree(buf);
> + goto use_default_val;
> + }
> +
> cal_data[i] = (buf[fmt->idx] >> fmt->shift) & fmt->mask;
>
> if (cal_data[i] < fmt->min_val || cal_data[i] > fmt->max_val) {
> --
> 2.47.0.338.g60cca15819-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] drm/mediatek: dp: Support flexible length of DP calibration data
2024-12-04 14:25 [PATCH v2] drm/mediatek: dp: Support flexible length of DP calibration data Fei Shao
2024-12-31 3:32 ` CK Hu (胡俊光)
@ 2025-01-02 13:43 ` Chun-Kuang Hu
1 sibling, 0 replies; 3+ messages in thread
From: Chun-Kuang Hu @ 2025-01-02 13:43 UTC (permalink / raw)
To: Fei Shao
Cc: Chun-Kuang Hu, AngeloGioacchino Del Regno, Matthias Brugger,
dri-devel, linux-arm-kernel, linux-kernel, linux-mediatek
Hi, Fei:
Fei Shao <fshao@chromium.org> 於 2024年12月4日 週三 下午10:26寫道:
>
> 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.
Applied to mediatek-drm-next [1], thanks.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/chunkuang.hu/linux.git/log/?h=mediatek-drm-next
Regards,
Chun-Kuang.
>
> Signed-off-by: Fei Shao <fshao@chromium.org>
> ---
>
> Changes in v2:
> - use %zu identifier for size_t in dev_warn()
>
> drivers/gpu/drm/mediatek/mtk_dp.c | 18 +++++++++++++-----
> 1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c
> index 36713c176cfc..55671701459a 100644
> --- a/drivers/gpu/drm/mediatek/mtk_dp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_dp.c
> @@ -1165,17 +1165,25 @@ static void mtk_dp_get_calibration_data(struct mtk_dp *mtk_dp)
> buf = (u32 *)nvmem_cell_read(cell, &len);
> nvmem_cell_put(cell);
>
> - if (IS_ERR(buf) || ((len / sizeof(u32)) != 4)) {
> + if (IS_ERR(buf)) {
> dev_warn(dev, "Failed to read nvmem_cell_read\n");
> -
> - if (!IS_ERR(buf))
> - kfree(buf);
> -
> goto use_default_val;
> }
>
> + /* The cell length is in bytes. Convert it to be compatible with u32 buffer. */
> + len /= sizeof(u32);
> +
> for (i = 0; i < MTK_DP_CAL_MAX; i++) {
> fmt = &mtk_dp->data->efuse_fmt[i];
> +
> + if (fmt->idx >= len) {
> + dev_warn(mtk_dp->dev,
> + "Out-of-bound efuse data access, fmt idx = %d, buf len = %zu\n",
> + fmt->idx, len);
> + kfree(buf);
> + goto use_default_val;
> + }
> +
> cal_data[i] = (buf[fmt->idx] >> fmt->shift) & fmt->mask;
>
> if (cal_data[i] < fmt->min_val || cal_data[i] > fmt->max_val) {
> --
> 2.47.0.338.g60cca15819-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-01-02 13:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-04 14:25 [PATCH v2] drm/mediatek: dp: Support flexible length of DP calibration data Fei Shao
2024-12-31 3:32 ` CK Hu (胡俊光)
2025-01-02 13:43 ` Chun-Kuang Hu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®