drm/rockchip: dw_hdmi: cleanup drm encoder during unbind
authorToby Chen <tobyc@nvidia.com>
Fri, 17 Mar 2023 00:51:26 +0000 (17:51 -0700)
committerHeiko Stuebner <heiko@sntech.de>
Wed, 22 Mar 2023 23:05:28 +0000 (00:05 +0100)
This fixes a use-after-free crash during rmmod.

The DRM encoder is embedded inside the larger rockchip_hdmi,
which is allocated with the component. The component memory
gets freed before the main drm device is destroyed. Fix it
by running encoder cleanup before tearing down its container.

Signed-off-by: Toby Chen <tobyc@nvidia.com>
[moved encoder cleanup above clk_disable, similar to bind-error-path]
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20230317005126.496-1-tobyc@nvidia.com
drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c

index 293dcf0..1126999 100644 (file)
@@ -667,6 +667,7 @@ static void dw_hdmi_rockchip_unbind(struct device *dev, struct device *master,
        struct rockchip_hdmi *hdmi = dev_get_drvdata(dev);
 
        dw_hdmi_unbind(hdmi->hdmi);
+       drm_encoder_cleanup(&hdmi->encoder.encoder);
        clk_disable_unprepare(hdmi->ref_clk);
 
        regulator_disable(hdmi->avdd_1v8);