From patchwork Fri Dec 13 22:24:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 22395 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f71.google.com (mail-qa0-f71.google.com [209.85.216.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 974F223FBA for ; Fri, 13 Dec 2013 22:26:55 +0000 (UTC) Received: by mail-qa0-f71.google.com with SMTP id o15sf2636613qap.2 for ; Fri, 13 Dec 2013 14:26:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=/5CRBhA2YuXEjuCEq2oiaF3pcg/Bl9no1KuZE9ZvJEA=; b=Kk4zXJZDKPuxhnJuuHHsOPYBTqw5alxRIzZRIf8wFVFvP2cC2HYL4s6xXTiABx6+wk tp/B5XLn5pWC/RZeUamM/YSDhOVx/bisvDQTJ8tYCh5xYv4Y/r248+MdbG519V1W7vmy Dvg9Dw+DX+o7ZqAKXYpfo/u124KAu6EKvwEaZqgEh4MGig5t44dxJwyiEGJ/Q9eADKhH FnIdBbLK7/i6dSDINeFsYmV/s4t0Jmn+SvnqYfEfsbGLifUi6yIhi3dm43ZnCyOVZBM6 wkp/Qf/4hd5ayeAoE5rdR0fGbJCcxG3mhW5MKlWw3vv21gT4qelrg7mCBPi4t2boC5pS I6cA== X-Gm-Message-State: ALoCoQmUE4fovlfYogYaQPEZ/21Kway4aqBSW91VlxM9AFRt7Q6eWztr88zEb3N52/EVh8NA06gh X-Received: by 10.236.209.134 with SMTP id s6mr1501076yho.40.1386973615458; Fri, 13 Dec 2013 14:26:55 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.120.5 with SMTP id ky5ls1237356qeb.26.gmail; Fri, 13 Dec 2013 14:26:55 -0800 (PST) X-Received: by 10.58.95.97 with SMTP id dj1mr2192520veb.21.1386973615361; Fri, 13 Dec 2013 14:26:55 -0800 (PST) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by mx.google.com with ESMTPS id pu5si1203012veb.21.2013.12.13.14.26.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:26:55 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.175; Received: by mail-ve0-f175.google.com with SMTP id jx11so1826894veb.34 for ; Fri, 13 Dec 2013 14:26:55 -0800 (PST) X-Received: by 10.52.0.9 with SMTP id 9mr1832194vda.47.1386973615260; Fri, 13 Dec 2013 14:26:55 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp73501vcz; Fri, 13 Dec 2013 14:26:54 -0800 (PST) X-Received: by 10.68.66.103 with SMTP id e7mr6053911pbt.120.1386973614457; Fri, 13 Dec 2013 14:26:54 -0800 (PST) Received: from mail-pb0-f44.google.com (mail-pb0-f44.google.com [209.85.160.44]) by mx.google.com with ESMTPS id sl10si2513250pab.70.2013.12.13.14.26.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:26:54 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.44 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.160.44; Received: by mail-pb0-f44.google.com with SMTP id rq2so3132198pbb.31 for ; Fri, 13 Dec 2013 14:26:53 -0800 (PST) X-Received: by 10.68.252.161 with SMTP id zt1mr6095917pbc.130.1386973613318; Fri, 13 Dec 2013 14:26:53 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id qz9sm7457908pbc.3.2013.12.13.14.26.51 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:26:52 -0800 (PST) From: John Stultz To: LKML Cc: Greg KH , Android Kernel Team , Sumit Semwal , Jesse Barker , Colin Cross , Rebecca Schultz Zavin , John Stultz Subject: [PATCH 030/115] gpu: ion: Fix memory leak of dirty bits Date: Fri, 13 Dec 2013 14:24:04 -0800 Message-Id: <1386973529-4884-31-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1386973529-4884-1-git-send-email-john.stultz@linaro.org> References: <1386973529-4884-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Rebecca Schultz Zavin Signed-off-by: Rebecca Schultz Zavin [jstultz: modified patch to apply to staging directory] Signed-off-by: John Stultz --- drivers/staging/android/ion/ion.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 6ba2c39..3aeb41c 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -164,24 +164,20 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, return ERR_PTR(PTR_ERR(table)); } buffer->sg_table = table; - if (buffer->flags & ION_FLAG_CACHED) + if (buffer->flags & ION_FLAG_CACHED) { for_each_sg(buffer->sg_table->sgl, sg, buffer->sg_table->nents, i) { if (sg_dma_len(sg) == PAGE_SIZE) continue; pr_err("%s: cached mappings must have pagewise " "sg_lists\n", __func__); - heap->ops->unmap_dma(heap, buffer); - kfree(buffer); - return ERR_PTR(-EINVAL); + ret = -EINVAL; + goto err; } - ret = ion_buffer_alloc_dirty(buffer); - if (ret) { - heap->ops->unmap_dma(heap, buffer); - heap->ops->free(buffer); - kfree(buffer); - return ERR_PTR(ret); + ret = ion_buffer_alloc_dirty(buffer); + if (ret) + goto err; } buffer->dev = dev; @@ -200,6 +196,12 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, sg_dma_address(sg) = sg_phys(sg); ion_buffer_add(dev, buffer); return buffer; + +err: + heap->ops->unmap_dma(heap, buffer); + heap->ops->free(buffer); + kfree(buffer); + return ERR_PTR(ret); } static void ion_buffer_destroy(struct kref *kref) @@ -209,12 +211,13 @@ static void ion_buffer_destroy(struct kref *kref) if (WARN_ON(buffer->kmap_cnt > 0)) buffer->heap->ops->unmap_kernel(buffer->heap, buffer); - buffer->heap->ops->unmap_dma(buffer->heap, buffer); buffer->heap->ops->free(buffer); mutex_lock(&dev->lock); rb_erase(&buffer->node, &dev->buffers); mutex_unlock(&dev->lock); + if (buffer->flags & ION_FLAG_CACHED) + kfree(buffer->dirty); kfree(buffer); }