From patchwork Fri Sep 2 08:22:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 9310553 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 92FA260756 for ; Fri, 2 Sep 2016 08:23:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85ED92970C for ; Fri, 2 Sep 2016 08:23:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7AF442970E; Fri, 2 Sep 2016 08:23:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 269E52970C for ; Fri, 2 Sep 2016 08:23:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BAAF06EA36; Fri, 2 Sep 2016 08:23:22 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id D44956EA30 for ; Fri, 2 Sep 2016 08:23:20 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id i138so1840531wmf.3 for ; Fri, 02 Sep 2016 01:23:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OD5ac+b20lGyAI6vdTKI4wT6gp4LYShrJFrUt61/zkg=; b=lGOF0yS3DXv+UjaGCNq9LaArR/CCgO0pvORAnRcJT/6ACUDcytOqfNmNt3uHQ4t4EL Qt+dcmSFx5J+ptj1VJ8ORR9jeiM6b8FKweP9EaPKxPqi1E0Jh9BxKp9D3Lfu2GKG8R5K QtOcOYWB7jwaLaJHDUoOqikQ24+cZ1cR7+CO6QNGSZdc9YjhikEJ3iCFJnNm6i1IF3Sc UwW/FB82cIgKfxTMu9oXvQ49HjGjXA4+l4p1+04Fvk6UZnkjCPweWT1atsmeDrTszXVV JZuPnMuEWCq27pOCg7aDWilq4O4OELG4x1qapJdk68f3bpJBYeT90zrqwzuSNBqyJogQ hqag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OD5ac+b20lGyAI6vdTKI4wT6gp4LYShrJFrUt61/zkg=; b=MFV9nu2FYbjcQ5hzKW+gfVY6+aluRMwscLDpv0enMq2zDG3iTtTiVZXZgSMzkbPv1R GK7KAXexlJ7SMKjiJi8sCdKy+0ym1sCSx3RXZ+IpRuQvmudtUibPS/U+btA5bt1Fl4Em vARUJUg0C9kYBa5gUD9QxR3x/QLrhlmSJorRNfwAOGB8ucIn/qMrVrZJ45eNrnRiZ9DO GoxvXY5fP5TfFOAjY5kQztAtMvgr0gw4AfsgWF80ICLe4MvVJqBOD0mC/aS+8x3iyDdJ b0Wm9EHT4n5xef6w2cJ1xq7XdHzxPr8AEcysNmePgzYs2LQrhdBXI9JkLyDFIE5efB+w +aWQ== X-Gm-Message-State: AE9vXwND7fUcmNLNtZ3dDihzkXFjLjkuvPNQxSjt73H+H9efP4klXn6KNsiqGjqx8FAOPA== X-Received: by 10.28.238.87 with SMTP id m84mr1945622wmh.44.1472804599495; Fri, 02 Sep 2016 01:23:19 -0700 (PDT) Received: from localhost.localdomain ([37.120.93.201]) by smtp.gmail.com with ESMTPSA id gg10sm9325662wjd.4.2016.09.02.01.23.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Sep 2016 01:23:18 -0700 (PDT) From: David Herrmann To: dri-devel@lists.freedesktop.org Subject: [PATCH v5 3/7] of/platform: expose of_platform_device_destroy() Date: Fri, 2 Sep 2016 10:22:41 +0200 Message-Id: <20160902082245.7119-4-dh.herrmann@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160902082245.7119-1-dh.herrmann@gmail.com> References: <20160902082245.7119-1-dh.herrmann@gmail.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP We already expose of_platform_device_create(), but give the caller no chance to revert its effect. Make sure we also provide the counterpart of_platform_device_destroy(). This requires a small refactoring, since so far the internal destructor is used as iterator to for_each_device(), but we don't want to expose it with the "void *data" parameter. So provide of_platform_device_depopulate() as new iterator, which calls into of_platform_device_destroy(). While at it, drop the unused 'children_left' argument by of_platform_notify(). It is a left-over that somehow was never removed. Signed-off-by: David Herrmann Reviewed-by: Tom Gundersen --- drivers/of/platform.c | 35 ++++++++++++++++++++++++++--------- include/linux/of_platform.h | 1 + 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index f39ccd5..f9bb563 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -524,15 +524,18 @@ static int __init of_platform_default_populate_init(void) arch_initcall_sync(of_platform_default_populate_init); #endif -static int of_platform_device_destroy(struct device *dev, void *data) +/** + * of_platform_device_destroy - unregister an of_device + * @dev: device to unregister + * + * This is the inverse operation of of_platform_device_create(). It unregisters + * the passed device, if registered. + */ +void of_platform_device_destroy(struct device *dev) { /* Do not touch devices not populated from the device tree */ if (!dev->of_node || !of_node_check_flag(dev->of_node, OF_POPULATED)) - 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); + return; if (dev->bus == &platform_bus_type) platform_device_unregister(to_platform_device(dev)); @@ -544,6 +547,20 @@ static int of_platform_device_destroy(struct device *dev, void *data) of_dma_deconfigure(dev); of_node_clear_flag(dev->of_node, OF_POPULATED); of_node_clear_flag(dev->of_node, OF_POPULATED_BUS); +} +EXPORT_SYMBOL(of_platform_device_destroy); + +static int of_platform_device_depopulate(struct device *dev, void *data) +{ + /* Do not touch devices not populated from the device tree */ + if (!dev->of_node || !of_node_check_flag(dev->of_node, OF_POPULATED)) + 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_depopulate); + + of_platform_device_destroy(dev); return 0; } @@ -562,7 +579,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(parent, NULL, + of_platform_device_depopulate); of_node_clear_flag(parent->of_node, OF_POPULATED_BUS); } } @@ -574,7 +592,6 @@ static int of_platform_notify(struct notifier_block *nb, { struct of_reconfig_data *rd = arg; struct platform_device *pdev_parent, *pdev; - bool children_left; switch (of_reconfig_get_state_change(action, rd)) { case OF_RECONFIG_CHANGE_ADD: @@ -612,7 +629,7 @@ static int of_platform_notify(struct notifier_block *nb, return NOTIFY_OK; /* no? not meant for us */ /* unregister takes one ref away */ - of_platform_device_destroy(&pdev->dev, &children_left); + of_platform_device_depopulate(&pdev->dev, NULL); /* and put the reference of the find */ of_dev_put(pdev); diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h index 956a100..a9017d3 100644 --- a/include/linux/of_platform.h +++ b/include/linux/of_platform.h @@ -63,6 +63,7 @@ extern struct platform_device *of_find_device_by_node(struct device_node *np); extern struct platform_device *of_platform_device_create(struct device_node *np, const char *bus_id, struct device *parent); +extern void of_platform_device_destroy(struct device *dev); extern int of_platform_bus_probe(struct device_node *root, const struct of_device_id *matches,