From patchwork Sun Jun 20 12:55:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ojaswin Mujoo X-Patchwork-Id: 12333397 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=-10.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 8CCD4C48BDF for ; Sun, 20 Jun 2021 12:57:59 +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 50F636113C for ; Sun, 20 Jun 2021 12:57:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 50F636113C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+9Hm8xOjVGH4l/79tGD2aFyf2kxwECXlczcJK8DKwNA=; b=BmN9+9WsyKmNw5 U/yYHuYfmRl9456i7RNYAoCKyVHJ07Wsq3UlXwbfYzdG5NQ46DaKli5jj01JV20tB7LnnETMZjCSD cDEgEk9FhAheR0tFbN/rjVSS9oYCU8pR2rJyVPKWdkXBazzl4PButSm4rx8LiGZqlgvTMb7XMjLjJ Jt/XaWf2ecCH/RYrsmFY5WAzUuFgwWUp3kBASwzYBaH0A3r8HO1UD7VPl/3wDaKfmObrVpkQvnTkS 2TATee1ZtyKrb0qywYTVbGIGZxMkRuvjSsA7N/N77lupcfa2k1WEtE1F4bZWtT5vcg6APWFscuuXK UGt0qQ2kq21bp4syulaQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1luwzc-00117Z-5C; Sun, 20 Jun 2021 12:56:04 +0000 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1luwzY-001173-E8 for linux-arm-kernel@lists.infradead.org; Sun, 20 Jun 2021 12:56:02 +0000 Received: by mail-pg1-x530.google.com with SMTP id m2so11856084pgk.7 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=FeOY4dib6XG4oHDkna9qYKxadsfRNsQqkww50ACoiubfLaZZIYQqsqop684NRgOsWO IKCa8XZAeg/6Sr03kSOfcRUEEJVLKGB0pVeMmbv3oYCIbSyq8Kvq2cZR+q9lEZfXvorE BQHD4cJzzoyDMfhwSwkKzCZ5TdQkS0J0Is7CWTb1VjhF1xLQv1/YrN8s7iY90kjRWmD2 ObNtGcg6bDhJgHeyu4Axhdy/MNORyJGEgzWhIApb6ckx2PiLUQVVtSlTJ4mXiWgIBBs1 LWDa6sUoMbfeFcfy9FU23i3m2tAsKKfao0pbCt3hZWxvRFHuoXHKzB++DSThNpODFLRx XpYg== X-Gm-Message-State: AOAM532rRhQvXnwZzLyA3cTLOOKaAilSbQjczzNae7s37mKxXZMRzVlD uvnAZi7aDSjRhOkxSBJ4J/4= X-Google-Smtp-Source: ABdhPJzkahBPxIIzFmiVpSwNGpcOXwxm5HsGFWd8NkHOWtAiXW9R+Z0u9Al8u/OwyA8MXNVk9HO+tQ== 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-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210620_055600_535446_47C11C66 X-CRM114-Status: GOOD ( 19.75 ) 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 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);