Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp168388imd; Fri, 26 Oct 2018 06:50:49 -0700 (PDT) X-Google-Smtp-Source: AJdET5f11FrIpRGXltE/Ha03ELTQcmQ3QkQpi6qZinR+n+hA8bkZYOhCWea87CLT9aVDFWncrLX4 X-Received: by 2002:a62:3301:: with SMTP id z1-v6mr3721984pfz.85.1540561849476; Fri, 26 Oct 2018 06:50:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540561849; cv=none; d=google.com; s=arc-20160816; b=U6Jn3ZJYe6iKWdL64gY43ciEd2/MbBuQ+pH/+QAn9mKyi7+1ZoDqfD4ruTcUmaBL/W HOg4BsOhjFGYbxd84RUnQl0lnwi/5vHcNsLvOaa4ga+FS2G4/YiZn97DMCu+fUn00/g3 sDMzIqxWNlTxmS1hmqomhnTpIKlf5RI5jIMXuthi9hKFNHg3nIXFHfpHLteHENyq1LOl B5zUYfrHH2gsgGCOEOtQ+LNi4zKl+930UPL8WwpJJXiS8GXEiqJ95Q4fPcqHiTmUp2iZ oY1+bR+GtxNIiAbHOH9hFcCEM93PU1P3gPYr9c47EzSjch1epDgAeDAFja2H+UnWY10K +4MQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=G34t4MkXGLaLYe92aSD+WaIW/iRp8hPEpZfZi1DldYc=; b=d62snw/ouKmNKTkm25CB1bgoyaGEG8m3JM6WiiCN69H8/I+mu94hF9BzYEgwQKtR6i vQOWbwVHsh1aMjF/k4xg5k6a9JsfMYYX58gOQ0NGc4Lun3cZVeROjCbtpva4unD4IPsX d3LOzzVXER2wfDXgoBmnDCNJ0O5lROQAOw+v8n8/56hL9G9wZqsOwtZvmdLv+FlaUISr PR7dgQCspy8q0PylnfHx/6JAYHea7OeUbBgXpZFd58T5uoxJhHt7go8sfAJEHwJO9McQ ZA0cBUuMF1ajbcrrbI6sJZiY8DWl5K54qyst5Ums17swveBQ9FTwCdYakM/BO9mOvLcm 6cBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r15-v6si11302406pgh.88.2018.10.26.06.50.34; Fri, 26 Oct 2018 06:50:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727666AbeJZWZt (ORCPT + 99 others); Fri, 26 Oct 2018 18:25:49 -0400 Received: from mx2.suse.de ([195.135.220.15]:44840 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726113AbeJZWZt (ORCPT ); Fri, 26 Oct 2018 18:25:49 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 76520B057; Fri, 26 Oct 2018 13:48:39 +0000 (UTC) From: Nicolas Saenz Julienne To: stefan.wahren@i2se.com, eric@anholt.net, dave.stevenson@raspberrypi.org Cc: nsaenzjulienne@suse.de, linux-rpi-kernel@lists.infradead.org, gregkh@linuxfoundation.org, linux-arm-kernel@lists.infradead.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC 16/18] staging: vchiq_arm: rework probe and init functions Date: Fri, 26 Oct 2018 15:48:11 +0200 Message-Id: <20181026134813.7775-17-nsaenzjulienne@suse.de> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181026134813.7775-1-nsaenzjulienne@suse.de> References: <20181026134813.7775-1-nsaenzjulienne@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some operations performed in the probe function should have been implemented in the init function. Namely class and dev region creations. Signed-off-by: Nicolas Saenz Julienne --- .../interface/vchiq_arm/vchiq_arm.c | 71 ++++++++++++------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c index 383013a92939..a7dcced79980 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c @@ -166,7 +166,6 @@ static struct cdev vchiq_cdev; static dev_t vchiq_devid; static VCHIQ_STATE_T g_state; static struct class *vchiq_class; -static struct device *vchiq_dev; static DEFINE_SPINLOCK(msg_queue_spinlock); static struct platform_device *bcm2835_camera; @@ -3552,34 +3551,19 @@ static int vchiq_probe(struct platform_device *pdev) if (err != 0) goto failed_platform_init; - err = alloc_chrdev_region(&vchiq_devid, VCHIQ_MINOR, 1, DEVICE_NAME); - if (err != 0) { - vchiq_log_error(vchiq_arm_log_level, - "Unable to allocate device number"); - goto failed_platform_init; - } cdev_init(&vchiq_cdev, &vchiq_fops); vchiq_cdev.owner = THIS_MODULE; err = cdev_add(&vchiq_cdev, vchiq_devid, 1); if (err != 0) { vchiq_log_error(vchiq_arm_log_level, "Unable to register device"); - goto failed_cdev_add; + goto failed_platform_init; } - /* create sysfs entries */ - vchiq_class = class_create(THIS_MODULE, DEVICE_NAME); - err = PTR_ERR(vchiq_class); - if (IS_ERR(vchiq_class)) - goto failed_class_create; - - vchiq_dev = device_create(vchiq_class, NULL, - vchiq_devid, NULL, "vchiq"); - err = PTR_ERR(vchiq_dev); - if (IS_ERR(vchiq_dev)) + if (IS_ERR(device_create(vchiq_class, &pdev->dev, vchiq_devid, + NULL, "vchiq"))) goto failed_device_create; - /* create debugfs entries */ vchiq_debugfs_init(); vchiq_log_info(vchiq_arm_log_level, @@ -3594,11 +3578,7 @@ static int vchiq_probe(struct platform_device *pdev) return 0; failed_device_create: - class_destroy(vchiq_class); -failed_class_create: cdev_del(&vchiq_cdev); -failed_cdev_add: - unregister_chrdev_region(vchiq_devid, 1); failed_platform_init: vchiq_log_warning(vchiq_arm_log_level, "could not load vchiq"); return err; @@ -3609,9 +3589,7 @@ static int vchiq_remove(struct platform_device *pdev) platform_device_unregister(bcm2835_camera); vchiq_debugfs_deinit(); device_destroy(vchiq_class, vchiq_devid); - class_destroy(vchiq_class); cdev_del(&vchiq_cdev); - unregister_chrdev_region(vchiq_devid, 1); return 0; } @@ -3624,7 +3602,48 @@ static struct platform_driver vchiq_driver = { .probe = vchiq_probe, .remove = vchiq_remove, }; -module_platform_driver(vchiq_driver); + +static int __init vchiq_driver_init(void) +{ + int ret; + + vchiq_class = class_create(THIS_MODULE, DEVICE_NAME); + if (IS_ERR(vchiq_class)) { + pr_err("Failed to create vchiq class\n"); + return PTR_ERR(vchiq_class); + } + + ret = alloc_chrdev_region(&vchiq_devid, VCHIQ_MINOR, 1, DEVICE_NAME); + if (ret) { + pr_err("Failed to allocate vchiq's chrdev region\n"); + goto class_destroy; + } + + ret = platform_driver_register(&vchiq_driver); + if (ret) { + pr_err("Failed to register vchiq driver\n"); + goto region_unregister; + } + + return 0; + +region_unregister: + platform_driver_unregister(&vchiq_driver); + +class_destroy: + class_destroy(vchiq_class); + + return ret; +} +module_init(vchiq_driver_init); + +static void __exit vchiq_driver_exit(void) +{ + platform_driver_unregister(&vchiq_driver); + unregister_chrdev_region(vchiq_devid, 1); + class_destroy(vchiq_class); +} +module_exit(vchiq_driver_exit); MODULE_LICENSE("Dual BSD/GPL"); MODULE_DESCRIPTION("Videocore VCHIQ driver"); -- 2.19.1