From patchwork Wed Jan 7 15:29:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Pieralisi X-Patchwork-Id: 5585231 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@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 C99D59F665 for ; Wed, 7 Jan 2015 15:29:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 08F7A20219 for ; Wed, 7 Jan 2015 15:29:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 783052024C for ; Wed, 7 Jan 2015 15:29:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753101AbbAGP3y (ORCPT ); Wed, 7 Jan 2015 10:29:54 -0500 Received: from foss-mx-na.foss.arm.com ([217.140.108.86]:56837 "EHLO foss-mx-na.foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752584AbbAGP3x (ORCPT ); Wed, 7 Jan 2015 10:29:53 -0500 Received: from foss-smtp-na-1.foss.arm.com (unknown [10.80.61.8]) by foss-mx-na.foss.arm.com (Postfix) with ESMTP id 2F5234E1; Wed, 7 Jan 2015 09:29:50 -0600 (CST) Received: from collaborate-mta1.arm.com (highbank-bc01-b06.austin.arm.com [10.112.81.134]) by foss-smtp-na-1.foss.arm.com (Postfix) with ESMTP id ACE595FAD8; Wed, 7 Jan 2015 09:29:42 -0600 (CST) Received: from red-moon.cambridge.arm.com (red-moon.cambridge.arm.com [10.1.203.137]) by collaborate-mta1.arm.com (Postfix) with ESMTP id 5805213F78C; Wed, 7 Jan 2015 09:29:41 -0600 (CST) From: Lorenzo Pieralisi To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: Lorenzo Pieralisi , Arnd Bergmann , Liviu Dudau , Mohit Kumar , Jingoo Han , Bjorn Helgaas , Rob Herring Subject: [RFC PATCH 1/3] drivers: of: fix resources freeing in of_pci_get_host_bridge_resources() Date: Wed, 7 Jan 2015 15:29:29 +0000 Message-Id: <1420644571-18928-2-git-send-email-lorenzo.pieralisi@arm.com> X-Mailer: git-send-email 2.2.1 In-Reply-To: <1420644571-18928-1-git-send-email-lorenzo.pieralisi@arm.com> References: <1420644571-18928-1-git-send-email-lorenzo.pieralisi@arm.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@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=ham 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 In the function of_pci_get_host_bridge_resources() if the parsing of ranges fails, previously allocated resources inclusive of bus_range are not freed and are not expected to be freed by the function caller on error return. This patch fixes the issues by adding code that properly frees resources and bus_range before exiting the function with an error return value. Cc: Arnd Bergmann Cc: Liviu Dudau Cc: Bjorn Helgaas Cc: Rob Herring Signed-off-by: Lorenzo Pieralisi Acked-by: Liviu Dudau --- drivers/of/of_pci.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c index 88471d3..6fbfe99 100644 --- a/drivers/of/of_pci.c +++ b/drivers/of/of_pci.c @@ -146,6 +146,7 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, struct of_pci_range_parser parser; char range_type[4]; int err; + struct pci_host_bridge_window *window; if (io_base) *io_base = (resource_size_t)OF_BAD_ADDR; @@ -225,7 +226,10 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, conversion_failed: kfree(res); parse_failed: + list_for_each_entry(window, resources, list) + kfree(window->res); pci_free_resource_list(resources); + kfree(bus_range); return err; } EXPORT_SYMBOL_GPL(of_pci_get_host_bridge_resources);