From patchwork Thu Aug 25 19:15:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 9299681 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 05ECC60757 for ; Thu, 25 Aug 2016 19:16:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC2862918C for ; Thu, 25 Aug 2016 19:16:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E0EA529224; Thu, 25 Aug 2016 19:16:05 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 7FF4F2918C for ; Thu, 25 Aug 2016 19:16:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8F9366E10D; Thu, 25 Aug 2016 19:16:03 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id AB8C16E10D for ; Thu, 25 Aug 2016 19:16:02 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id i138so8571394wmf.3 for ; Thu, 25 Aug 2016 12:16:02 -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; bh=+bLB7Sf+o6XKCaehWNFXWodwGfSUChribOVghpmwgdI=; b=YGBpccuVLNfg4Ukbr4TJxP7bNejWaFQ25Ukd1meQt8f3w3vvknc2kSPNriHWdajHRT rekCQbToXVQqlxWk5ryxEVM4FLHtRj2N9Arz9JdyOjyltNRURBcpIB9hUQeu3+2o8vN4 6N/u8lusZgHHWZ3CYHdRsM8SOcqDy3CLV642mDWEfqH1CC7u+qCX8+vnoCs4FDjFzOVi e59HmK4nxJQjDh6wyYeRlrnex4cDTDf56snj8vDinBxroQQK++HidXpX72R6UKRvalpK YcZ6rjWiNrIJ5NH3uqwhBqKZOn5Q39710HObBkhrHrlQY7g+XZVqZIPtor2Gl4ApI7iM jsTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=+bLB7Sf+o6XKCaehWNFXWodwGfSUChribOVghpmwgdI=; b=V1UBFSxLX3aBMZIcmAIW8yrltHHw+YE4DHflnDBUxgig677kd3wgZuvh880qNU4XG9 iIc90sZhkkUL4TkY8nRjQQBWRpwt2a+UnryhiZfC0Rq7kYVKxT5VcQ2HmDMgFG5pMkcc whD7UkAGZqLW6KcwptoaJTnBbt1e/FbcdMspULHFEci2/1hf0gR7YTHplthmLAvjqKEL MZ5Oym78UUEvD9v5JAn/0MXzf2JLluXPvB5Ks4n3GkuvP2chBVXXBKGE7RLx2E1A9bZN pLCReJcd2nQykomhjoUqw5T7EmO8t0zEoaFqCxruku1tZBMJIvmbIen6A+XtTVu3qJdF eseQ== X-Gm-Message-State: AE9vXwMg8ABhUGUBBBD4S8GLOUYfn024/dUzt8hO7RTmEX05VWWS241fg7ebNgo9D+Fwhw== X-Received: by 10.28.97.2 with SMTP id v2mr9193125wmb.31.1472152561097; Thu, 25 Aug 2016 12:16:01 -0700 (PDT) Received: from localhost.localdomain ([37.120.99.16]) by smtp.gmail.com with ESMTPSA id 17sm17113527wmf.6.2016.08.25.12.15.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Aug 2016 12:16:00 -0700 (PDT) From: David Herrmann To: dri-devel@lists.freedesktop.org Subject: [PATCH v2] drm: cleanup drm_core_{init,exit}() Date: Thu, 25 Aug 2016 21:15:50 +0200 Message-Id: <20160825191550.19832-1-dh.herrmann@gmail.com> X-Mailer: git-send-email 2.9.3 Cc: Daniel Vetter 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-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). v2: - Call drm_core_exit() directly from the init-error-handler. Requires to drop __exit annotation, though. Signed-off-by: David Herrmann --- Hey This is based on top of "[PATCH] drm: drop obsolete drm_core.h" Should be trivial to rebase, though. Just a DRM_ERROR()-message conflict. Thanks David drivers/gpu/drm/drm_drv.c | 48 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index d771453..0773547 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -941,52 +941,48 @@ static const struct file_operations drm_stub_fops = { .llseek = noop_llseek, }; +static void drm_core_exit(void) +{ + unregister_chrdev(DRM_MAJOR, "drm"); + debugfs_remove(drm_debugfs_root); + drm_sysfs_destroy(); + idr_destroy(&drm_minors_idr); + drm_connector_ida_destroy(); + drm_global_release(); +} + 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\n"); return 0; -err_p3: - drm_sysfs_destroy(); -err_p2: - unregister_chrdev(DRM_MAJOR, "drm"); - idr_destroy(&drm_minors_idr); -err_p1: +error: + drm_core_exit(); return ret; } -static void __exit drm_core_exit(void) -{ - debugfs_remove(drm_debugfs_root); - drm_sysfs_destroy(); - - unregister_chrdev(DRM_MAJOR, "drm"); - - drm_connector_ida_destroy(); - idr_destroy(&drm_minors_idr); -} - module_init(drm_core_init); module_exit(drm_core_exit);