From patchwork Tue Sep 7 11:50:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 12478385 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9A12C433EF for ; Tue, 7 Sep 2021 11:52:45 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E4E16008E for ; Tue, 7 Sep 2021 11:52:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8E4E16008E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=kWtKMpsliWOoKIgGQWYVFkphHVBEtYbZBDXBUP55KFk=; b=Jd9thl3nHRtg1d djjyjFI/cpD/Lh2PomVarCivxetADWmWgUqWJ04oYiQZBCsNYqoYwtk/ZJnQN4I6R74JRkImGtj9M JPxsnJTuanQYFz/8H0t7wdIjDfxp9mHd7eITB4KsGVPk6lPEV0C+d3/vS4U8bSLsMGPhkohwZoLNe hb3r54HGGduvocdw9Gv0bclDlI4j+++DeW27pl8Ej8SsqaAV0yKLudSJv+18yl7bFhIyz1sEMgV5o okFzTAXwUMuXWwpT6C3a/pUjuxpD0/0j4ur/5y+iPQ5HjiKiJTkx5sx0zui0ZONW9jVrE2TDqJgHU SKxqqheieuZw4ITRz+4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mNZcs-003Zhh-EO; Tue, 07 Sep 2021 11:50:54 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mNZcn-003Zgj-UR; Tue, 07 Sep 2021 11:50:51 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5B68661090; Tue, 7 Sep 2021 11:50:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631015449; bh=vQnkrTI6mz3nPzuTIQmNmI9aZxB+mRDoyGv+baQD7Tk=; h=From:To:Cc:Subject:Date:From; b=NPjaE/EV2zRpjIPJS08d3ad+RCeNuwmWt3qQYDAl0H1EsKHOzh1m6bMF1AoGzGM+1 1RQPvYk0T8rOK6ux+/RNzG6gthSCO6vUZ09/obZys8FRGzxgiQYnDpcWY/vPexPv/3 e9iwzg2w7O8TpoaWh+V9Hk5408kw6/QaAXE/3Ujc= From: Greg Kroah-Hartman To: linux-staging@lists.linux.dev Cc: Greg Kroah-Hartman , Nicolas Saenz Julienne , Stefan Wahren , Arnd Bergmann , Dan Carpenter , Ojaswin Mujoo , Phil Elwell , bcm-kernel-feedback-list@broadcom.com, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] staging: vchiq: convert to use a miscdevice Date: Tue, 7 Sep 2021 13:50:45 +0200 Message-Id: <20210907115045.2206083-1-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3690; h=from:subject; bh=vQnkrTI6mz3nPzuTIQmNmI9aZxB+mRDoyGv+baQD7Tk=; b=owGbwMvMwCRo6H6F97bub03G02pJDInmQcLLjsafubLW68SBr/71rL6nbzHs31r547vKlQMlU6/P nuD4riOWhUGQiUFWTJHlyzaeo/srDil6GdqehpnDygQyhIGLUwAmwqnIMFdw0yHPMo0XBbNjOlp817 t+dpOxN2GYn/R0YmUUC9PDmC9TJq2TvH+18vjCeQA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210907_045050_080712_510217BC X-CRM114-Status: GOOD ( 14.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Using a struct class, a cdev, and another device just for a single minor device is total overkill. Just use a dynamic misc device instead, saving lots of logic and memory. Cc: Nicolas Saenz Julienne Cc: Stefan Wahren Cc: Arnd Bergmann Cc: Dan Carpenter Cc: Ojaswin Mujoo Cc: Phil Elwell Cc: bcm-kernel-feedback-list@broadcom.com Cc: linux-rpi-kernel@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Greg Kroah-Hartman --- .../interface/vchiq_arm/vchiq_dev.c | 71 +++---------------- 1 file changed, 11 insertions(+), 60 deletions(-) diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c index bf1a88c9d1ee..788fa5a987a3 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c @@ -9,18 +9,13 @@ #include #include #include +#include #include "vchiq_core.h" #include "vchiq_ioctl.h" #include "vchiq_arm.h" #include "vchiq_debugfs.h" -#define DEVICE_NAME "vchiq" - -static struct cdev vchiq_cdev; -static dev_t vchiq_devid; -static struct class *vchiq_class; - static const char *const ioctl_names[] = { "CONNECT", "SHUTDOWN", @@ -1364,6 +1359,13 @@ vchiq_fops = { .read = vchiq_read }; +static struct miscdevice vchiq_miscdev = { + .fops = &vchiq_fops, + .minor = MISC_DYNAMIC_MINOR, + .name = "vchiq", + +}; + /** * vchiq_register_chrdev - Register the char driver for vchiq * and create the necessary class and @@ -1374,57 +1376,9 @@ vchiq_fops = { */ int vchiq_register_chrdev(struct device *parent) { - struct device *vchiq_dev; - int ret; - - vchiq_class = class_create(THIS_MODULE, DEVICE_NAME); - if (IS_ERR(vchiq_class)) { - pr_err("Failed to create vchiq class\n"); - ret = PTR_ERR(vchiq_class); - goto error_exit; - } - - ret = alloc_chrdev_region(&vchiq_devid, 0, 1, DEVICE_NAME); - if (ret) { - pr_err("vchiq: Failed to allocate vchiq's chrdev region\n"); - goto alloc_region_error; - } - - cdev_init(&vchiq_cdev, &vchiq_fops); - vchiq_cdev.owner = THIS_MODULE; - ret = cdev_add(&vchiq_cdev, vchiq_devid, 1); - if (ret) { - vchiq_log_error(vchiq_arm_log_level, - "Unable to register vchiq char device"); - goto cdev_add_error; - } - - vchiq_dev = device_create(vchiq_class, parent, vchiq_devid, NULL, - DEVICE_NAME); - if (IS_ERR(vchiq_dev)) { - vchiq_log_error(vchiq_arm_log_level, - "Failed to create vchiq char device node"); - ret = PTR_ERR(vchiq_dev); - goto device_create_error; - } - - vchiq_log_info(vchiq_arm_log_level, - "vchiq char dev initialised successfully - device %d.%d", - MAJOR(vchiq_devid), MINOR(vchiq_devid)); + vchiq_miscdev.parent = parent; - return 0; - -device_create_error: - cdev_del(&vchiq_cdev); - -cdev_add_error: - unregister_chrdev_region(vchiq_devid, 1); - -alloc_region_error: - class_destroy(vchiq_class); - -error_exit: - return ret; + return misc_register(&vchiq_miscdev); } /** @@ -1433,8 +1387,5 @@ int vchiq_register_chrdev(struct device *parent) */ void vchiq_deregister_chrdev(void) { - device_destroy(vchiq_class, vchiq_devid); - cdev_del(&vchiq_cdev); - unregister_chrdev_region(vchiq_devid, 1); - class_destroy(vchiq_class); + misc_deregister(&vchiq_miscdev); }