Received: by 2002:aa6:da0e:0:b029:115:a171:fe4c with SMTP id z14csp1263227lkb; Wed, 7 Jul 2021 02:53:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7X49+oP2buaUXLD+sJYi3Tt6dYyxxFGLRNYvGxcGc5Yoq67LBA8QQweIKNKkxpatJekKp X-Received: by 2002:a05:6402:384:: with SMTP id o4mr4742058edv.131.1625651610600; Wed, 07 Jul 2021 02:53:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625651610; cv=none; d=google.com; s=arc-20160816; b=RiWQnNCVse26aLgcs5Sjh/bana/zo4+pnN6v3HIz1Cr+2ZSnqCPjD5bY7DdNHVZ6qe vrHhyQP3DH63cXqC/C+ORfM8mNZT2Jg32nmiRyOWGT6Hn0uvomg41oVV5qmbHFA5BcYZ HgHm3pAEsXSMVaX7yhTr9fRRcwHRoPUQqQmbilVDbAtvkK8jVdhilo5J+9Xdg5uP2g8J +4YngGIHQi1gHJT1cuD4HMqHIJJaELFOcAQYqBtIdQNyvdbOrPb2C71I015xjf3fG+Nz irqeU5YKdOgVEpbWezlUUwIPjUwg/D6vfrqkzc1nIxx4vbKFf5TotTnRdRdsyTfsSAF+ ecDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=AP/I8rxrmE9MlRDmDxJIy4tqdiKllNYXAEVIGV9L3GI=; b=RSbtz4Kxm96gPJt0EgwbYe3e8vgrvmwQn3bJVZRMGu9vcOrEGU0txDHoz0rCCXVOD1 pQrfPbXXcYsZMHEI2/3eCmGvYoxpxHa7TWATEJcIsGormu8YaP1X4+z3bHh/nCOqx1h0 3ZyDX4Z1F15OkQl1xb3I24i6l3cVUMtCdOJ4izHbc6sWVG7UMVDNePLkM5zS/XJ6OHNJ pZV1qV+OmbbctfwFsdoPQMyyKu/JBJvdiyXKyPKViUj4r7T1nF0m0h/P+zbkYuI7HJlH rH854924GlYNc5xAJ68//LDRW6GQhL0WhvJ+Al+5D5ej2TBroPORgwi+TtF9MdGMOHn8 6eZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm3 header.b=g8C+NgNu; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=ksdUKZT1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w20si16980231edc.462.2021.07.07.02.53.08; Wed, 07 Jul 2021 02:53:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm3 header.b=g8C+NgNu; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=ksdUKZT1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231355AbhGGJyK (ORCPT + 99 others); Wed, 7 Jul 2021 05:54:10 -0400 Received: from wnew2-smtp.messagingengine.com ([64.147.123.27]:48731 "EHLO wnew2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231173AbhGGJyH (ORCPT ); Wed, 7 Jul 2021 05:54:07 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailnew.west.internal (Postfix) with ESMTP id 8A5B02B007A1; Wed, 7 Jul 2021 05:51:26 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 07 Jul 2021 05:51:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=AP/I8rxrmE9Ml RDmDxJIy4tqdiKllNYXAEVIGV9L3GI=; b=g8C+NgNuTUqc8w4R12gc57tLUAN8A H90sc6rEChB5iWGD1xPpTKRa7Jsga+lA1erKdI/pSzanlpQtgH7KlXqHbLKuxewy R4l8Qzuw9VGPnHm7C2cOC2FVCuudKNWy08NWGDUAODJ+bKvrn8u78kK2IOUds2tt CAZBLwGT+3yL+tNydQLRs+a0cvIgnkpJa/WrHs/ZPL8jPBQpOv9sRMsTlUQeEDuA yxtTGnFeOicgLRihcJJ/Cify411XF1BWjeTC+k3qb/JFifYh+UAm6ASNNUSaAKTG NUlqZ5lDqcVoanOULZWHbXC0mLs4tVk8JZOuVGS4GdNqnmUG+7BExnnlg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=AP/I8rxrmE9MlRDmDxJIy4tqdiKllNYXAEVIGV9L3GI=; b=ksdUKZT1 gCC2cs1svaMtcvWYJV8ZfB1bcjwqAtY4Hpqq0mW3ZReppRbnA0jj0gQkt3L8GaKy 3rZZoM8Si6iKSVwUnBe6qFucNzCiEJYvQZk79m7eVgd/XLaXVqcQs9qdN9mhLPr0 RKcTUhuJp6mIiTH0skZ9Wjgrr/zzdqtI8fIjvuh523xxvfB+K1eAjzA/cGIM09l/ D6HNfGVugXJGCqKacF9HE7jA16k+m0qlSB1lWlqZ+0WdZk+hUUCiGNtsowwbP3lP HLM+x2XgIZa2C/4xMWWMpxXBVUPVDyCdiKEZBFuxYz6hhq6dy0kPY6TIF+ri+e5c RlRDJyjsyrm3XA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrtddvgddvtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepofgrgihimhgv ucftihhprghrugcuoehmrgigihhmvgestggvrhhnohdrthgvtghhqeenucggtffrrghtth gvrhhnpedvkeelveefffekjefhffeuleetleefudeifeehuddugffghffhffehveevheeh vdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmrg igihhmvgestggvrhhnohdrthgvtghh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 7 Jul 2021 05:51:25 -0400 (EDT) From: Maxime Ripard To: dri-devel@lists.freedesktop.org, Daniel Vetter , David Airlie , Maarten Lankhorst , Thomas Zimmermann , Maxime Ripard Cc: Emma Anholt , Hans Verkuil , Daniel Vetter , linux-kernel@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, bcm-kernel-feedback-list@broadcom.com, Dave Stevenson , Phil Elwell , Tim Gover , Dom Cobley , Maxime Ripard , Nicolas Saenz Julienne Subject: [PATCH 2/3] drm/vc4: hdmi: Drop devm interrupt handler for hotplug interrupts Date: Wed, 7 Jul 2021 11:51:11 +0200 Message-Id: <20210707095112.1469670-3-maxime@cerno.tech> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210707095112.1469670-1-maxime@cerno.tech> References: <20210707095112.1469670-1-maxime@cerno.tech> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The hotplugs interrupt handlers are registered through the devm_request_threaded_irq function. However, while free_irq is indeed called properly when the device is unbound or bind fails, it's called after unbind or bind is done. In our particular case, it means that on failure it creates a window where our interrupt handler can be called, but we're freeing every resource (CEC adapter, DRM objects, etc.) it might need. In order to address this, let's switch to the non-devm variant to control better when the handler will be unregistered and allow us to make it safe. Fixes: f4790083c7c2 ("drm/vc4: hdmi: Rely on interrupts to handle hotplug") Signed-off-by: Maxime Ripard --- drivers/gpu/drm/vc4/vc4_hdmi.c | 41 +++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index d966f61966c6..50393a8a42b3 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -1590,25 +1590,27 @@ static int vc4_hdmi_hotplug_init(struct vc4_hdmi *vc4_hdmi) { struct drm_connector *connector = &vc4_hdmi->connector; struct platform_device *pdev = vc4_hdmi->pdev; - struct device *dev = &pdev->dev; int ret; if (vc4_hdmi->variant->external_irq_controller) { - ret = devm_request_threaded_irq(dev, - platform_get_irq_byname(pdev, "hpd-connected"), - NULL, - vc4_hdmi_hpd_irq_thread, IRQF_ONESHOT, - "vc4 hdmi hpd connected", vc4_hdmi); + unsigned int hpd_con = platform_get_irq_byname(pdev, "hpd-connected"); + unsigned int hpd_rm = platform_get_irq_byname(pdev, "hpd-removed"); + + ret = request_threaded_irq(hpd_con, + NULL, + vc4_hdmi_hpd_irq_thread, IRQF_ONESHOT, + "vc4 hdmi hpd connected", vc4_hdmi); if (ret) return ret; - ret = devm_request_threaded_irq(dev, - platform_get_irq_byname(pdev, "hpd-removed"), - NULL, - vc4_hdmi_hpd_irq_thread, IRQF_ONESHOT, - "vc4 hdmi hpd disconnected", vc4_hdmi); - if (ret) + ret = request_threaded_irq(hpd_rm, + NULL, + vc4_hdmi_hpd_irq_thread, IRQF_ONESHOT, + "vc4 hdmi hpd disconnected", vc4_hdmi); + if (ret) { + free_irq(hpd_con, vc4_hdmi); return ret; + } connector->polled = DRM_CONNECTOR_POLL_HPD; } @@ -1616,6 +1618,16 @@ static int vc4_hdmi_hotplug_init(struct vc4_hdmi *vc4_hdmi) return 0; } +static void vc4_hdmi_hotplug_exit(struct vc4_hdmi *vc4_hdmi) +{ + struct platform_device *pdev = vc4_hdmi->pdev; + + if (vc4_hdmi->variant->external_irq_controller) { + free_irq(platform_get_irq_byname(pdev, "hpd-connected"), vc4_hdmi); + free_irq(platform_get_irq_byname(pdev, "hpd-removed"), vc4_hdmi); + } +} + #ifdef CONFIG_DRM_VC4_HDMI_CEC static irqreturn_t vc4_cec_irq_handler_rx_thread(int irq, void *priv) { @@ -2197,7 +2209,7 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data) ret = vc4_hdmi_cec_init(vc4_hdmi); if (ret) - goto err_destroy_conn; + goto err_free_hotplug; ret = vc4_hdmi_audio_init(vc4_hdmi); if (ret) @@ -2211,6 +2223,8 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data) err_free_cec: vc4_hdmi_cec_exit(vc4_hdmi); +err_free_hotplug: + vc4_hdmi_hotplug_exit(vc4_hdmi); err_destroy_conn: vc4_hdmi_connector_destroy(&vc4_hdmi->connector); err_destroy_encoder: @@ -2252,6 +2266,7 @@ static void vc4_hdmi_unbind(struct device *dev, struct device *master, kfree(vc4_hdmi->hd_regset.regs); vc4_hdmi_cec_exit(vc4_hdmi); + vc4_hdmi_hotplug_exit(vc4_hdmi); vc4_hdmi_connector_destroy(&vc4_hdmi->connector); drm_encoder_cleanup(&vc4_hdmi->encoder.base.base); -- 2.31.1