From patchwork Wed Sep 9 12:21:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 7146111 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B76D9BEEC1 for ; Wed, 9 Sep 2015 12:22:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8FBAC20972 for ; Wed, 9 Sep 2015 12:22:00 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 8CD0420965 for ; Wed, 9 Sep 2015 12:21:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C46576E0AE; Wed, 9 Sep 2015 05:21:58 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com [209.85.212.172]) by gabe.freedesktop.org (Postfix) with ESMTPS id B1C656E0AE for ; Wed, 9 Sep 2015 05:21:56 -0700 (PDT) Received: by wicgb1 with SMTP id gb1so114182582wic.1 for ; Wed, 09 Sep 2015 05:21:55 -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=Kg+l9UFlYBGSgtzNF0zkWyPpTRhBlKAxsMLgRldKH2U=; b=SemNaLaQ5G9/8SAFzpsLpFOM4MMDmJjiUe4Cu3XgCiisoo+9UQltUg+0C2MbDAphrY EKkjqAjTL08/8F3fYqdq0+VjRqo1AfMXjlTkCqC0lC9YFvgEFufRKQZSYZVQrLhYSAVD zKn0SGl3xjsV8YApXkMyEU0YMPBtqbc20DKd/rd8SOh2852TBa14h9xQYDVPbJu1s1B8 /K0/2ExAIC2FbZDZDEKA36T7zvLL7gbHo+WEsiQSPcQLN3ZCeSCGpSwD6TyrRJJuEHbi bFFQIhXePTLq/HIxbDepFHDnajRYsH0CuJOZl7P7WX/02kHgDc2OF1MzEFcdff2ESTZe p7bg== X-Received: by 10.180.182.7 with SMTP id ea7mr56400968wic.58.1441801315017; Wed, 09 Sep 2015 05:21:55 -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.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Sep 2015 05:21:53 -0700 (PDT) From: David Herrmann To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/5] drm: move drm_class into drm_sysfs.c Date: Wed, 9 Sep 2015 14:21:30 +0200 Message-Id: <1441801293-1440-3-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 Right now, drm_sysfs_create() returns the newly allocated "struct class" to the caller (which is drm_core_init()), which then has to set the global variable 'drm_class'. During cleanup, though, we call drm_sysfs_destroy() which implicitly uses the global 'drm_class'. This is confusing, as ownership of the global 'drm_class' is non-obvious. This patch changes drm_sysfs_create() to drm_sysfs_init() and makes it initialize the 'drm_class' object directly, rather than returning it. This way, both drm_sysfs_init() and drm_sysfs_destroy() work in a similar fashion and manage the global drm class. Signed-off-by: David Herrmann --- drivers/gpu/drm/drm_drv.c | 6 ++---- drivers/gpu/drm/drm_internal.h | 2 +- drivers/gpu/drm/drm_sysfs.c | 47 +++++++++++++++++++----------------------- 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 53d09a1..58299f7 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -55,7 +55,6 @@ module_param_named(debug, drm_debug, int, 0600); static DEFINE_SPINLOCK(drm_minor_lock); static struct idr drm_minors_idr; -struct class *drm_class; static struct dentry *drm_debugfs_root; void drm_err(const char *format, ...) @@ -839,10 +838,9 @@ static int __init drm_core_init(void) if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops)) goto err_p1; - drm_class = drm_sysfs_create(THIS_MODULE, "drm"); - if (IS_ERR(drm_class)) { + ret = drm_sysfs_init(); + if (ret < 0) { printk(KERN_ERR "DRM: Error creating drm class.\n"); - ret = PTR_ERR(drm_class); goto err_p2; } diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h index 059af01..43cbda3 100644 --- a/drivers/gpu/drm/drm_internal.h +++ b/drivers/gpu/drm/drm_internal.h @@ -73,7 +73,7 @@ int drm_authmagic(struct drm_device *dev, void *data, /* drm_sysfs.c */ extern struct class *drm_class; -struct class *drm_sysfs_create(struct module *owner, char *name); +int drm_sysfs_init(void); void drm_sysfs_destroy(void); struct device *drm_sysfs_minor_alloc(struct drm_minor *minor); int drm_sysfs_connector_add(struct drm_connector *connector); diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c index 3f66cb0..f08873f 100644 --- a/drivers/gpu/drm/drm_sysfs.c +++ b/drivers/gpu/drm/drm_sysfs.c @@ -30,6 +30,8 @@ static struct device_type drm_sysfs_device_minor = { .name = "drm_minor" }; +struct class *drm_class; + /** * __drm_class_suspend - internal DRM class suspend routine * @dev: Linux device to suspend @@ -112,41 +114,34 @@ static CLASS_ATTR_STRING(version, S_IRUGO, CORE_DATE); /** - * drm_sysfs_create - create a struct drm_sysfs_class structure - * @owner: pointer to the module that is to "own" this struct drm_sysfs_class - * @name: pointer to a string for the name of this class. + * drm_sysfs_init - initialize sysfs helpers + * + * This is used to create the DRM class, which is the implicit parent of any + * other top-level DRM sysfs objects. * - * This is used to create DRM class pointer that can then be used - * in calls to drm_sysfs_device_add(). + * You must call drm_sysfs_destroy() to release the allocated resources. * - * Note, the pointer created here is to be destroyed when finished by making a - * call to drm_sysfs_destroy(). + * Return: 0 on success, negative error code on failure. */ -struct class *drm_sysfs_create(struct module *owner, char *name) +int drm_sysfs_init(void) { - struct class *class; int err; - class = class_create(owner, name); - if (IS_ERR(class)) { - err = PTR_ERR(class); - goto err_out; - } - - class->pm = &drm_class_dev_pm_ops; + drm_class = class_create(THIS_MODULE, "drm"); + if (IS_ERR(drm_class)) + return PTR_ERR(drm_class); - err = class_create_file(class, &class_attr_version.attr); - if (err) - goto err_out_class; + drm_class->pm = &drm_class_dev_pm_ops; - class->devnode = drm_devnode; - - return class; + err = class_create_file(drm_class, &class_attr_version.attr); + if (err) { + class_destroy(drm_class); + drm_class = NULL; + return err; + } -err_out_class: - class_destroy(class); -err_out: - return ERR_PTR(err); + drm_class->devnode = drm_devnode; + return 0; } /**