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 @@ -1903,38 +1903,46 @@ 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 - vc4_cec_irq_handler_rx_bare,
35 - vc4_cec_irq_handler_rx_thread, 0,
36 - "vc4 hdmi cec rx", vc4_hdmi);
37 + ret = request_threaded_irq(platform_get_irq_byname(pdev, "cec-rx"),
38 + vc4_cec_irq_handler_rx_bare,
39 + vc4_cec_irq_handler_rx_thread, 0,
40 + "vc4 hdmi cec rx", vc4_hdmi);
42 goto err_delete_cec_adap;
44 - ret = devm_request_threaded_irq(&pdev->dev,
45 - platform_get_irq_byname(pdev, "cec-tx"),
46 - vc4_cec_irq_handler_tx_bare,
47 - vc4_cec_irq_handler_tx_thread, 0,
48 - "vc4 hdmi cec tx", vc4_hdmi);
49 + ret = request_threaded_irq(platform_get_irq_byname(pdev, "cec-tx"),
50 + vc4_cec_irq_handler_tx_bare,
51 + vc4_cec_irq_handler_tx_thread, 0,
52 + "vc4 hdmi cec tx", vc4_hdmi);
54 - goto err_delete_cec_adap;
55 + goto err_remove_cec_rx_handler;
57 HDMI_WRITE(HDMI_CEC_CPU_MASK_SET, 0xffffffff);
59 - ret = devm_request_threaded_irq(&pdev->dev, platform_get_irq(pdev, 0),
60 - vc4_cec_irq_handler,
61 - vc4_cec_irq_handler_thread, 0,
62 - "vc4 hdmi cec", vc4_hdmi);
63 + ret = request_threaded_irq(platform_get_irq(pdev, 0),
64 + vc4_cec_irq_handler,
65 + vc4_cec_irq_handler_thread, 0,
66 + "vc4 hdmi cec", vc4_hdmi);
68 goto err_delete_cec_adap;
71 ret = cec_register_adapter(vc4_hdmi->cec_adap, &pdev->dev);
73 - goto err_delete_cec_adap;
74 + goto err_remove_handlers;
79 + if (vc4_hdmi->variant->external_irq_controller)
80 + free_irq(platform_get_irq_byname(pdev, "cec-tx"), vc4_hdmi);
82 + free_irq(platform_get_irq(pdev, 0), vc4_hdmi);
84 +err_remove_cec_rx_handler:
85 + if (vc4_hdmi->variant->external_irq_controller)
86 + free_irq(platform_get_irq_byname(pdev, "cec-rx"), vc4_hdmi);
89 cec_delete_adapter(vc4_hdmi->cec_adap);
91 @@ -1943,6 +1951,15 @@ err_delete_cec_adap:
93 static void vc4_hdmi_cec_exit(struct vc4_hdmi *vc4_hdmi)
95 + struct platform_device *pdev = vc4_hdmi->pdev;
97 + if (vc4_hdmi->variant->external_irq_controller) {
98 + free_irq(platform_get_irq_byname(pdev, "cec-rx"), vc4_hdmi);
99 + free_irq(platform_get_irq_byname(pdev, "cec-tx"), vc4_hdmi);
101 + free_irq(platform_get_irq(pdev, 0), vc4_hdmi);
104 cec_unregister_adapter(vc4_hdmi->cec_adap);