950-0676-drm-vc4-hdmi-Drop-devm-interrupt-handler-for-hotplug.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. From fda46a52e84a5160d7277e55e1c1be376b0ba579 Mon Sep 17 00:00:00 2001
  2. From: Maxime Ripard <[email protected]>
  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. The hotplugs interrupt handlers are registered through the
  7. devm_request_threaded_irq function. However, while free_irq is indeed
  8. called properly when the device is unbound or bind fails, it's called
  9. after unbind or bind is done.
  10. In our particular case, it means that on failure it creates a window
  11. where our interrupt handler can be called, but we're freeing every
  12. resource (CEC adapter, DRM objects, etc.) it might need.
  13. In order to address this, let's switch to the non-devm variant to
  14. control better when the handler will be unregistered and allow us to
  15. make it safe.
  16. Fixes: f4790083c7c2 ("drm/vc4: hdmi: Rely on interrupts to handle hotplug")
  17. Signed-off-by: Maxime Ripard <[email protected]>
  18. ---
  19. drivers/gpu/drm/vc4/vc4_hdmi.c | 41 +++++++++++++++++++++++-----------
  20. 1 file changed, 28 insertions(+), 13 deletions(-)
  21. --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
  22. +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
  23. @@ -1612,26 +1612,28 @@ static irqreturn_t vc4_hdmi_hpd_irq_thre
  24. static int vc4_hdmi_hotplug_init(struct vc4_hdmi *vc4_hdmi)
  25. {
  26. struct platform_device *pdev = vc4_hdmi->pdev;
  27. - struct device *dev = &pdev->dev;
  28. struct drm_connector *connector = &vc4_hdmi->connector;
  29. int ret;
  30. if (vc4_hdmi->variant->external_irq_controller) {
  31. - ret = devm_request_threaded_irq(dev,
  32. - platform_get_irq_byname(pdev, "hpd-connected"),
  33. - NULL,
  34. - vc4_hdmi_hpd_irq_thread, IRQF_ONESHOT,
  35. - "vc4 hdmi hpd connected", vc4_hdmi);
  36. + unsigned int hpd_con = platform_get_irq_byname(pdev, "hpd-connected");
  37. + unsigned int hpd_rm = platform_get_irq_byname(pdev, "hpd-removed");
  38. +
  39. + ret = request_threaded_irq(hpd_con,
  40. + NULL,
  41. + vc4_hdmi_hpd_irq_thread, IRQF_ONESHOT,
  42. + "vc4 hdmi hpd connected", vc4_hdmi);
  43. if (ret)
  44. return ret;
  45. - ret = devm_request_threaded_irq(dev,
  46. - platform_get_irq_byname(pdev, "hpd-removed"),
  47. - NULL,
  48. - vc4_hdmi_hpd_irq_thread, IRQF_ONESHOT,
  49. - "vc4 hdmi hpd disconnected", vc4_hdmi);
  50. - if (ret)
  51. + ret = request_threaded_irq(hpd_rm,
  52. + NULL,
  53. + vc4_hdmi_hpd_irq_thread, IRQF_ONESHOT,
  54. + "vc4 hdmi hpd disconnected", vc4_hdmi);
  55. + if (ret) {
  56. + free_irq(hpd_con, vc4_hdmi);
  57. return ret;
  58. + }
  59. connector->polled = DRM_CONNECTOR_POLL_HPD;
  60. }
  61. @@ -1639,6 +1641,16 @@ static int vc4_hdmi_hotplug_init(struct
  62. return 0;
  63. }
  64. +static void vc4_hdmi_hotplug_exit(struct vc4_hdmi *vc4_hdmi)
  65. +{
  66. + struct platform_device *pdev = vc4_hdmi->pdev;
  67. +
  68. + if (vc4_hdmi->variant->external_irq_controller) {
  69. + free_irq(platform_get_irq_byname(pdev, "hpd-connected"), vc4_hdmi);
  70. + free_irq(platform_get_irq_byname(pdev, "hpd-removed"), vc4_hdmi);
  71. + }
  72. +}
  73. +
  74. #ifdef CONFIG_DRM_VC4_HDMI_CEC
  75. static irqreturn_t vc4_cec_irq_handler_rx_thread(int irq, void *priv)
  76. {
  77. @@ -2305,7 +2317,7 @@ static int vc4_hdmi_bind(struct device *
  78. ret = vc4_hdmi_cec_init(vc4_hdmi);
  79. if (ret)
  80. - goto err_destroy_conn;
  81. + goto err_free_hotplug;
  82. ret = vc4_hdmi_audio_init(vc4_hdmi);
  83. if (ret)
  84. @@ -2319,6 +2331,8 @@ static int vc4_hdmi_bind(struct device *
  85. err_free_cec:
  86. vc4_hdmi_cec_exit(vc4_hdmi);
  87. +err_free_hotplug:
  88. + vc4_hdmi_hotplug_exit(vc4_hdmi);
  89. err_destroy_conn:
  90. vc4_hdmi_connector_destroy(&vc4_hdmi->connector);
  91. err_destroy_encoder:
  92. @@ -2360,6 +2374,7 @@ static void vc4_hdmi_unbind(struct devic
  93. kfree(vc4_hdmi->hd_regset.regs);
  94. vc4_hdmi_cec_exit(vc4_hdmi);
  95. + vc4_hdmi_hotplug_exit(vc4_hdmi);
  96. vc4_hdmi_connector_destroy(&vc4_hdmi->connector);
  97. drm_encoder_cleanup(&vc4_hdmi->encoder.base.base);