From patchwork Tue Nov 29 21:12:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jyri Sarha X-Patchwork-Id: 9453129 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 28BD860710 for ; Tue, 29 Nov 2016 21:13:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19F1B28365 for ; Tue, 29 Nov 2016 21:13:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0ED552838D; Tue, 29 Nov 2016 21:13:13 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 3F0C128365 for ; Tue, 29 Nov 2016 21:13:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7FEA56E767; Tue, 29 Nov 2016 21:13:07 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from fllnx210.ext.ti.com (fllnx210.ext.ti.com [198.47.19.17]) by gabe.freedesktop.org (Postfix) with ESMTPS id 355AE6E767 for ; Tue, 29 Nov 2016 21:13:06 +0000 (UTC) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllnx210.ext.ti.com (8.15.1/8.15.1) with ESMTP id uATLD2wI003978; Tue, 29 Nov 2016 15:13:02 -0600 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id uATLD2ZP014459; Tue, 29 Nov 2016 15:13:02 -0600 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.294.0; Tue, 29 Nov 2016 15:13:01 -0600 Received: from jadmar.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id uATLCxsE030788; Tue, 29 Nov 2016 15:13:00 -0600 From: Jyri Sarha To: Subject: [PATCH] drm/drm_bridge: adjust bridge module's refcount Date: Tue, 29 Nov 2016 23:12:56 +0200 Message-ID: <1480453976-26303-1-git-send-email-jsarha@ti.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Cc: Jyri Sarha , tomi.valkeinen@ti.com, laurent.pinchart@ideasonboard.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Store the module that provides the bridge and adjust its refcount accordingly. The bridge module unload should not be allowed while the bridge is attached. Signed-off-by: Jyri Sarha --- drivers/gpu/drm/drm_bridge.c | 15 ++++++++++++--- include/drm/drm_bridge.h | 11 ++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index 0ee052b..36d427b 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -61,22 +61,26 @@ static LIST_HEAD(bridge_list); /** - * drm_bridge_add - add the given bridge to the global bridge list + * __drm_bridge_add - add the given bridge to the global bridge list * * @bridge: bridge control structure + * @module: module that provides this bridge * * RETURNS: * Unconditionally returns Zero. */ -int drm_bridge_add(struct drm_bridge *bridge) +int __drm_bridge_add(struct drm_bridge *bridge, struct module *module) { +#ifdef MODULE + bridge->module = module; +#endif mutex_lock(&bridge_lock); list_add_tail(&bridge->list, &bridge_list); mutex_unlock(&bridge_lock); return 0; } -EXPORT_SYMBOL(drm_bridge_add); +EXPORT_SYMBOL(__drm_bridge_add); /** * drm_bridge_remove - remove the given bridge from the global bridge list @@ -114,6 +118,9 @@ int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge) if (bridge->dev) return -EBUSY; + if (!try_module_get(bridge->module)) + return -ENOENT; + bridge->dev = dev; if (bridge->funcs->attach) @@ -144,6 +151,8 @@ void drm_bridge_detach(struct drm_bridge *bridge) if (bridge->funcs->detach) bridge->funcs->detach(bridge); + module_put(bridge->module); + bridge->dev = NULL; } EXPORT_SYMBOL(drm_bridge_detach); diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h index 530a1d6..d60d5d2 100644 --- a/include/drm/drm_bridge.h +++ b/include/drm/drm_bridge.h @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -192,13 +193,21 @@ struct drm_bridge { #ifdef CONFIG_OF struct device_node *of_node; #endif +#ifdef MODULE + struct module *module; +#endif struct list_head list; const struct drm_bridge_funcs *funcs; void *driver_private; }; -int drm_bridge_add(struct drm_bridge *bridge); +int __drm_bridge_add(struct drm_bridge *bridge, struct module *module); +#ifdef MODULE +#define drm_bridge_add(bridge) __drm_bridge_add(bridge, THIS_MODULE) +#else +#define drm_bridge_add(bridge) __drm_bridge_add(bridge, NULL) +#endif void drm_bridge_remove(struct drm_bridge *bridge); struct drm_bridge *of_drm_find_bridge(struct device_node *np); int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);