From patchwork Wed Sep 9 12:21:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 7146151 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 265D79F380 for ; Wed, 9 Sep 2015 12:22:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4B3A420965 for ; Wed, 9 Sep 2015 12:22:06 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id F3A082097C for ; Wed, 9 Sep 2015 12:22:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2CA566E0CE; Wed, 9 Sep 2015 05:22:00 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com [209.85.212.182]) by gabe.freedesktop.org (Postfix) with ESMTPS id 35CED6E0AE for ; Wed, 9 Sep 2015 05:21:58 -0700 (PDT) Received: by wicfx3 with SMTP id fx3so154708487wic.1 for ; Wed, 09 Sep 2015 05:21:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=irF7kmj1TxtWgdkIL9Xt0H7WD+3OAJAQM/TChyCQ04Y=; b=ZEJvhLFqAHlrkrq8UpdnOAUlgTcZ3uSB+tc48XJu9yCCces8mvkh3YivvsHlij0Un3 rT9I7MdDuYkVtPinqhO1Ep6nhIl5jWIShcTCUjokP1MGswP7/UN/tzQ08ePsmvZQ/mf+ PAENx04i0a8iep9cOBXiHQoy7hXnMRlg/tfE6RVcmw2hB4uRESwIzAQcgLc2lJmA/w+r NMRDoIrIbAotxoMN8qRaKu3RoMWQCQcLwUblbtbtv2JcXc9cGB8u4COpMduwY+raPRBZ sLawBlIGZ53Jb3izRdFYF0Dvgx1U2rPaBCIxqLQIt4FCfGo4yaA+0zeB17M1v7yWwB28 kWrg== X-Received: by 10.180.101.164 with SMTP id fh4mr56425133wib.25.1441801316643; Wed, 09 Sep 2015 05:21:56 -0700 (PDT) Received: from david-t2.fritz.box (p5DDC7D72.dip0.t-ipconnect.de. [93.220.125.114]) by smtp.gmail.com with ESMTPSA id fu5sm6380823wic.0.2015.09.09.05.21.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Sep 2015 05:21:55 -0700 (PDT) From: David Herrmann To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/5] drm: cleanup drm_core_{init,exit}() Date: Wed, 9 Sep 2015 14:21:31 +0200 Message-Id: <1441801293-1440-4-git-send-email-dh.herrmann@gmail.com> X-Mailer: git-send-email 2.5.1 In-Reply-To: <1441801293-1440-1-git-send-email-dh.herrmann@gmail.com> References: <1441801293-1440-1-git-send-email-dh.herrmann@gmail.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: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Various cleanups to the DRM core initialization and exit handlers: - Register chrdev last: Once register_chrdev() returns, open() will succeed on the given chrdevs. This is usually not an issue, as no chardevs are registered, yet. However, nodes can be created by user-space via mknod(2), even though such major/minor combinations are unknown to the kernel. Avoid calling into drm_stub_open() in those cases. Again, drm_stub_open() would just bail out as the inode is unknown, but it's really non-obvious if you hack on drm_stub_open(). - Unify error-paths into just one label. All the error-path helpers can be called even though the constructors were not called yet, or failed. Hence, just call all cleanups unconditionally. - Call into drm_global_release(). This is a no-op, but provides debugging helpers in case there're GLOBALS left on module unload. This function was unused until now. - Use DRM_ERROR() instead of printk(), and also print the error-code on failure (even if it is static!). - Don't throw away error-codes of register_chrdev()! - Don't hardcode -1 as errno. This is just plain wrong. - Order exit-handlers in the exact reverse order of initialization (except if the order actually matters for syncing-reasons, which is not the case here, though). Signed-off-by: David Herrmann --- drivers/gpu/drm/drm_drv.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 58299f7..bf2924b 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -829,50 +829,50 @@ static const struct file_operations drm_stub_fops = { static int __init drm_core_init(void) { - int ret = -ENOMEM; + int ret; drm_global_init(); drm_connector_ida_init(); idr_init(&drm_minors_idr); - if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops)) - goto err_p1; - ret = drm_sysfs_init(); if (ret < 0) { - printk(KERN_ERR "DRM: Error creating drm class.\n"); - goto err_p2; + DRM_ERROR("Cannot create DRM class: %d\n", ret); + goto error; } drm_debugfs_root = debugfs_create_dir("dri", NULL); if (!drm_debugfs_root) { - DRM_ERROR("Cannot create /sys/kernel/debug/dri\n"); - ret = -1; - goto err_p3; + ret = -ENOMEM; + DRM_ERROR("Cannot create debugfs-root: %d\n", ret); + goto error; } + ret = register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops); + if (ret < 0) + goto error; + DRM_INFO("Initialized %s %d.%d.%d %s\n", CORE_NAME, CORE_MAJOR, CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE); return 0; -err_p3: - drm_sysfs_destroy(); -err_p2: - unregister_chrdev(DRM_MAJOR, "drm"); +error: + debugfs_remove(drm_debugfs_root); + drm_sysfs_destroy(); idr_destroy(&drm_minors_idr); -err_p1: + drm_connector_ida_destroy(); + drm_global_release(); return ret; } static void __exit drm_core_exit(void) { + unregister_chrdev(DRM_MAJOR, "drm"); debugfs_remove(drm_debugfs_root); drm_sysfs_destroy(); - - unregister_chrdev(DRM_MAJOR, "drm"); - - drm_connector_ida_destroy(); idr_destroy(&drm_minors_idr); + drm_connector_ida_destroy(); + drm_global_release(); } module_init(drm_core_init);