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: 128845 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp3889256ljc; Mon, 19 Feb 2018 12:06:43 -0800 (PST) X-Google-Smtp-Source: AH8x227+vzerAfrd1qcjToD0Wa5TiDb5g5uWUD0VwpncwTuUxDfW4aOIycR9aM7Lg+0TPP9ibFe+ X-Received: by 10.101.97.139 with SMTP id c11mr3603458pgv.447.1519070803118; Mon, 19 Feb 2018 12:06:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519070803; cv=none; d=google.com; s=arc-20160816; b=p0Rej0g1bokI1yQ+vKrzaNCk0OdkMcS670T/PQ9UxMQ02aZhkkWzlZnaNZ/AlpMRJB YVi1m6oZ9VEo30JWk6rAyFgpXMn+epCnnEkGOoulc8Kos4Jod8mu//Rnwrl+WTXW5SG5 JlkGhEXWgT+qtt7VwVT5O9qcTvm/O+33AJ8E/e4UrmGfGIkp0Jsm57Unws4awOocJZWZ njr3iTtAily+GFyfBClYW4PM2+g9OlXZLKqqYU1axSWVC7cUZdJfNQI/1WEl9iDUGoF8 hFSN5Mi3rRRLUGEwXP0h20gJn/Sja2VIbJHFln/MYGyul/tlljIBlK/Es3A0i2Mt+f+D GIeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:message-id:date:subject:to:from :dkim-signature:delivered-to:arc-authentication-results; bh=Rh8rAwzioWxg+daTdC6waEKZaaE+hPK8hbpXEsaMUyw=; b=Zw3VImZJcg1G85OGodzXHfBxzGLx6s2QvOGPb2ErlDBm+5fOdYloT9imzMMtscL5w9 mX3BjxtPemidSZZHy7F6iL2nitWB5vxVJGPJWUQnCBRL6IIraLNv/NVXO9hyXMjC59oQ s0u3zFDSIGdc4rurquSFQaQAu2IX+S4kZtKQoSRkRrRP97SXKzDxdgYIAXEVd2kDBj1r cMgzFuYBKqMImhQ6j0i8hQVmeH4QbdT6IikK3vIbVgYwFNve4AcKchPgbTocu0JQw+nN JnsDaGfLilt0Zd35OYcafGKmw707VtKOFSb+/MNAk9zFk+8xpl3HBfVKCuogz2SCAOfg 0XIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@ti.com header.s=ti-com-17Q1 header.b=rlR3OhRU; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id d21-v6si5929093pll.268.2018.02.19.12.06.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Feb 2018 12:06:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@ti.com header.s=ti-com-17Q1 header.b=rlR3OhRU; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com 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" 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 Reported-by: Jyri Sarha Signed-off-by: Lukas Wunner --- 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);