Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2945403pxj; Sun, 20 Jun 2021 05:56:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxil5Ux3u/TY3KkDjw+5T/6qRdP45d1hXW2an1yeDf1ZB7oHOyaa34xseISATguqIGyOn1q X-Received: by 2002:a92:d601:: with SMTP id w1mr14329966ilm.1.1624193817092; Sun, 20 Jun 2021 05:56:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624193817; cv=none; d=google.com; s=arc-20160816; b=k3OD1HLDa8r2CmAHevm6FFPvK0k13zkctvvifU6bXlHpDEHwAG78Sn/ftEyNdCbz6q tiRYellDHBfmIl0SuvWS5d49Ps3dqIVrwIU6tXMSrTTGMRbrWKQ5lBN5gkoyIXkfjUpi +ruRjtgIeVIz4Pt2qdt7+mjZAx9RZMk9KsrUgw9C3bqenS0uKL+4dAPgDoBd6B6TLMj6 vXnX4cY4cVpQMzNrZJbJGk0YDfhC/SxlVO4QqhpG+/OXHMHgYawIb5xVG4Sg23+ZhMY7 3NU36uW03SXBiuEfTgx2Fe5riErdpIdB9a1hXC9pXmnro88SnQIpa9p6CzhwSX2QmUGZ 16Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=iML3X+LebYbUqiIruyQrVisHl+E/xyjft7hYS7VDy7I=; b=YPYlU7ol+sp/VAglx1KgTi1t+NtTz4zJJpVcAGCvbWY/3ad8BFBX9iEVFFR9/x54Oc L0c+3r1iOQ1Sa0oDWNIK/b5V0pJRzAZt1kaFV/yF7LhLSwH8R/Tm0pZh9tVDepi/TH7M j1EvuvCQXiIrZBNwgZK7SG9p3/0dVbsgwTMJFHkRw41j8SrklG3X9bNU6XRVW4iqoi+e qLj8dqfu+mCWPmSYEZZBE0/cC8wd9hVbzcA9Myj9DNbpn0JoKlCaYSrMOFgPQOmFGWe3 2vy0TU6aKeTqpC/ZURzeeRhbnTEpJkNhGUXbvRM0bGNU/wrINOmqv3xYIL41LK40vpey pfYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=e8tvsQft; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v1si606323iot.18.2021.06.20.05.56.45; Sun, 20 Jun 2021 05:56:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=e8tvsQft; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229653AbhFTM6O (ORCPT + 99 others); Sun, 20 Jun 2021 08:58:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229637AbhFTM6N (ORCPT ); Sun, 20 Jun 2021 08:58:13 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E5F9C061574 for ; Sun, 20 Jun 2021 05:56:00 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id y14so444124pgs.12 for ; Sun, 20 Jun 2021 05:56:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=iML3X+LebYbUqiIruyQrVisHl+E/xyjft7hYS7VDy7I=; b=e8tvsQftsTNLUtKuaA2EpXy9VCg5x+v8pEWsQ/vBG7LLU7qU1FsYYONTdHXmSt66as oETD9VuIshmh3GLbtbZNtSBkqP3axHMFKdntbXaTDPN2GABSQHGlVnctayHu9bJ/Wndx 4EJrVCuDsN7oeQYSmauOgkc+fLu9CfHQTuEYiWTVjkUVWhNR2TTyAZ08rdP11iUZ5LMw Y38HnQWd35H7LD2ug4IKwmbCf+MwMFHj/eL7M6Oa/EHPRDUA+IaoL1S9BJTU4EZU16up sy899nw5tadH62begMVgJMuESIg48eRN8OIGZxKj7G/LfuoHbU2dL0ZcJ9wI45IRXCY+ 3SGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=iML3X+LebYbUqiIruyQrVisHl+E/xyjft7hYS7VDy7I=; b=FWEvoO3dqhsZfBxmnWsF0zcP3sOl7glHPQ3KS5+C3cEgpW8MG4X3z/6FrUF7iePgvc 6KA96ylkKinKNZ7hd2bhwYdj1WKGbGexgQUJLx1IFwEO8rIOb9Dyt7BaOMDbM5Q6vbfA dxK31vaEv5ikuS98oArPl89O/7O45somKS7O2W7PdrHZbeySWpitVtra4fxXAC/lIDS6 +ZNVjxUue4EtxP8gvM6tI6rAeHT2bdAbUjjw8+ak0cp33fpBDOgzwAXVK4HtXLZzRiEP 0kfIO8J4BRnDaQ4MKH7UJDuxPWl7yJlm96hFUHOSyBadNPdltj01BCJ+PRW26TCR/Wwo ykKg== X-Gm-Message-State: AOAM533XE4zVomGKFve7X03swKEmECYVFTaQRnoJlrElGYNxGyB/Z2mc sm0u4bcShaDDyJ7o1yURppc= X-Received: by 2002:a62:1c86:0:b029:2fe:b583:6418 with SMTP id c128-20020a621c860000b02902feb5836418mr14801744pfc.23.1624193759733; Sun, 20 Jun 2021 05:55:59 -0700 (PDT) Received: from ojas ([122.177.154.120]) by smtp.gmail.com with ESMTPSA id co18sm3812154pjb.37.2021.06.20.05.55.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Jun 2021 05:55:59 -0700 (PDT) Date: Sun, 20 Jun 2021 18:25:46 +0530 From: Ojaswin Mujoo To: nsaenz@kernel.org Cc: gregkh@linuxfoundation.org, stefan.wahren@i2se.com, arnd@arndb.de, dan.carpenter@oracle.com, phil@raspberrypi.com, bcm-kernel-feedback-list@broadcom.com, linux-arm-kernel@lists.infradead.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/5] staging: vchiq: Refactor vchiq cdev code Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move the vchiq cdev initialization code to its own function for better code organization. Call the initialization function during probe, thus shifting the whole cdev creation logic (which was earlier split in vchiq_probe() and vchiq_driver_init()) to vchiq_probe(). Signed-off-by: Ojaswin Mujoo --- .../interface/vchiq_arm/vchiq_arm.c | 137 +++++++++++------- 1 file changed, 87 insertions(+), 50 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 a936102dbc34..f2d8116913f2 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c @@ -2207,6 +2207,81 @@ vchiq_fops = { .read = vchiq_read }; +/** + * vchiq_register_chrdev - Register the char driver for vchiq + * and create the necessary class and + * device files in userspace. + * @parent The parent of the char device. + * + * Returns 0 on success else returns the error code. + */ +static 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)); + + 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; +} + +/** + * vchiq_deregister_chrdev - Deregister and cleanup the vchiq char + * driver and device files + */ +static 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); +} + /* * Autosuspend related functionality */ @@ -2740,7 +2815,6 @@ static int vchiq_probe(struct platform_device *pdev) struct device_node *fw_node; const struct of_device_id *of_id; struct vchiq_drvdata *drvdata; - struct device *vchiq_dev; int err; of_id = of_match_node(vchiq_of_match, pdev->dev.of_node); @@ -2766,28 +2840,18 @@ static int vchiq_probe(struct platform_device *pdev) if (err) 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) { - vchiq_log_error(vchiq_arm_log_level, - "Unable to register device"); - goto failed_platform_init; - } - - vchiq_dev = device_create(vchiq_class, &pdev->dev, vchiq_devid, NULL, - "vchiq"); - if (IS_ERR(vchiq_dev)) { - err = PTR_ERR(vchiq_dev); - goto failed_device_create; - } - vchiq_debugfs_init(); vchiq_log_info(vchiq_arm_log_level, - "vchiq: initialised - version %d (min %d), device %d.%d", - VCHIQ_VERSION, VCHIQ_VERSION_MIN, - MAJOR(vchiq_devid), MINOR(vchiq_devid)); + "vchiq: platform initialised - version %d (min %d)", + VCHIQ_VERSION, VCHIQ_VERSION_MIN); + + /* + * We don't handle error here since the function handles + * cleanup in cases of failure. Further, we can proceed + * even if this function fails. + */ + vchiq_register_chrdev(&pdev->dev); vcsm_cma = vchiq_register_child(pdev, "vcsm-cma"); bcm2835_codec = vchiq_register_child(pdev, "bcm2835-codec"); @@ -2797,10 +2861,8 @@ static int vchiq_probe(struct platform_device *pdev) return 0; -failed_device_create: - cdev_del(&vchiq_cdev); failed_platform_init: - vchiq_log_warning(vchiq_arm_log_level, "could not load vchiq"); + vchiq_log_warning(vchiq_arm_log_level, "could not initialize vchiq platform"); return err; } @@ -2812,8 +2874,7 @@ static int vchiq_remove(struct platform_device *pdev) platform_device_unregister(bcm2835_codec); platform_device_unregister(vcsm_cma); vchiq_debugfs_deinit(); - device_destroy(vchiq_class, vchiq_devid); - cdev_del(&vchiq_cdev); + vchiq_deregister_chrdev(); return 0; } @@ -2831,31 +2892,9 @@ 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, 0, 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) { + if (ret) pr_err("Failed to register vchiq driver\n"); - goto region_unregister; - } - - return 0; - -region_unregister: - unregister_chrdev_region(vchiq_devid, 1); - -class_destroy: - class_destroy(vchiq_class); return ret; } @@ -2864,8 +2903,6 @@ 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); -- 2.25.1