Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752642AbcLLSjQ (ORCPT ); Mon, 12 Dec 2016 13:39:16 -0500 Received: from quartz.orcorp.ca ([184.70.90.242]:41223 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752462AbcLLSjP (ORCPT ); Mon, 12 Dec 2016 13:39:15 -0500 Date: Mon, 12 Dec 2016 11:39:05 -0700 From: Jason Gunthorpe To: Rob Herring , Frank Rowand Cc: Pawel Moll , Grant Likely , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] of/platform: depopulate devices in the reverse order of creation Message-ID: <20161212183905.GA30702@obsidianresearch.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.156 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1226 Lines: 32 If the DT has inter-dependencies, then the devices need to be removed in the right order to avoid removal problems. Assuming the DT is constructed so that EPROBE_DEFER doesn't happen during creating then a good way to avoid removal problems is reversing the order during depopulation. Signed-off-by: Jason Gunthorpe --- drivers/of/platform.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) In my specific case I have a gpio driver, followed by a i2c bitbang using that driver. So gpiolib prints an error if it the gpio driver is removed before the gpio client.. diff --git a/drivers/of/platform.c b/drivers/of/platform.c index cd72c0156db2ba..5720fe44f991e9 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -568,7 +568,8 @@ static int of_platform_device_destroy(struct device *dev, void *data) void of_platform_depopulate(struct device *parent) { if (parent->of_node && of_node_check_flag(parent->of_node, OF_POPULATED_BUS)) { - device_for_each_child(parent, NULL, of_platform_device_destroy); + device_for_each_child_reverse(parent, NULL, + of_platform_device_destroy); of_node_clear_flag(parent->of_node, OF_POPULATED_BUS); } } -- 2.7.4