From patchwork Sun Sep 22 11:57:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Mack X-Patchwork-Id: 2924221 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 01C3A9F476 for ; Sun, 22 Sep 2013 11:58:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6967220439 for ; Sun, 22 Sep 2013 11:58:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9723F20164 for ; Sun, 22 Sep 2013 11:58:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753056Ab3IVL6Y (ORCPT ); Sun, 22 Sep 2013 07:58:24 -0400 Received: from svenfoo.org ([82.94.215.22]:58123 "EHLO mail.zonque.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753035Ab3IVL6J (ORCPT ); Sun, 22 Sep 2013 07:58:09 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.zonque.de (Postfix) with ESMTP id 07EF8C1714; Sun, 22 Sep 2013 13:58:07 +0200 (CEST) Received: from mail.zonque.de ([127.0.0.1]) by localhost (rambrand.bugwerft.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HTDIK3tn-lZn; Sun, 22 Sep 2013 13:58:06 +0200 (CEST) Received: from tamtam.fritz.box (p5DDC784F.dip0.t-ipconnect.de [93.220.120.79]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.zonque.de (Postfix) with ESMTPSA id 39F98C1696; Sun, 22 Sep 2013 13:58:05 +0200 (CEST) From: Daniel Mack To: linux-usb@vger.kernel.org Cc: linux-omap@vger.kernel.org, neumann@teufel.de, bigeasy@linutronix.de, vinod.koul@intel.com, dan.j.williams@intel.com, balbi@ti.com, gregkh@linuxfoundation.org, Daniel Mack Subject: [PATCH v2 4/5] dma: cppi41: only allocate descriptor memory once Date: Sun, 22 Sep 2013 13:57:47 +0200 Message-Id: <1379851068-18675-5-git-send-email-zonque@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1379851068-18675-1-git-send-email-zonque@gmail.com> References: <1379851068-18675-1-git-send-email-zonque@gmail.com> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Spam-Status: No, score=-9.2 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,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 cdd->cd and cdd->descs_phys are allocated DESCS_AREAS times from init_descs() and freed as often from purge_descs(). This leads to both memory leaks and double-frees. Fix this by pulling the calls to dma_{alloc,free}_coherent() out of the loops. While at it, remove the intermediate variable mem_decs (I guess it was only there to make the code comply to the 80-chars CodingSytle rule). Signed-off-by: Daniel Mack --- drivers/dma/cppi41.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/drivers/dma/cppi41.c b/drivers/dma/cppi41.c index d689706..3347321 100644 --- a/drivers/dma/cppi41.c +++ b/drivers/dma/cppi41.c @@ -727,13 +727,12 @@ static void purge_descs(struct device *dev, struct cppi41_dd *cdd) mem_decs = ALLOC_DECS_NUM * sizeof(struct cppi41_desc); for (i = 0; i < DESCS_AREAS; i++) { - cppi_writel(0, cdd->qmgr_mem + QMGR_MEMBASE(i)); cppi_writel(0, cdd->qmgr_mem + QMGR_MEMCTRL(i)); - - dma_free_coherent(dev, mem_decs, cdd->cd, - cdd->descs_phys); } + + dma_free_coherent(dev, ALLOC_DECS_NUM * sizeof(struct cppi41_desc), + cdd->cd, cdd->descs_phys); } static void disable_sched(struct cppi41_dd *cdd) @@ -755,8 +754,7 @@ static void deinit_cppi41(struct device *dev, struct cppi41_dd *cdd) static int init_descs(struct device *dev, struct cppi41_dd *cdd) { - unsigned int desc_size; - unsigned int mem_decs; + unsigned int desc_size = sizeof(struct cppi41_desc); int i; u32 reg; u32 idx; @@ -765,28 +763,25 @@ static int init_descs(struct device *dev, struct cppi41_dd *cdd) (sizeof(struct cppi41_desc) - 1)); BUILD_BUG_ON(sizeof(struct cppi41_desc) < 32); BUILD_BUG_ON(ALLOC_DECS_NUM < 32); + BUILD_BUG_ON(DESCS_AREAS != 1); - desc_size = sizeof(struct cppi41_desc); - mem_decs = ALLOC_DECS_NUM * desc_size; + cdd->cd = dma_alloc_coherent(dev, ALLOC_DECS_NUM * desc_size, + &cdd->descs_phys, GFP_KERNEL); + if (!cdd->cd) + return -ENOMEM; idx = 0; for (i = 0; i < DESCS_AREAS; i++) { - reg = idx << QMGR_MEMCTRL_IDX_SH; reg |= (ilog2(desc_size) - 5) << QMGR_MEMCTRL_DESC_SH; reg |= ilog2(ALLOC_DECS_NUM) - 5; - BUILD_BUG_ON(DESCS_AREAS != 1); - cdd->cd = dma_alloc_coherent(dev, mem_decs, - &cdd->descs_phys, GFP_KERNEL); - if (!cdd->cd) - return -ENOMEM; - cppi_writel(cdd->descs_phys, cdd->qmgr_mem + QMGR_MEMBASE(i)); cppi_writel(reg, cdd->qmgr_mem + QMGR_MEMCTRL(i)); idx += ALLOC_DECS_NUM; } + return 0; }