From patchwork Mon Feb 19 20:06:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jyri Sarha X-Patchwork-Id: 10228811 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4E638602B7 for ; Mon, 19 Feb 2018 20:06:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E5B828B3E for ; Mon, 19 Feb 2018 20:06:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32AC728B81; Mon, 19 Feb 2018 20:06:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7908528B3E for ; Mon, 19 Feb 2018 20:06:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C6E606E313; Mon, 19 Feb 2018 20:06:40 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from fllnx209.ext.ti.com (fllnx209.ext.ti.com [198.47.19.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7D3356E313 for ; Mon, 19 Feb 2018 20:06:39 +0000 (UTC) Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by fllnx209.ext.ti.com (8.15.1/8.15.1) with ESMTP id w1JK6VBF010897; Mon, 19 Feb 2018 14:06:31 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1519070791; bh=EHaGEPYqfJUikSx8rIvhb3etIGi26OLUjXhWxzoCHwk=; h=From:To:CC:Subject:Date; b=rlR3OhRU7kpgeVdEuTTWhKHuP+w9OP5CUy/Y8AVJPfYpGwGmTsS2nTVPT/7o7pk/x cs2NhX+VcIAgJTQTMSAZVMzCs5XCXYkoOo/jyKsteyEJkVMMyQmK1LqQTAHpf8OwHo agm3lhZAqexxvsnkAJgM/SIlslqKbSd0RSQ/ZLRw= Received: from DFLE104.ent.ti.com (dfle104.ent.ti.com [10.64.6.25]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id w1JK6VgY029075; Mon, 19 Feb 2018 14:06:31 -0600 Received: from DFLE100.ent.ti.com (10.64.6.21) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.35; Mon, 19 Feb 2018 14:06:30 -0600 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE100.ent.ti.com (10.64.6.21) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1261.35 via Frontend Transport; Mon, 19 Feb 2018 14:06:30 -0600 Received: from jadmar.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w1JK6Sx3029087; Mon, 19 Feb 2018 14:06:29 -0600 From: Jyri Sarha To: Subject: [PATCH RFC] drm/bridge: panel: Add module_get/but calls to attached panel driver Date: Mon, 19 Feb 2018 22:06:22 +0200 Message-ID: <1519070782-20834-1-git-send-email-jsarha@ti.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: airlied@linux.ie, Jyri Sarha , tomi.valkeinen@ti.com, laurent.pinchart@ideasonboard.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Currently there is no way for a master drm driver to protect against an attached panel driver from being unloaded while it is in use. The least we can do is to indicate the usage by incrementing the module reference count. Signed-off-by: Jyri Sarha cc: eric@anholt.net cc: laurent.pinchart@ideasonboard.com --- I do not see any module_get/put code in drm core. Is there is a reason for that? There is two more alternative places for adding the module_get/put code. One is puting it directly to drm_panel_attach() and drm_panel_detach(). However, if the same module implements both the master drm driver and the panel (like tilcdc does with its tilcdc_panel.c), then attaching the panel will lock the module in for no good reason. Still, this solution should work with drm bridges as I do not see any reason why anybody would implement bridge drivers in the same module with the master drm driver. The other place to put the code would in the master drm driver. But for handling the situation with bridges would need the device pointer in struct drm_bridge. drivers/gpu/drm/bridge/panel.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/gpu/drm/bridge/panel.c b/drivers/gpu/drm/bridge/panel.c index 6d99d4a..0a10be6 100644 --- a/drivers/gpu/drm/bridge/panel.c +++ b/drivers/gpu/drm/bridge/panel.c @@ -161,6 +161,10 @@ struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel, if (!panel) return ERR_PTR(-EINVAL); + if (WARN_ON(!panel->dev->driver) || + !try_module_get(panel->dev->driver->owner)) + return ERR_PTR(-ENODEV); + panel_bridge = devm_kzalloc(panel->dev, sizeof(*panel_bridge), GFP_KERNEL); if (!panel_bridge) @@ -199,6 +203,9 @@ void drm_panel_bridge_remove(struct drm_bridge *bridge) panel_bridge = drm_bridge_to_panel_bridge(bridge); drm_bridge_remove(bridge); + + module_put(panel_bridge->panel->dev->driver->owner); + devm_kfree(panel_bridge->panel->dev, bridge); } EXPORT_SYMBOL(drm_panel_bridge_remove);