From patchwork Thu Sep 1 12:48:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 9309017 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 AF56A60756 for ; Thu, 1 Sep 2016 12:49:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA95229382 for ; Thu, 1 Sep 2016 12:49:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F9F329388; Thu, 1 Sep 2016 12:49:03 +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 538FC29382 for ; Thu, 1 Sep 2016 12:49:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8BA9F6E93B; Thu, 1 Sep 2016 12:49:02 +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 48AD36E93B for ; Thu, 1 Sep 2016 12:49:00 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id w207so8277106wmw.0 for ; Thu, 01 Sep 2016 05:49:00 -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=g4m+B5See4X6MUT5K0ZLGpSQxmQtfcpGAvHg92aYSeQ=; b=XsRhHyh/GArgmk8GQCUDN/T6sC/8bDEiihfR/62FZkqwgo0LGHeOlP/EudfaJcBWFw e4BFP8CaMy1zGRNDptiTxV1JuQNwOdWGbX+G05xpJzS46WbAF3kQonDBtv6wT1LovgIP C8yVsunY0jZ7uE3c28tN6eKy12ftoZUUG/xcijnRDpgbiUahjLELA8HGeNkH2+yGNYjL y7xpt55e0IC/OVlj+jFLe8jyBihp3Y/QDIHK9qbN9hBt5PbfbMV2NK+ZtbTZfwaCMDDa ibbYqByYcxo0nBV19lUH9t2ttKwwLxwFO15xepSgIGLtOMTgW8IlDH8qDrNZZjUW6KJA YVcA== 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:in-reply-to :references; bh=g4m+B5See4X6MUT5K0ZLGpSQxmQtfcpGAvHg92aYSeQ=; b=f6KI/+UHwYezWLzA2oLWa15VLEUb6LKYR+KiF5cfYCZFONbh2PAufaFRF3JI0WWwzp uzjO7UH71QN7FmQ6+6FeeQcLlnJct/oFRkasCrkeX32EquWoz3dW30+iwKC5QRwrXwgK EVjy9JlOEHXl01eSH8OaaejFVrZaDP6dJ7FsWdU9cDJIMmA8UT15sK+qMAzi4YxsxHsk t5apGu/Mr4dMjjO+nKllaGPdgwITCk6DYWHFKmHij37eLznJQL1LjwCs5fELNxW+JNYr yP3Nin1sJ4EJoXl7uxOEX1eKbRRXwNXjDH+tNdgXEKVA/lEIkVYvuDawvguXodCfyDzD XRmA== X-Gm-Message-State: AE9vXwMW2xLKWBqUkK/NWvTSBSJp6aigeUrPbIoWfGDechuy5+nYcCF6Gt9kjkD2WodpMg== X-Received: by 10.194.61.164 with SMTP id q4mr8349149wjr.89.1472734138606; Thu, 01 Sep 2016 05:48:58 -0700 (PDT) Received: from localhost.localdomain ([37.120.86.93]) by smtp.gmail.com with ESMTPSA id i8sm14287786wmg.21.2016.09.01.05.48.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Sep 2016 05:48:57 -0700 (PDT) From: David Herrmann To: dri-devel@lists.freedesktop.org Subject: [PATCH 6/6] drm: cleanup drm_core_{init,exit}() Date: Thu, 1 Sep 2016 14:48:37 +0200 Message-Id: <20160901124837.680-7-dh.herrmann@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160901124837.680-1-dh.herrmann@gmail.com> References: <20160901124837.680-1-dh.herrmann@gmail.com> 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 --- 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);