From patchwork Fri Jul 4 16:15:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 33110 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qg0-f69.google.com (mail-qg0-f69.google.com [209.85.192.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E8C8B20C88 for ; Fri, 4 Jul 2014 16:15:50 +0000 (UTC) Received: by mail-qg0-f69.google.com with SMTP id j107sf3802354qga.8 for ; Fri, 04 Jul 2014 09:15:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=oA79ZeaF4XdbQeZX1jkPS77jNHtgO2JPIHvCDMJFFEA=; b=P2a5mGcTJ+TC0dWrZS7FJh1XdMyp8zBp0UyYuLN1IBhW3JbMJ1qrfVoua2TczMEU0a iYf6x5/N+jKGrQLs8F4Vr1NaE2tX9sS+qt6pxymYG6Ki5VgbvxdsVaT7HQjfHDw0n3tf TbYAikb78wOK9GJmkj5gVRepIiQuubwjI5cVTWDU9Qvi4kPT8XaKVgYT/mL3mf3lK5tS AP32wdfGZtPCtH+s/emSm6ymz8Y51q9ZqlPw435RhvNttnMfPebSLJ3n+l93T9VISsiY Ymlo1wnnvGRnnkWigRQC6xGRQLPsnBmXgOhOTVwzbuWi8YGYRt7LwRX4JL6/OexVmnai q93Q== X-Gm-Message-State: ALoCoQmXpbUd7wOOxiP+AkaBsotQBbl5e536LTccBRvAU8rVl+tSckeeVDm7c7gbzoPf+07GhRL3 X-Received: by 10.58.114.41 with SMTP id jd9mr6131400veb.9.1404490550677; Fri, 04 Jul 2014 09:15:50 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.81.169 with SMTP id f38ls502748qgd.24.gmail; Fri, 04 Jul 2014 09:15:50 -0700 (PDT) X-Received: by 10.58.56.102 with SMTP id z6mr9971783vep.7.1404490550601; Fri, 04 Jul 2014 09:15:50 -0700 (PDT) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by mx.google.com with ESMTPS id ui7si15710768vcb.92.2014.07.04.09.15.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 04 Jul 2014 09:15:50 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.179 as permitted sender) client-ip=209.85.128.179; Received: by mail-ve0-f179.google.com with SMTP id sa20so1855252veb.10 for ; Fri, 04 Jul 2014 09:15:50 -0700 (PDT) X-Received: by 10.58.46.34 with SMTP id s2mr704375vem.49.1404490550497; Fri, 04 Jul 2014 09:15:50 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp476475vcb; Fri, 4 Jul 2014 09:15:50 -0700 (PDT) X-Received: by 10.69.25.69 with SMTP id io5mr11897423pbd.22.1404490549593; Fri, 04 Jul 2014 09:15:49 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w7si2100446pdl.180.2014.07.04.09.15.48; Fri, 04 Jul 2014 09:15:49 -0700 (PDT) Received-SPF: none (google.com: devicetree-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753100AbaGDQPq (ORCPT + 8 others); Fri, 4 Jul 2014 12:15:46 -0400 Received: from mail-wi0-f175.google.com ([209.85.212.175]:51300 "EHLO mail-wi0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752880AbaGDQPp (ORCPT ); Fri, 4 Jul 2014 12:15:45 -0400 Received: by mail-wi0-f175.google.com with SMTP id r20so13153502wiv.14 for ; Fri, 04 Jul 2014 09:15:43 -0700 (PDT) X-Received: by 10.180.20.234 with SMTP id q10mr54148246wie.9.1404490543523; Fri, 04 Jul 2014 09:15:43 -0700 (PDT) Received: from trevor.secretlab.ca (host31-50-124-166.range31-50.btcentralplus.com. [31.50.124.166]) by mx.google.com with ESMTPSA id u10sm80775484wix.11.2014.07.04.09.15.41 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Jul 2014 09:15:42 -0700 (PDT) Received: by trevor.secretlab.ca (Postfix, from userid 1000) id EE241C40C75; Fri, 4 Jul 2014 17:15:39 +0100 (BST) From: Grant Likely To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: Grant Likely , Pawel Moll , Pantelis Antoniou Subject: [PATCH] of/platform: Fix of_platform_device_destroy iteration of devices Date: Fri, 4 Jul 2014 17:15:33 +0100 Message-Id: <1404490533-7817-1-git-send-email-grant.likely@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: grant.likely@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.179 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , of_platform_destroy does not work properly, since the tree population test was iterating on all devices having as its parent the given platform device. The check was intended to check whether any other platform or amba devices created by of_platform_populate were still populated, but instead checked for every kind of device. This is wrong, since platform devices typically create a subsystem regular device and set themselves as parents. Instead, go ahead and call the unregister functions for any devices created with of_platform_populate. The driver core will take care of unbinding drivers, and drivers are responsible for getting rid of any child devices that weren't created by of_platform_populate. Signed-off-by: Grant Likely Cc: Pawel Moll Cc: Pantelis Antoniou --- drivers/of/platform.c | 32 +++++++++----------------------- include/linux/of.h | 1 + include/linux/of_platform.h | 7 ++----- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 500436f9be7f..0197725e033a 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -422,6 +422,7 @@ static int of_platform_bus_create(struct device_node *bus, break; } } + of_node_set_flag(bus, OF_POPULATED_BUS); return rc; } @@ -508,19 +509,13 @@ EXPORT_SYMBOL_GPL(of_platform_populate); static int of_platform_device_destroy(struct device *dev, void *data) { - bool *children_left = data; - /* Do not touch devices not populated from the device tree */ - if (!dev->of_node || !of_node_check_flag(dev->of_node, OF_POPULATED)) { - *children_left = true; + if (!dev->of_node || !of_node_check_flag(dev->of_node, OF_POPULATED)) return 0; - } - /* Recurse, but don't touch this device if it has any children left */ - if (of_platform_depopulate(dev) != 0) { - *children_left = true; - return 0; - } + /* Recurse for any nodes that were treated as busses */ + if (of_node_check_flag(dev->of_node, OF_POPULATED_BUS)) + device_for_each_child(dev, NULL, of_platform_device_destroy); if (dev->bus == &platform_bus_type) platform_device_unregister(to_platform_device(dev)); @@ -528,19 +523,15 @@ static int of_platform_device_destroy(struct device *dev, void *data) else if (dev->bus == &amba_bustype) amba_device_unregister(to_amba_device(dev)); #endif - else { - *children_left = true; - return 0; - } of_node_clear_flag(dev->of_node, OF_POPULATED); - + of_node_clear_flag(dev->of_node, OF_POPULATED_BUS); return 0; } /** * of_platform_depopulate() - Remove devices populated from device tree - * @parent: device which childred will be removed + * @parent: device which children will be removed * * Complementary to of_platform_populate(), this function removes children * of the given device (and, recurrently, their children) that have been @@ -550,14 +541,9 @@ static int of_platform_device_destroy(struct device *dev, void *data) * Returns 0 when all children devices have been removed or * -EBUSY when some children remained. */ -int of_platform_depopulate(struct device *parent) +void of_platform_depopulate(struct device *parent) { - bool children_left = false; - - device_for_each_child(parent, &children_left, - of_platform_device_destroy); - - return children_left ? -EBUSY : 0; + device_for_each_child(parent, NULL, of_platform_device_destroy); } EXPORT_SYMBOL_GPL(of_platform_depopulate); diff --git a/include/linux/of.h b/include/linux/of.h index 196b34c1ef4e..abf829a1f150 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -204,6 +204,7 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size) #define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */ #define OF_DETACHED 2 /* node has been detached from the device tree */ #define OF_POPULATED 3 /* device already created for the node */ +#define OF_POPULATED_BUS 4 /* of_platform_populate recursed to children of this node */ #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags) #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags) diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h index d96e1badbee0..c2b0627a2317 100644 --- a/include/linux/of_platform.h +++ b/include/linux/of_platform.h @@ -72,7 +72,7 @@ extern int of_platform_populate(struct device_node *root, const struct of_device_id *matches, const struct of_dev_auxdata *lookup, struct device *parent); -extern int of_platform_depopulate(struct device *parent); +extern void of_platform_depopulate(struct device *parent); #else static inline int of_platform_populate(struct device_node *root, const struct of_device_id *matches, @@ -81,10 +81,7 @@ static inline int of_platform_populate(struct device_node *root, { return -ENODEV; } -static inline int of_platform_depopulate(struct device *parent) -{ - return -ENODEV; -} +static inline void of_platform_depopulate(struct device *parent) { } #endif #endif /* _LINUX_OF_PLATFORM_H */