From patchwork Wed Mar 22 17:33:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 9639621 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 D000C6020B for ; Wed, 22 Mar 2017 17:34:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8B642841F for ; Wed, 22 Mar 2017 17:34:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD56228460; Wed, 22 Mar 2017 17:34:09 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F3FE2841F for ; Wed, 22 Mar 2017 17:34:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965124AbdCVReH (ORCPT ); Wed, 22 Mar 2017 13:34:07 -0400 Received: from 8bytes.org ([81.169.241.247]:40664 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964998AbdCVRdm (ORCPT ); Wed, 22 Mar 2017 13:33:42 -0400 Received: by theia.8bytes.org (Postfix, from userid 1000) id E4770236; Wed, 22 Mar 2017 18:33:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1490204013; bh=JTvUuc6cELWg+m0awNMda/PtT9H4HkCHOZa7H11qTdA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E4xu1qAbAjaSSoupandLsrKqfQ1ZpI+HqFbO8uQsBULGKfJKtdJ21YxrGnf5wXMN+ 5CMINAgYMBy6XFZJkmXxbS1XrYZlqoXSSBbtS2wkDaL8JBZty9HZAkokqRw3SsaNN8 qQEkvYG/kLCAqRVqanuYTGmS/fGEWvjqQPboxBUWp/pfdxs2Zz/NXYTBn6LWR+lDjn 8J1CPPGwGYOQgX28iecWfkomhHFap5Zvbe66eFw8qOpY4m26TtDJckG9u8oWVCwlXs 9By0t8feUc0OCIwwqej5/z+tu3tCt6vbb/EJg3VL3xfii8boQO25GUnfFAFkLRmSSd iklnTiG4k8fTg== From: Joerg Roedel To: "Rafael J. Wysocki" , Len Brown Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Joerg Roedel Subject: [PATCH 2/3] ACPI: Remove platform devices from a bus on removal Date: Wed, 22 Mar 2017 18:33:24 +0100 Message-Id: <1490204005-2733-3-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1490204005-2733-1-git-send-email-joro@8bytes.org> References: <1490204005-2733-1-git-send-email-joro@8bytes.org> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Joerg Roedel The function acpi_bus_attach() creates platform_devices if this is specified by the firmware. But in acpi_bus_trim() these devices are not removed, leaving a dangling reference to the parent device. In the case of a PCI root-bus, this results in the host_bridge device not being released on hot-remove. Fix it by scanning the list of platform_devices for devices to be removed with the bus. Signed-off-by: Joerg Roedel --- drivers/acpi/scan.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 1926918..b07518b 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -13,6 +13,7 @@ #include #include #include +#include #include @@ -1928,6 +1929,25 @@ int acpi_bus_scan(acpi_handle handle) EXPORT_SYMBOL(acpi_bus_scan); /** + * acpi_bus_trim_platform_device - Check and remove a platform device + * from a bus + * @dev: Platform device to check + * @data: pointer to the acpi_device to check dev against + * + * Checks whether the platform_device dev belongs to the acpi_device + * data and unregisters dev if it matches. + */ +static int acpi_bus_trim_platform_device(struct device *dev, void *data) +{ + struct acpi_device *adev = data; + + if (dev->fwnode == acpi_fwnode_handle(adev)) + platform_device_unregister(to_platform_device(dev)); + + return 0; +} + +/** * acpi_bus_trim - Detach scan handlers and drivers from ACPI device objects. * @adev: Root of the ACPI namespace scope to walk. * @@ -1950,6 +1970,12 @@ void acpi_bus_trim(struct acpi_device *adev) } else { device_release_driver(&adev->dev); } + + /* Remove platform devices from the bus */ + if (adev->pnp.type.platform_id) + bus_for_each_dev(&platform_bus_type, NULL, adev, + acpi_bus_trim_platform_device); + /* * Most likely, the device is going away, so put it into D3cold before * that.