0594e35dbeedef485bca4d0f98bd706509ef5e22
[openwrt/staging/linusw.git] /
1 From fda46a52e84a5160d7277e55e1c1be376b0ba579 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Mon, 5 Jul 2021 17:31:48 +0200
4 Subject: [PATCH] drm/vc4: hdmi: Drop devm interrupt handler for
5 hotplug interrupts
6
7 The hotplugs 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: f4790083c7c2 ("drm/vc4: hdmi: Rely on interrupts to handle hotplug")
21 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
22 ---
23 drivers/gpu/drm/vc4/vc4_hdmi.c | 41 +++++++++++++++++++++++-----------
24 1 file changed, 28 insertions(+), 13 deletions(-)
25
26 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
27 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
28 @@ -1611,26 +1611,28 @@ static irqreturn_t vc4_hdmi_hpd_irq_thre
29 static int vc4_hdmi_hotplug_init(struct vc4_hdmi *vc4_hdmi)
30 {
31 struct platform_device *pdev = vc4_hdmi->pdev;
32 - struct device *dev = &pdev->dev;
33 struct drm_connector *connector = &vc4_hdmi->connector;
34 int ret;
35
36 if (vc4_hdmi->variant->external_irq_controller) {
37 - ret = devm_request_threaded_irq(dev,
38 - platform_get_irq_byname(pdev, "hpd-connected"),
39 - NULL,
40 - vc4_hdmi_hpd_irq_thread, IRQF_ONESHOT,
41 - "vc4 hdmi hpd connected", vc4_hdmi);
42 + unsigned int hpd_con = platform_get_irq_byname(pdev, "hpd-connected");
43 + unsigned int hpd_rm = platform_get_irq_byname(pdev, "hpd-removed");
44 +
45 + ret = request_threaded_irq(hpd_con,
46 + NULL,
47 + vc4_hdmi_hpd_irq_thread, IRQF_ONESHOT,
48 + "vc4 hdmi hpd connected", vc4_hdmi);
49 if (ret)
50 return ret;
51
52 - ret = devm_request_threaded_irq(dev,
53 - platform_get_irq_byname(pdev, "hpd-removed"),
54 - NULL,
55 - vc4_hdmi_hpd_irq_thread, IRQF_ONESHOT,
56 - "vc4 hdmi hpd disconnected", vc4_hdmi);
57 - if (ret)
58 + ret = request_threaded_irq(hpd_rm,
59 + NULL,
60 + vc4_hdmi_hpd_irq_thread, IRQF_ONESHOT,
61 + "vc4 hdmi hpd disconnected", vc4_hdmi);
62 + if (ret) {
63 + free_irq(hpd_con, vc4_hdmi);
64 return ret;
65 + }
66
67 connector->polled = DRM_CONNECTOR_POLL_HPD;
68 }
69 @@ -1638,6 +1640,16 @@ static int vc4_hdmi_hotplug_init(struct
70 return 0;
71 }
72
73 +static void vc4_hdmi_hotplug_exit(struct vc4_hdmi *vc4_hdmi)
74 +{
75 + struct platform_device *pdev = vc4_hdmi->pdev;
76 +
77 + if (vc4_hdmi->variant->external_irq_controller) {
78 + free_irq(platform_get_irq_byname(pdev, "hpd-connected"), vc4_hdmi);
79 + free_irq(platform_get_irq_byname(pdev, "hpd-removed"), vc4_hdmi);
80 + }
81 +}
82 +
83 #ifdef CONFIG_DRM_VC4_HDMI_CEC
84 static irqreturn_t vc4_cec_irq_handler_rx_thread(int irq, void *priv)
85 {
86 @@ -2299,7 +2311,7 @@ static int vc4_hdmi_bind(struct device *
87
88 ret = vc4_hdmi_cec_init(vc4_hdmi);
89 if (ret)
90 - goto err_destroy_conn;
91 + goto err_free_hotplug;
92
93 ret = vc4_hdmi_audio_init(vc4_hdmi);
94 if (ret)
95 @@ -2313,6 +2325,8 @@ static int vc4_hdmi_bind(struct device *
96
97 err_free_cec:
98 vc4_hdmi_cec_exit(vc4_hdmi);
99 +err_free_hotplug:
100 + vc4_hdmi_hotplug_exit(vc4_hdmi);
101 err_destroy_conn:
102 vc4_hdmi_connector_destroy(&vc4_hdmi->connector);
103 err_destroy_encoder:
104 @@ -2354,6 +2368,7 @@ static void vc4_hdmi_unbind(struct devic
105 kfree(vc4_hdmi->hd_regset.regs);
106
107 vc4_hdmi_cec_exit(vc4_hdmi);
108 + vc4_hdmi_hotplug_exit(vc4_hdmi);
109 vc4_hdmi_connector_destroy(&vc4_hdmi->connector);
110 drm_encoder_cleanup(&vc4_hdmi->encoder.base.base);
111