From patchwork Fri Dec 13 22:24:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 22435 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f200.google.com (mail-ob0-f200.google.com [209.85.214.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4168723FBA for ; Fri, 13 Dec 2013 22:28:02 +0000 (UTC) Received: by mail-ob0-f200.google.com with SMTP id wm4sf8718441obc.11 for ; Fri, 13 Dec 2013 14:28:01 -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=/sDxSNp59riKTWr6SyoZEGmKcZlGBvev2yAKaf5c6Kg=; b=HTH504uS932BG3xzGkV9MA2C1fhLp2q+TDFbExBxo5Np4WecFh133j5aXWvxKQl0Yu MK1KsWpnrsaWqm64ZxLWIlO5RJz5nJ3tpTjQisvXRGbB/XNu5vtqfxBEfubHCeSSdfdq ovcSRdBFwPvbAxlRVOSGmynDgA9ti/A9TqtmH97jWYW4CRcuE4WptMVZSxTJ4p0xXKHp 9bOjiOTFq4bbyuOGx04qqhULqQJJmCKkOCJkT24SiWRfBoa5v+1ZUvNEdLYJFlaP4NvI 7UhrZG7tIweFlpht00J+BnwngN369rdDGMmVTr/oxUSwj87oOF1+nc0bTywfPmJz1Mf5 l9dQ== X-Gm-Message-State: ALoCoQnVJbafS50Q5TFgfh055FDIqfKPLBlp1/4rRTLUQrRfO08rPNYPdLSU/DgqR9FvhTEULV8f X-Received: by 10.50.17.101 with SMTP id n5mr2268813igd.2.1386973681876; Fri, 13 Dec 2013 14:28:01 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.71.142 with SMTP id v14ls1233403qeu.35.gmail; Fri, 13 Dec 2013 14:28:01 -0800 (PST) X-Received: by 10.58.96.15 with SMTP id do15mr2193013veb.56.1386973681593; Fri, 13 Dec 2013 14:28:01 -0800 (PST) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id v13si1188435vcp.146.2013.12.13.14.28.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:28:01 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id ij19so1746738vcb.31 for ; Fri, 13 Dec 2013 14:28:01 -0800 (PST) X-Received: by 10.58.255.233 with SMTP id at9mr2260835ved.20.1386973681499; Fri, 13 Dec 2013 14:28:01 -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 u4csp73593vcz; Fri, 13 Dec 2013 14:28:01 -0800 (PST) X-Received: by 10.66.189.229 with SMTP id gl5mr6027566pac.47.1386973680830; Fri, 13 Dec 2013 14:28:00 -0800 (PST) Received: from mail-pd0-f170.google.com (mail-pd0-f170.google.com [209.85.192.170]) by mx.google.com with ESMTPS id vb7si2522185pbc.32.2013.12.13.14.28.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:28:00 -0800 (PST) Received-SPF: neutral (google.com: 209.85.192.170 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.192.170; Received: by mail-pd0-f170.google.com with SMTP id g10so3030226pdj.15 for ; Fri, 13 Dec 2013 14:28:00 -0800 (PST) X-Received: by 10.68.106.130 with SMTP id gu2mr5954820pbb.59.1386973680450; Fri, 13 Dec 2013 14:28:00 -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.27.58 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:27:59 -0800 (PST) From: John Stultz To: LKML Cc: Greg KH , Android Kernel Team , Sumit Semwal , Jesse Barker , Colin Cross , John Stultz Subject: [PATCH 072/115] ion: chunk_heap: fix leak in allocated counter Date: Fri, 13 Dec 2013 14:24:46 -0800 Message-Id: <1386973529-4884-73-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.220.172 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: Colin Cross buffer->size is controlled by the outer ion layer, don't modify it inside the heap. Instead, compute the rounded up allocated size on demand. Signed-off-by: Colin Cross [jstultz: modified patch to apply to staging directory] Signed-off-by: John Stultz --- drivers/staging/android/ion/ion_chunk_heap.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/staging/android/ion/ion_chunk_heap.c b/drivers/staging/android/ion/ion_chunk_heap.c index 410c08e..85fefe7 100644 --- a/drivers/staging/android/ion/ion_chunk_heap.c +++ b/drivers/staging/android/ion/ion_chunk_heap.c @@ -47,15 +47,15 @@ static int ion_chunk_heap_allocate(struct ion_heap *heap, struct scatterlist *sg; int ret, i; unsigned long num_chunks; + unsigned long allocated_size; if (ion_buffer_fault_user_mappings(buffer)) return -ENOMEM; - num_chunks = ALIGN(size, chunk_heap->chunk_size) / - chunk_heap->chunk_size; - buffer->size = num_chunks * chunk_heap->chunk_size; + allocated_size = ALIGN(size, chunk_heap->chunk_size); + num_chunks = allocated_size / chunk_heap->chunk_size; - if (buffer->size > chunk_heap->size - chunk_heap->allocated) + if (allocated_size > chunk_heap->size - chunk_heap->allocated) return -ENOMEM; table = kzalloc(sizeof(struct sg_table), GFP_KERNEL); @@ -78,7 +78,7 @@ static int ion_chunk_heap_allocate(struct ion_heap *heap, } buffer->priv_virt = table; - chunk_heap->allocated += buffer->size; + chunk_heap->allocated += allocated_size; return 0; err: sg = table->sgl; @@ -100,6 +100,9 @@ static void ion_chunk_heap_free(struct ion_buffer *buffer) struct sg_table *table = buffer->priv_virt; struct scatterlist *sg; int i; + unsigned long allocated_size; + + allocated_size = ALIGN(buffer->size, chunk_heap->chunk_size); ion_heap_buffer_zero(buffer); @@ -111,7 +114,7 @@ static void ion_chunk_heap_free(struct ion_buffer *buffer) gen_pool_free(chunk_heap->pool, page_to_phys(sg_page(sg)), sg_dma_len(sg)); } - chunk_heap->allocated -= buffer->size; + chunk_heap->allocated -= allocated_size; sg_free_table(table); kfree(table); }