From patchwork Thu Dec 22 19:14:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 13080245 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F2ACC001B2 for ; Thu, 22 Dec 2022 19:15:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235107AbiLVTPW (ORCPT ); Thu, 22 Dec 2022 14:15:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230206AbiLVTPV (ORCPT ); Thu, 22 Dec 2022 14:15:21 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 346FC27DE4; Thu, 22 Dec 2022 11:15:20 -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 42193890; Thu, 22 Dec 2022 20:15:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1671736518; bh=6uYCqoGzATUwi33s8qwvH2BR201HZIZgkpsRD/uga5I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ngtNY6j8Irf0q8DYlJnrYOOiK2jqTxM+kAzkuHj3rAgfw3ZJABT0ddX64ZpV3JJ1P NM9rWtLFodm8PIs2zQIisV8Iswy9mhy0JyIS0qXs3yVy1vdnZ5zXj2speGm+fyQJju VmkFWDDPv1gYfAVBZ0PMD60gGTEPetazrd/wcVY0= 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 1/4] staging: vc04_services: Stop leaking platform device on error path Date: Fri, 23 Dec 2022 00:44:57 +0530 Message-Id: <20221222191500.515795-2-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 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org vchiq driver registers the child platform devices in vchiq_register_child(). However, in the registration error code path, currently the driver is leaking platform devices by not destroying the return platform device. Plug this leak using platform_device_put() as mentioned in the documentation for platform_device_register(). Signed-off-by: Umang Jain --- drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 1 + 1 file changed, 1 insertion(+) 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 dc33490ba7fb..fc7ea7ba97b2 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c @@ -1779,6 +1779,7 @@ vchiq_register_child(struct platform_device *pdev, const char *name) child = platform_device_register_full(&pdevinfo); if (IS_ERR(child)) { dev_warn(&pdev->dev, "%s not registered\n", name); + platform_device_put(child); child = NULL; } From patchwork Thu Dec 22 19:14:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 13080246 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACCC0C4332F for ; Thu, 22 Dec 2022 19:15:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229948AbiLVTPb (ORCPT ); Thu, 22 Dec 2022 14:15:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235394AbiLVTP0 (ORCPT ); Thu, 22 Dec 2022 14:15:26 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECAA228E31; Thu, 22 Dec 2022 11:15:25 -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 49B6E89F; Thu, 22 Dec 2022 20:15:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1671736524; bh=ZVkLGUNPuXKW9TCCk2CvFJa796G8cO0C9Y1XT9ye/iw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e4std9e1LWG4Z+fh4/ZeD7HFUx10A7JSRR2HuymdcZYROvVfrwjbticYFHytoJJnp vNfowK277ndSn0PNfBxt3BOKF4jjGA0NIPpvfXar9wSqXQpowknm4mdOB1HwIqU7n/ 8Bn5vQv1ia7ly4RIZLI2fiu0hwoHCIO/Q+CsRF3w= 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 2/4] staging: vchiq: Do not assign default dma_mask explicitly Date: Fri, 23 Dec 2022 00:44:58 +0530 Message-Id: <20221222191500.515795-3-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 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The vchiq driver assigns DMA_BIT_MASK(32) to the child platform devices it registers. By default, platform_device_register_* helpers assign DMA_BIT_MASK(32) dma_mask to the platform devices it registers. It is unnecessary to define it explicitly in struct platform_device_info hence, drop this explicit dma_mask assignment. This will help simplying the vchiq_register_child() going forwards. No functional changes intended in this patch. Signed-off-by: Umang Jain --- drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 1 - 1 file changed, 1 deletion(-) 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 fc7ea7ba97b2..3c4766375daa 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c @@ -1774,7 +1774,6 @@ vchiq_register_child(struct platform_device *pdev, const char *name) pdevinfo.parent = &pdev->dev; pdevinfo.name = name; pdevinfo.id = PLATFORM_DEVID_NONE; - pdevinfo.dma_mask = DMA_BIT_MASK(32); child = platform_device_register_full(&pdevinfo); if (IS_ERR(child)) { From patchwork Thu Dec 22 19:14:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 13080247 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AD8EC001B2 for ; Thu, 22 Dec 2022 19:15:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235519AbiLVTPg (ORCPT ); Thu, 22 Dec 2022 14:15:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235454AbiLVTPd (ORCPT ); Thu, 22 Dec 2022 14:15:33 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FDB328E38; Thu, 22 Dec 2022 11:15:31 -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 56073471; Thu, 22 Dec 2022 20:15:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1671736530; bh=bqvMP11pqYGYAC5IZOywqjG3I9GF/0iY9Gg7h2H8QBs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tl8lcCTtBojKEuNJ8j+cnCa7NsqslZ/z3PEjsWPTzSUny88AVie/m6bS1/CJfboa4 yhk8NKmdqAN/+nuzHtsQhOui3SeFIdyhWigmoReRGlfp5e52gmnIvExLyXf5cvh27u m+01+akz6BoJrrgkRVYJEjxXAwz10DXh4qkfN1qU= 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 3/4] staging: vchiq: Simplify platform devices registration Date: Fri, 23 Dec 2022 00:44:59 +0530 Message-Id: <20221222191500.515795-4-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 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The child platform devices registered by the vchiq driver currently populates a struct platform_device_info with a name and parent device and uses platform_device_register_full() to its registration. It can be simplified by using platform_device_register_data() directly (which encapsulates populating the platform_device_info struct and a platform_device_register_full() call in itself). Signed-off-by: Umang Jain --- .../vc04_services/interface/vchiq_arm/vchiq_arm.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 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 3c4766375daa..ba34e4d603d4 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c @@ -1766,16 +1766,10 @@ MODULE_DEVICE_TABLE(of, vchiq_of_match); static struct platform_device * vchiq_register_child(struct platform_device *pdev, const char *name) { - struct platform_device_info pdevinfo; struct platform_device *child; - memset(&pdevinfo, 0, sizeof(pdevinfo)); - - pdevinfo.parent = &pdev->dev; - pdevinfo.name = name; - pdevinfo.id = PLATFORM_DEVID_NONE; - - child = platform_device_register_full(&pdevinfo); + child = platform_device_register_data(&pdev->dev, name, PLATFORM_DEVID_NONE, + NULL, 0); if (IS_ERR(child)) { dev_warn(&pdev->dev, "%s not registered\n", name); platform_device_put(child); 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: 13080248 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43DA9C4332F for ; Thu, 22 Dec 2022 19:15:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235624AbiLVTPt (ORCPT ); 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 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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();