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 @@ -1902,40 +1902,49 @@ 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;
58 HDMI_WRITE(HDMI_CEC_CPU_MASK_SET, 0xffffffff);
60 - ret = devm_request_threaded_irq(&pdev->dev, platform_get_irq(pdev, 0),
61 - vc4_cec_irq_handler,
62 - vc4_cec_irq_handler_thread, 0,
63 - "vc4 hdmi cec", vc4_hdmi);
64 + ret = request_threaded_irq(platform_get_irq(pdev, 0),
65 + vc4_cec_irq_handler,
66 + vc4_cec_irq_handler_thread, 0,
67 + "vc4 hdmi cec", vc4_hdmi);
69 goto err_delete_cec_adap;
72 ret = cec_register_adapter(vc4_hdmi->cec_adap, &pdev->dev);
74 - goto err_delete_cec_adap;
75 + goto err_remove_handlers;
77 pm_runtime_put(&vc4_hdmi->pdev->dev);
82 + if (vc4_hdmi->variant->external_irq_controller)
83 + free_irq(platform_get_irq_byname(pdev, "cec-tx"), vc4_hdmi);
85 + free_irq(platform_get_irq(pdev, 0), vc4_hdmi);
87 +err_remove_cec_rx_handler:
88 + if (vc4_hdmi->variant->external_irq_controller)
89 + free_irq(platform_get_irq_byname(pdev, "cec-rx"), vc4_hdmi);
92 cec_delete_adapter(vc4_hdmi->cec_adap);
94 @@ -1944,6 +1953,15 @@ err_delete_cec_adap:
96 static void vc4_hdmi_cec_exit(struct vc4_hdmi *vc4_hdmi)
98 + struct platform_device *pdev = vc4_hdmi->pdev;
100 + if (vc4_hdmi->variant->external_irq_controller) {
101 + free_irq(platform_get_irq_byname(pdev, "cec-rx"), vc4_hdmi);
102 + free_irq(platform_get_irq_byname(pdev, "cec-tx"), vc4_hdmi);
104 + free_irq(platform_get_irq(pdev, 0), vc4_hdmi);
107 cec_unregister_adapter(vc4_hdmi->cec_adap);