From patchwork Thu Dec 22 19:15:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 88417 Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1p8R2l-0038qm-9p; Thu, 22 Dec 2022 19:15:51 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235624AbiLVTPt (ORCPT + 1 other); Thu, 22 Dec 2022 14:15:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235397AbiLVTPn (ORCPT ); Thu, 22 Dec 2022 14:15:43 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E2EC28E3F; Thu, 22 Dec 2022 11:15:38 -0800 (PST) Received: from umang.jainideasonboard.com (unknown [IPv6:2401:4900:1f3f:d076:4da6:b729:f032:ed0a]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5558AD1D; Thu, 22 Dec 2022 20:15:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1671736536; bh=UfLBAATkzD9U4stHiW/1mzjiTeAr0HmtQX04bnFhvF8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aITi7TmA0EOroVzsJ9FqxJ9gy86SyUVUC++vZHXksel5bCRccVmDOWyJ1AKMjRP6l eWO0vHChMq/M/Zu1NQDBBqlHF54SlBUCc0nG7AFaTKZPdlgPte+Kr2UxaiYctcWfkh Dv/0GvVDWBScvp380GaZb/IE9nRaPY5XoK7Dch6s= From: Umang Jain To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-staging@lists.linux.dev, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org Cc: Greg Kroah-Hartman , Adrien Thierry , Stefan Wahren , Florian Fainelli , Dan Carpenter , Nicolas Saenz Julienne , Phil Elwell , Dave Stevenson , Kieran Bingham , Laurent Pinchart , Umang Jain Subject: [PATCH v2 4/4] staging: vchiq: Rework child platform device (un)register Date: Fri, 23 Dec 2022 00:45:00 +0530 Message-Id: <20221222191500.515795-5-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221222191500.515795-1-umang.jain@ideasonboard.com> References: <20221222191500.515795-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no This patch reworks how the child platform devices are (un)registered by the vchiq driver. It drops the global references to the child platform devices thereby reducing the scope of platform device access to probe() function only. It does so, by maintaining an array of platform device names and registering each of them through vchiq_register_child(). In addition to that, any new child platform device can be (un)regsitered easily by just appending to the child platform devices' array. For platform device unregisterion, device_for_each_child() helper is used to call vchiq_unregister_child() on each of the child platform device of vchiq driver. This is part of an effort to address TODO item "Get rid of all non essential global structures and create a proper per device structure" Signed-off-by: Umang Jain --- .../interface/vchiq_arm/vchiq_arm.c | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 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 ba34e4d603d4..d04dbea833ac 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c @@ -65,9 +65,6 @@ int vchiq_susp_log_level = VCHIQ_LOG_ERROR; DEFINE_SPINLOCK(msg_queue_spinlock); struct vchiq_state g_state; -static struct platform_device *bcm2835_camera; -static struct platform_device *bcm2835_audio; - struct vchiq_drvdata { const unsigned int cache_line_size; struct rpi_firmware *fw; @@ -1763,7 +1760,7 @@ static const struct of_device_id vchiq_of_match[] = { }; MODULE_DEVICE_TABLE(of, vchiq_of_match); -static struct platform_device * +static void vchiq_register_child(struct platform_device *pdev, const char *name) { struct platform_device *child; @@ -1773,10 +1770,18 @@ vchiq_register_child(struct platform_device *pdev, const char *name) if (IS_ERR(child)) { dev_warn(&pdev->dev, "%s not registered\n", name); platform_device_put(child); - child = NULL; } +} - return child; +static int +vchiq_unregister_child(struct device *dev, void *data) +{ + struct platform_device *pdev; + + pdev = to_platform_device(dev); + platform_device_unregister(pdev); + + return 0; } static int vchiq_probe(struct platform_device *pdev) @@ -1784,6 +1789,10 @@ static int vchiq_probe(struct platform_device *pdev) struct device_node *fw_node; const struct of_device_id *of_id; struct vchiq_drvdata *drvdata; + const char *const vchiq_devices[] = { + "bcm2835_audio", + "bcm2835-camera", + }; int err; of_id = of_match_node(vchiq_of_match, pdev->dev.of_node); @@ -1826,8 +1835,8 @@ static int vchiq_probe(struct platform_device *pdev) goto error_exit; } - bcm2835_camera = vchiq_register_child(pdev, "bcm2835-camera"); - bcm2835_audio = vchiq_register_child(pdev, "bcm2835_audio"); + for (unsigned int i = 0; i < ARRAY_SIZE(vchiq_devices); i++) + vchiq_register_child(pdev, vchiq_devices[i]); return 0; @@ -1839,8 +1848,7 @@ static int vchiq_probe(struct platform_device *pdev) static int vchiq_remove(struct platform_device *pdev) { - platform_device_unregister(bcm2835_audio); - platform_device_unregister(bcm2835_camera); + device_for_each_child(&pdev->dev, NULL, vchiq_unregister_child); vchiq_debugfs_deinit(); vchiq_deregister_chrdev();