Skip to contentSkip to conversation

drm/meson: constrain the DW-HDMI regmap range

PATCH New Zinan Zhou 2 participants 2 messages Jul 18

Subsystems (4)
lore
Share & tools
lore

Zinan Zhou

author
#0 lore raw

PATCH 1/1 drm/meson: constrain the DW-HDMI regmap range

The DesignWare HDMI regmap declares 0x10000 as its inclusive maximum register. A regmap traversal can consequently read one byte past the directly mapped G12A 64 KiB resource. It also treats the Meson TOP window from offset 0x8000 as DWC registers. On the older indirect interface, the address is truncated to 16 bits and aliases register zero.

Limit the regmap to 0x7e12, the last register defined by the supported Synopsys HDMI controller. This also keeps register iteration below the Meson TOP register window at offset 0x8000.

Fixes 3f68be7d8e96 ("drm/meson: Add support for HDMI encoder and DW-HDMI bridge + PHY")
Assisted-by Codex:gpt-5.6-sol
---
 drivers/gpu/drm/meson/meson_dw_hdmi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/meson/meson_dw_hdmi.c +3 -1
index fef1702acb14..1004108fb7ca 100644
@@ -100,6 +100,8 @@
 #define HDMITX_DWC_ADDR_REG	0x10
 #define HDMITX_DWC_DATA_REG	0x14
 #define HDMITX_DWC_CTRL_REG	0x18
+/* Last DWC register; direct layouts place the TOP block at offset 0x8000. */
+#define HDMITX_DWC_MAX_REGISTER	0x7e12
 
 /* HHI Registers */
 #define HHI_MEM_PD_REG0		0x100 /* 0x40 */
@@ -564,7 +566,7 @@ static const struct regmap_config meson_dw_hdmi_regmap_config = {
 	.val_bits = 8,
 	.reg_read = meson_dw_hdmi_reg_read,
 	.reg_write = meson_dw_hdmi_reg_write,
-	.max_register = 0x10000,
+	.max_register = HDMITX_DWC_MAX_REGISTER,
 	.fast_io = true,
 };
 

base-commit: b0a652436b892eb9a036a031b33099dca036faaa

Signature · 1 line
2.43.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The threaded IRQ handler dw_hdmi_top_thread_irq can execute before the hdmi and bridge pointers are initialized, leading to a NULL pointer dereference. --

--- Patch [1]: [PATCH] drm/meson: constrain the DW-HDMI regmap range --- commit f8ff68e6f372ddb9f5ca83893e7f1b1b21342d72
Author: Zinan Zhou <[email protected]>

drm/meson: constrain the DW-HDMI regmap range

The DesignWare HDMI regmap declares 0x10000 as its inclusive maximum register. A regmap traversal can consequently read one byte past the directly mapped G12A 64 KiB resource. It also treats the Meson TOP window from offset 0x8000 as DWC registers. On the older indirect interface, the address is truncated to 16 bits and aliases register zero.

Limit the regmap to 0x7e12, the last register defined by the supported Synopsys HDMI controller. This also keeps register iteration below the Meson TOP register window at offset 0x8000.

Quoted 4 lines
drivers/gpu/drm/meson/meson_dw_hdmi.c +0 -0
index fef1702acb145..1004108fb7ca2 100644

[ ... ]

drivers/gpu/drm/meson/meson_dw_hdmi.c static const struct regmap_config meson_dw_hdmi_regmap_config = { · line 571

Quoted 8 lines
drivers/gpu/drm/meson/meson_dw_hdmi.c +1 -1
@@ -564,7 +566,7 @@ static const struct regmap_config meson_dw_hdmi_regmap_config = {
 	.val_bits = 8,
 	.reg_read = meson_dw_hdmi_reg_read,
 	.reg_write = meson_dw_hdmi_reg_write,
-	.max_register = 0x10000,
+	.max_register = HDMITX_DWC_MAX_REGISTER,
 	.fast_io = true,
 };

[Severity: High]
This isn't a bug introduced by this patch, but while reviewing this file I noticed a potential race condition during initialization.

In meson_dw_hdmi_bind(), the IRQ handler is registered via devm_request_threaded_irq() before dw_hdmi->hdmi and dw_hdmi->bridge are initialized:

drivers/gpu/drm/meson/meson_dw_hdmi.c:meson_dw_hdmi_bind() {
    ...
    ret = devm_request_threaded_irq(dev, irq, dw_hdmi_top_irq,
                                    dw_hdmi_top_thread_irq, IRQF_SHARED,
                                    "dw_hdmi_top_irq", meson_dw_hdmi);
    ...
    meson_dw_hdmi->hdmi = dw_hdmi_probe(pdev, &meson_dw_hdmi->dw_plat_data);
    ...
    meson_dw_hdmi->bridge = of_drm_find_and_get_bridge(pdev->dev.of_node);
    ...
}

The driver then calls dw_hdmi_probe(), which unmasks the HPD interrupts at the hardware level.

If an HPD interrupt fires immediately (e.g., if a cable is already connected or the line bounces), can dw_hdmi_top_thread_irq() execute concurrently and cause a NULL pointer dereference?

drivers/gpu/drm/meson/meson_dw_hdmi.c:dw_hdmi_top_thread_irq() {
    ...
    dw_hdmi_setup_rx_sense(dw_hdmi->hdmi, hpd_connected,
                           hpd_connected);

    drm_helper_hpd_irq_event(dw_hdmi->bridge->dev);
    ...
}

Since dw_hdmi_probe() has not yet returned, wouldn't dw_hdmi->hdmi and dw_hdmi->bridge still be NULL at this point, causing a crash when dereferencing them?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1