From patchwork Sun Jul 3 11:26:47 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasiliy Kulikov X-Patchwork-Id: 103008 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id D73F6B6F64 for ; Sun, 3 Jul 2011 21:26:54 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751202Ab1GCL0x (ORCPT ); Sun, 3 Jul 2011 07:26:53 -0400 Received: from mail-bw0-f46.google.com ([209.85.214.46]:46434 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750999Ab1GCL0w (ORCPT ); Sun, 3 Jul 2011 07:26:52 -0400 Received: by bwd5 with SMTP id 5so3513410bwd.19 for ; Sun, 03 Jul 2011 04:26:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=+li9YaZoa/AzsYMJGq8kt0u1Rj+ZByYxYu4fXg+EGys=; b=DBgVPouBwpwYv/WJxP+breAjUb0jQio8NtiOJyR2rs3TDYg3ED4zq7L5bmkOi+dI9T NCg22ourBRikbTTxdxh/66ihk5Z3Yh0qGRxmvBGBzG5AavBVrfNTne+FyilsmAAs9Gx1 DP60090J9ufUnlZwcMs6MnMYNHvYqf1Fwo3CM= Received: by 10.204.41.206 with SMTP id p14mr4459750bke.53.1309692410964; Sun, 03 Jul 2011 04:26:50 -0700 (PDT) Received: from localhost (ppp85-140-45-147.pppoe.mtu-net.ru [85.140.45.147]) by mx.google.com with ESMTPS id ek1sm4615909bkb.9.2011.07.03.04.26.48 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 03 Jul 2011 04:26:50 -0700 (PDT) Date: Sun, 3 Jul 2011 15:26:47 +0400 From: Vasiliy Kulikov To: Jeff Garzik Cc: linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH -resend] ata: sata_dwc_460ex: fix error path Message-ID: <20110703112647.GA3769@albatros> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-ide-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org Fixed hsdev memleak on sata_dwc_probe() error. As dma_dwc_exit() can be called multiple times without sata_dma_regs and irq_dma changes, it might lead to double free on sequential dma_dwc_exit() calls. So, zero these fields after free calls. Signed-off-by: Vasiliy Kulikov --- drivers/ata/sata_dwc_460ex.c | 21 ++++++++++++++------- 1 files changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/ata/sata_dwc_460ex.c b/drivers/ata/sata_dwc_460ex.c index 1c4b3aa..6ca6f2c 100644 --- a/drivers/ata/sata_dwc_460ex.c +++ b/drivers/ata/sata_dwc_460ex.c @@ -766,11 +766,15 @@ static int dma_dwc_xfer_setup(struct scatterlist *sg, int num_elems, static void dma_dwc_exit(struct sata_dwc_device *hsdev) { dev_dbg(host_pvt.dwc_dev, "%s:\n", __func__); - if (host_pvt.sata_dma_regs) + if (host_pvt.sata_dma_regs) { iounmap(host_pvt.sata_dma_regs); + host_pvt.sata_dma_regs = NULL; + } - if (hsdev->irq_dma) + if (hsdev->irq_dma) { free_irq(hsdev->irq_dma, hsdev); + hsdev->irq_dma = 0; + } } /* @@ -1642,7 +1646,7 @@ static int sata_dwc_probe(struct platform_device *ofdev) if (hsdev == NULL) { dev_err(&ofdev->dev, "kmalloc failed for hsdev\n"); err = -ENOMEM; - goto error_out; + goto error; } memset(hsdev, 0, sizeof(*hsdev)); @@ -1652,7 +1656,7 @@ static int sata_dwc_probe(struct platform_device *ofdev) dev_err(&ofdev->dev, "ioremap failed for SATA register" " address\n"); err = -ENODEV; - goto error_out; + goto error_kmalloc; } hsdev->reg_base = base; dev_dbg(&ofdev->dev, "ioremap done for SATA register address\n"); @@ -1665,7 +1669,7 @@ static int sata_dwc_probe(struct platform_device *ofdev) if (!host) { dev_err(&ofdev->dev, "ata_host_alloc_pinfo failed\n"); err = -ENOMEM; - goto error_out; + goto error_iomap; } host->private_data = hsdev; @@ -1733,8 +1737,11 @@ error_out: /* Free SATA DMA resources */ dma_dwc_exit(hsdev); - if (base) - iounmap(base); +error_iomap: + iounmap(base); +error_kmalloc: + kfree(hsdev); +error: return err; }