4c3f1700671553e023027b363b92807fb7f15c50
[openwrt/staging/ynezz.git] /
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
5 interrupts
6
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.
11
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.
15
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
18 make it safe.
19
20 Fixes: 15b4511a4af6 ("drm/vc4: add HDMI CEC support")
21 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
22 ---
23 drivers/gpu/drm/vc4/vc4_hdmi.c | 49 +++++++++++++++++++++++-----------
24 1 file changed, 33 insertions(+), 16 deletions(-)
25
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);
30
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);
38 if (ret)
39 goto err_delete_cec_adap;
40
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);
47 if (ret)
48 - goto err_delete_cec_adap;
49 + goto err_remove_cec_rx_handler;
50 } else {
51 HDMI_WRITE(HDMI_CEC_CPU_MASK_SET, 0xffffffff);
52
53 - ret = devm_request_threaded_irq(&pdev->dev, platform_get_irq(pdev, 0),
54 + ret = request_threaded_irq(platform_get_irq(pdev, 0),
55 vc4_cec_irq_handler,
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_
59
60 ret = cec_register_adapter(vc4_hdmi->cec_adap, &pdev->dev);
61 if (ret < 0)
62 - goto err_delete_cec_adap;
63 + goto err_remove_handlers;
64
65 return 0;
66
67 +err_remove_handlers:
68 + if (vc4_hdmi->variant->external_irq_controller)
69 + free_irq(platform_get_irq_byname(pdev, "cec-tx"), vc4_hdmi);
70 + else
71 + free_irq(platform_get_irq(pdev, 0), vc4_hdmi);
72 +
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);
76 +
77 err_delete_cec_adap:
78 cec_delete_adapter(vc4_hdmi->cec_adap);
79
80 @@ -1936,6 +1944,15 @@ err_delete_cec_adap:
81
82 static void vc4_hdmi_cec_exit(struct vc4_hdmi *vc4_hdmi)
83 {
84 + struct platform_device *pdev = vc4_hdmi->pdev;
85 +
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);
89 + } else {
90 + free_irq(platform_get_irq(pdev, 0), vc4_hdmi);
91 + }
92 +
93 cec_unregister_adapter(vc4_hdmi->cec_adap);
94 }
95 #else