1 From 687a0fc86f37e0bc74c8382c0d89b0929fade1de Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Mon, 5 Jul 2021 15:47:43 +0200
4 Subject: [PATCH] drm/vc4: hdmi: Drop devm interrupt handler for CEC
7 The CEC interrupt handlers are registered through the
8 devm_request_threaded_irq function. However, while free_irq is indeed
9 called properly when the device is unbound or bind fails, it's called
10 after unbind or bind is done.
12 In our particular case, it means that on failure it creates a window
13 where our interrupt handler can be called, but we're freeing every
14 resource (CEC adapter, DRM objects, etc.) it might need.
16 In order to address this, let's switch to the non-devm variant to
17 control better when the handler will be unregistered and allow us to
20 Fixes: 15b4511a4af6 ("drm/vc4: add HDMI CEC support")
21 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
23 drivers/gpu/drm/vc4/vc4_hdmi.c | 49 +++++++++++++++++++++++-----------
24 1 file changed, 33 insertions(+), 16 deletions(-)
26 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
27 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
28 @@ -1896,25 +1896,23 @@ static int vc4_hdmi_cec_init(struct vc4_
29 vc4_hdmi_cec_update_clk_div(vc4_hdmi);
31 if (vc4_hdmi->variant->external_irq_controller) {
32 - ret = devm_request_threaded_irq(&pdev->dev,
33 - platform_get_irq_byname(pdev, "cec-rx"),
34 + ret = request_threaded_irq(platform_get_irq_byname(pdev, "cec-rx"),
35 vc4_cec_irq_handler_rx_bare,
36 vc4_cec_irq_handler_rx_thread, 0,
37 "vc4 hdmi cec rx", vc4_hdmi);
39 goto err_delete_cec_adap;
41 - ret = devm_request_threaded_irq(&pdev->dev,
42 - platform_get_irq_byname(pdev, "cec-tx"),
43 + ret = request_threaded_irq(platform_get_irq_byname(pdev, "cec-tx"),
44 vc4_cec_irq_handler_tx_bare,
45 vc4_cec_irq_handler_tx_thread, 0,
46 "vc4 hdmi cec tx", vc4_hdmi);
48 - goto err_delete_cec_adap;
49 + goto err_remove_cec_rx_handler;
51 HDMI_WRITE(HDMI_CEC_CPU_MASK_SET, 0xffffffff);
53 - ret = devm_request_threaded_irq(&pdev->dev, platform_get_irq(pdev, 0),
54 + ret = request_threaded_irq(platform_get_irq(pdev, 0),
56 vc4_cec_irq_handler_thread, 0,
57 "vc4 hdmi cec", vc4_hdmi);
58 @@ -1924,10 +1922,20 @@ static int vc4_hdmi_cec_init(struct vc4_
60 ret = cec_register_adapter(vc4_hdmi->cec_adap, &pdev->dev);
62 - goto err_delete_cec_adap;
63 + goto err_remove_handlers;
68 + if (vc4_hdmi->variant->external_irq_controller)
69 + free_irq(platform_get_irq_byname(pdev, "cec-tx"), vc4_hdmi);
71 + free_irq(platform_get_irq(pdev, 0), vc4_hdmi);
73 +err_remove_cec_rx_handler:
74 + if (vc4_hdmi->variant->external_irq_controller)
75 + free_irq(platform_get_irq_byname(pdev, "cec-rx"), vc4_hdmi);
78 cec_delete_adapter(vc4_hdmi->cec_adap);
80 @@ -1936,6 +1944,15 @@ err_delete_cec_adap:
82 static void vc4_hdmi_cec_exit(struct vc4_hdmi *vc4_hdmi)
84 + struct platform_device *pdev = vc4_hdmi->pdev;
86 + if (vc4_hdmi->variant->external_irq_controller) {
87 + free_irq(platform_get_irq_byname(pdev, "cec-rx"), vc4_hdmi);
88 + free_irq(platform_get_irq_byname(pdev, "cec-tx"), vc4_hdmi);
90 + free_irq(platform_get_irq(pdev, 0), vc4_hdmi);
93 cec_unregister_adapter(vc4_hdmi->cec_adap);