From patchwork Fri Dec 6 03:21:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 3292721 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7DBA09F386 for ; Fri, 6 Dec 2013 03:23:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AEF2D200CA for ; Fri, 6 Dec 2013 03:23:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 74C50204EB for ; Fri, 6 Dec 2013 03:23:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757024Ab3LFDXa (ORCPT ); Thu, 5 Dec 2013 22:23:30 -0500 Received: from mga03.intel.com ([143.182.124.21]:56623 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755722Ab3LFDVS (ORCPT ); Thu, 5 Dec 2013 22:21:18 -0500 Received: from azsmga002.ch.intel.com ([10.2.17.35]) by azsmga101.ch.intel.com with ESMTP; 05 Dec 2013 19:21:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.93,838,1378882800"; d="scan'208";a="325986963" Received: from gerry-dev.bj.intel.com ([10.238.158.74]) by AZSMGA002.ch.intel.com with ESMTP; 05 Dec 2013 19:21:14 -0800 From: Jiang Liu To: Joerg Roedel , David Woodhouse , Dan Williams , Vinod Koul , Ashok Raj , Yijing Wang , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: Jiang Liu , Tony Luck , Yinghai Lu , linux-pci@vger.kernel.org, dmaengine@vger.kernel.org Subject: [Patch Part1 V2 14/20] iommu/vt-d: avoid double free in error recovery path Date: Fri, 6 Dec 2013 11:21:17 +0800 Message-Id: <1386300083-6882-15-git-send-email-jiang.liu@linux.intel.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1386300083-6882-1-git-send-email-jiang.liu@linux.intel.com> References: <1386300083-6882-1-git-send-email-jiang.liu@linux.intel.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, 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 The g_iommus array will be freed twice when failed to initialize IOMMU devices, which will cause system panic. Signed-off-by: Jiang Liu --- drivers/iommu/intel-iommu.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index cbdb1ff..1a20171 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -1293,19 +1293,10 @@ static void free_dmar_iommu(struct intel_iommu *iommu) iommu->domains = NULL; iommu->domain_ids = NULL; - g_iommus[iommu->seq_id] = NULL; - - /* if all iommus are freed, free g_iommus */ - for (i = 0; i < g_num_of_iommus; i++) { - if (g_iommus[i]) - break; - } - - if (i == g_num_of_iommus) - kfree(g_iommus); - /* free context mapping */ free_context_table(iommu); + + g_iommus[iommu->seq_id] = NULL; } static struct dmar_domain *alloc_domain(void) @@ -2621,6 +2612,7 @@ error: for_each_active_iommu(iommu, drhd) free_dmar_iommu(iommu); kfree(g_iommus); + g_iommus = NULL; return ret; }