From patchwork Wed Jan 7 17:30:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suman Anna X-Patchwork-Id: 5586341 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2168A9F357 for ; Wed, 7 Jan 2015 17:38:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4215920279 for ; Wed, 7 Jan 2015 17:38:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4EA062008F for ; Wed, 7 Jan 2015 17:38:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754462AbbAGRba (ORCPT ); Wed, 7 Jan 2015 12:31:30 -0500 Received: from arroyo.ext.ti.com ([192.94.94.40]:45245 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754405AbbAGRb1 (ORCPT ); Wed, 7 Jan 2015 12:31:27 -0500 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id t07HUuin016430; Wed, 7 Jan 2015 11:30:56 -0600 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id t07HUtsF005877; Wed, 7 Jan 2015 11:30:56 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.174.1; Wed, 7 Jan 2015 11:30:55 -0600 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id t07HUtDp021074; Wed, 7 Jan 2015 11:30:55 -0600 Received: from localhost (irmo.am.dhcp.ti.com [128.247.71.175]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id t07HUtt10073; Wed, 7 Jan 2015 11:30:55 -0600 (CST) From: Suman Anna To: Grant Likely , Rob Herring CC: Greg Kroah-Hartman , Pawel Moll , Pantelis Antoniou , Felipe Balbi , , , , , Suman Anna Subject: [RFC PATCH 1/3] of/device: manage resources similar to platform_device_add Date: Wed, 7 Jan 2015 11:30:52 -0600 Message-ID: <1420651854-17768-2-git-send-email-s-anna@ti.com> X-Mailer: git-send-email 2.2.1 In-Reply-To: <1420651854-17768-1-git-send-email-s-anna@ti.com> References: <1420651854-17768-1-git-send-email-s-anna@ti.com> MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 Drivers can use of_platform_populate() to create platform devices for children of the device main node, and a complementary API of_platform_depopulate() is provided to delete these child platform devices. The of_platform_depopulate() leverages the platform API for performing the cleanup of these devices. The platform device resources are managed differently between of_device_add and platform_device_add, and this asymmetry causes a kernel oops in platform_device_del during removal of the resources. Manage the platform device resources similar to platform_device_add to fix this kernel oops. Signed-off-by: Suman Anna --- drivers/of/device.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index 46d6c75c1404..fa27c1c71f29 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -50,6 +50,8 @@ EXPORT_SYMBOL(of_dev_put); int of_device_add(struct platform_device *ofdev) { + int i, ret; + BUG_ON(ofdev->dev.of_node == NULL); /* name and id have to be set so that the platform bus doesn't get @@ -63,7 +65,41 @@ int of_device_add(struct platform_device *ofdev) if (!ofdev->dev.parent) set_dev_node(&ofdev->dev, of_node_to_nid(ofdev->dev.of_node)); - return device_add(&ofdev->dev); + for (i = 0; i < ofdev->num_resources; i++) { + struct resource *p, *r = &ofdev->resource[i]; + + if (!r->name) + r->name = dev_name(&ofdev->dev); + + p = r->parent; + if (!p) { + if (resource_type(r) == IORESOURCE_MEM) + p = &iomem_resource; + else if (resource_type(r) == IORESOURCE_IO) + p = &ioport_resource; + } + + if (p && insert_resource(p, r)) { + dev_err(&ofdev->dev, "failed to claim resource %d\n", + i); + ret = -EBUSY; + goto failed; + } + } + + ret = device_add(&ofdev->dev); + if (ret == 0) + return ret; + +failed: + while (--i >= 0) { + struct resource *r = &ofdev->resource[i]; + unsigned long type = resource_type(r); + + if (type == IORESOURCE_MEM || type == IORESOURCE_IO) + release_resource(r); + } + return ret; } int of_device_register(struct platform_device *pdev)