From patchwork Thu May 8 16:37:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sylwester Nawrocki/Kernel \\(PLT\\) /SRPOL/Staff Engineer/Samsung Electronics" X-Patchwork-Id: 4137791 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6B840BFF02 for ; Thu, 8 May 2014 16:40:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 993462024D for ; Thu, 8 May 2014 16:40:52 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C74CA201FA for ; Thu, 8 May 2014 16:40:51 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WiRLC-0000qC-28; Thu, 08 May 2014 16:38:38 +0000 Received: from mailout3.samsung.com ([203.254.224.33]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WiRL9-0000ns-Hc for linux-arm-kernel@lists.infradead.org; Thu, 08 May 2014 16:38:36 +0000 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N59002AHKVMGC20@mailout3.samsung.com> for linux-arm-kernel@lists.infradead.org; Fri, 09 May 2014 01:38:10 +0900 (KST) X-AuditID: cbfee61b-b7f766d00000646c-ba-536bb2f2271d Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 1D.52.25708.2F2BB635; Fri, 09 May 2014 01:38:10 +0900 (KST) Received: from amdc1344.digital.local ([106.116.147.32]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0N5900E7JKV3T860@mmp1.samsung.com>; Fri, 09 May 2014 01:38:10 +0900 (KST) From: Sylwester Nawrocki To: robh+dt@kernel.org, grant.likely@linaro.org Subject: [PATCH] of: Add of_device_destroy_children() function Date: Thu, 08 May 2014 18:37:49 +0200 Message-id: <1399567069-3174-1-git-send-email-s.nawrocki@samsung.com> X-Mailer: git-send-email 1.7.9.5 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrKJMWRmVeSWpSXmKPExsVy+t9jAd1Pm7KDDU72C1jMP3KO1eLAnx2M FpseX2O1uLxrDptF694j7BaH37SzOrB5bFrVyeZx59oeNo/NS+o9+rasYvT4vEkugDWKyyYl NSezLLVI3y6BK6Pj/CeWgs0iFReP3GNpYJwm2MXIySEhYCLx4stVZghbTOLCvfVsXYxcHEIC ixgl3q45wQzhdDBJnGvZClbFJmAo0Xu0jxHEFhHQl5jecYUVpIhZYCKjxKfHS8ASwgJ2Eiv7 frOD2CwCqhKnJ2wCGsvBwSvgKrGoOwnElBBQkJgzyWYCI/cCRoZVjKKpBckFxUnpuUZ6xYm5 xaV56XrJ+bmbGMGB8Ux6B+OqBotDjAIcjEo8vC+mZAcLsSaWFVfmHmKU4GBWEuF9sQwoxJuS WFmVWpQfX1Sak1p8iFGag0VJnPdgq3WgkEB6YklqdmpqQWoRTJaJg1OqgTH9lvWh89PVWz2/ p++dGPTj1ZRHcgdcJK9PrCl6YREYVbvrmp0cr/nUnDQO2ZIbBSExjgaZ9Reu//7oaHjUwTZh dfXi208/9W97lzdb8/Cjdacusq17dW7y/GTfp91NUQ4MV/Z+dW71Vf5rVzDh4J/edob8CSac mkmf9VmDTM4djvuw+3XW814lluKMREMt5qLiRADQUESYCAIAAA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140508_093835_768749_FA6DCE49 X-CRM114-Status: GOOD ( 11.92 ) X-Spam-Score: -5.7 (-----) Cc: devicetree@vger.kernel.org, Sylwester Nawrocki , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds a helper function to unregister devices which were created by an of_platform_populate() call. The pattern used here can already be found in multiple drivers. This helper can now be used instead of repeating similar code in drivers. Signed-off-by: Sylwester Nawrocki Acked-by: Kyungmin Park --- This patch has been tested on ARM only (on Exynos4412 Trats2 board). drivers/of/device.c | 24 ++++++++++++++++++++++++ include/linux/of_device.h | 3 +++ 2 files changed, 27 insertions(+) -- 1.7.9.5 diff --git a/drivers/of/device.c b/drivers/of/device.c index dafb973..9303197 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -190,3 +190,27 @@ int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env) return 0; } + +static int __remove_child_device(struct device *dev, void *unused) +{ + if (of_match_node(of_default_bus_match_table, dev->of_node)) + of_device_destroy_children(dev); + + device_unregister(dev); + return 0; +} + +/** + * of_device_destroy_children - unregister @parent's child devices + * @parent: the parent device to start with + * + * Destroy all child devices of the @parent device, any grandchildren + * compatible with values listed in the of_default_bus_match_table will + * also be unregistered recursively. This function can be used to + * destroy devices created by an of_platform_populate() call. + */ +void of_device_destroy_children(struct device *parent) +{ + device_for_each_child(parent, NULL, __remove_child_device); +} +EXPORT_SYMBOL(of_device_destroy_children); diff --git a/include/linux/of_device.h b/include/linux/of_device.h index ef37021..0c41e0b 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h @@ -32,6 +32,7 @@ extern void of_dev_put(struct platform_device *dev); extern int of_device_add(struct platform_device *pdev); extern int of_device_register(struct platform_device *ofdev); extern void of_device_unregister(struct platform_device *ofdev); +extern void of_device_destroy_children(struct device *parent); extern ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len); @@ -64,6 +65,8 @@ static inline int of_driver_match_device(struct device *dev, static inline void of_device_uevent(struct device *dev, struct kobj_uevent_env *env) { } +static inline void of_device_destroy_children(struct device *parent) { } + static inline int of_device_get_modalias(struct device *dev, char *str, ssize_t len) {