From patchwork Mon May 30 08:38:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9140427 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 D850C60759 for ; Mon, 30 May 2016 08:38:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDB6E28066 for ; Mon, 30 May 2016 08:38:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C23252821C; Mon, 30 May 2016 08:38:58 +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]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D69E128066 for ; Mon, 30 May 2016 08:38:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4E1E16E6C5; Mon, 30 May 2016 08:38:55 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3091D6E6C3; Mon, 30 May 2016 08:38:53 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id a136so20366090wme.0; Mon, 30 May 2016 01:38:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=vVHoMMoJ7kQQnEe1UHt9X2xyPLJcoRSIIZ3KgI71Uvg=; b=GKYLwpOGAfbBsIaH+7mUFmUYy6jFSuIx8rw3zO+OeQxe8y/4ECEkIFoRBmuFso1bQW lOUrb7WbjERTZ5gP3kqn1TxF2ElJjPEAc57L9u8+GDM0vdDZjuTZTWilwNJluwJG/CoT NI+3WShNhsB8f/T3VdNQrGQkcaS7SGVrOcsgLRnjYpY/Ck1/srAopLPd7CBjFq6Ah5wH IUqEFXGld86Q58TZRx55RLzQSpnAHolFPb0tqc0J0CkEQvdXR/cjzLHktabownv2PQwF nlWQ5UQdrfTMsfT/0HMn7M1jylXdxv450nLDWlYXP65EkSdKm94J4ymz5fLtj73waQLT y3hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=vVHoMMoJ7kQQnEe1UHt9X2xyPLJcoRSIIZ3KgI71Uvg=; b=UKFYPIecpHHZXzcJl3wJJdkg+FdbZebNt5N6W8zyo0KdMK4dIurDzZHLCjXLKbNIaw LcWqKVbMTkPQPz8qM7GV/MOc+1dR9oK67ZfbZlRiCkna/HzBsDDOC6bcNYVGxg29zYuF jTzTKwFwSCQDd1FXPBqm+3L5FttGEK01LheRned7zKuAOuh+nupw9rq21QKXr4i7o1Rq 9cEQeaV/a26sPM4RL5u4HO/z+VEj9bVcru3cNVAvlVDv6hZ0IKiJltCVQJGvG2WRSsAa pCgs1ulzE09dCT/vQmCpLcTP4Vik/Gw88iWCigdTB1oWbjt8m5X9r3YRapIonqcAQejY nahg== X-Gm-Message-State: ALyK8tIco8eNoSVx6ArlR3ub+x8IwJ8oxxy+xvoqsx8EqUJFRdO+sHZvpE1ft8a7EURwYg== X-Received: by 10.28.158.8 with SMTP id h8mr10541425wme.1.1464597531398; Mon, 30 May 2016 01:38:51 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id l9sm6945376wjm.0.2016.05.30.01.38.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 May 2016 01:38:50 -0700 (PDT) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Mon, 30 May 2016 09:38:19 +0100 Message-Id: <1464597519-16659-2-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1464597519-16659-1-git-send-email-chris@chris-wilson.co.uk> References: <1464597519-16659-1-git-send-email-chris@chris-wilson.co.uk> Cc: Daniel Vetter , dri-devel@lists.freedesktop.org Subject: [Intel-gfx] [PATCH v2 01/21] drm: Export drm_dev_init() for subclassing X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP In order to allow drivers to pack their privates and drm_device into one struct (e.g. for subclassing), export the initialisation routines for struct drm_device. v2: Missed return ret. That error path had only one job to do! Signed-off-by: Chris Wilson Cc: Daniel Vetter Cc: dri-devel@lists.freedesktop.org Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_drv.c | 63 ++++++++++++++++++++++++++++++++++++----------- include/drm/drmP.h | 3 +++ 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index bff89226a344..f0553ccd4f71 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -549,11 +549,12 @@ static void drm_fs_inode_free(struct inode *inode) } /** - * drm_dev_alloc - Allocate new DRM device - * @driver: DRM driver to allocate device for + * drm_dev_init - Initialise new DRM device + * @dev: DRM device + * @driver: DRM driver * @parent: Parent device object * - * Allocate and initialize a new DRM device. No device registration is done. + * Initialize a new DRM device. No device registration is done. * Call drm_dev_register() to advertice the device to user space and register it * with other core subsystems. This should be done last in the device * initialization sequence to make sure userspace can't access an inconsistent @@ -565,18 +566,14 @@ static void drm_fs_inode_free(struct inode *inode) * Note that for purely virtual devices @parent can be NULL. * * RETURNS: - * Pointer to new DRM device, or NULL if out of memory. + * 0 on success, or error code on failure. */ -struct drm_device *drm_dev_alloc(struct drm_driver *driver, - struct device *parent) +int drm_dev_init(struct drm_device *dev, + struct drm_driver *driver, + struct device *parent) { - struct drm_device *dev; int ret; - dev = kzalloc(sizeof(*dev), GFP_KERNEL); - if (!dev) - return NULL; - kref_init(&dev->ref); dev->dev = parent; dev->driver = driver; @@ -638,7 +635,7 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver, goto err_setunique; } - return dev; + return 0; err_setunique: if (drm_core_check_feature(dev, DRIVER_GEM)) @@ -653,8 +650,46 @@ err_minors: drm_fs_inode_free(dev->anon_inode); err_free: mutex_destroy(&dev->master_mutex); - kfree(dev); - return NULL; + return ret; +} +EXPORT_SYMBOL(drm_dev_init); + +/** + * drm_dev_alloc - Allocate new DRM device + * @driver: DRM driver to allocate device for + * @parent: Parent device object + * + * Allocate and initialize a new DRM device. No device registration is done. + * Call drm_dev_register() to advertice the device to user space and register it + * with other core subsystems. This should be done last in the device + * initialization sequence to make sure userspace can't access an inconsistent + * state. + * + * The initial ref-count of the object is 1. Use drm_dev_ref() and + * drm_dev_unref() to take and drop further ref-counts. + * + * Note that for purely virtual devices @parent can be NULL. + * + * RETURNS: + * Pointer to new DRM device, or NULL if out of memory. + */ +struct drm_device *drm_dev_alloc(struct drm_driver *driver, + struct device *parent) +{ + struct drm_device *dev; + int ret; + + dev = kzalloc(sizeof(*dev), GFP_KERNEL); + if (!dev) + return NULL; + + ret = drm_dev_init(dev, driver, parent); + if (ret) { + kfree(dev); + return NULL; + } + + return dev; } EXPORT_SYMBOL(drm_dev_alloc); diff --git a/include/drm/drmP.h b/include/drm/drmP.h index c5d29505f937..12dc5f9cad89 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -1075,6 +1075,9 @@ extern void drm_sysfs_hotplug_event(struct drm_device *dev); struct drm_device *drm_dev_alloc(struct drm_driver *driver, struct device *parent); +int drm_dev_init(struct drm_device *dev, + struct drm_driver *driver, + struct device *parent); void drm_dev_ref(struct drm_device *dev); void drm_dev_unref(struct drm_device *dev); int drm_dev_register(struct drm_device *dev, unsigned long flags);