staging: ion: Fix error handling in ion_buffer_create
PATCH 1/1 staging: ion: Fix error handling in ion_buffer_create
This patch fixes error handling case when buffer->pages allocation fails. Also, it removes unreachable code of checking ret variable although it is not updated.
--- drivers/staging/android/ion/ion.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/staging/android/ion/ion.c +5 -9
@@ -213,10 +213,10 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, "heap->ops->map_dma should return ERR_PTR on error")) table =ERR_PTR (-EINVAL );if (IS_ERR (table)) { - heap->ops->free (buffer); -kfree (buffer); -return ERR_CAST (table); + ret = -EINVAL ; + goto err1; } + buffer->sg_table = table;if (ion_buffer_fault_user_mappings (buffer)) {int num_pages =PAGE_ALIGN (buffer->size) /PAGE_SIZE ;
@@ -226,7 +226,7 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, buffer->pages =vmalloc (sizeof (struct page *) * num_pages);if (!buffer->pages) { ret = -ENOMEM ; - goto err1; + goto err; }for_each_sg (table->sgl, sg, table->nents, i) {
@@ -235,9 +235,6 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,for (j =0 ; j < sg->length /PAGE_SIZE ; j++) buffer->pages[k++] = page++; } - -if (ret) - goto err; } buffer->dev = dev;
@@ -261,9 +258,8 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, err: heap->ops->unmap_dma (heap, buffer); - heap->ops->free (buffer); err1: -vfree (buffer->pages); + heap->ops->free (buffer); err2:kfree (buffer);return ERR_PTR (ret);
Signature · 1 line
1.7.9.5
Quoted 4 lines · Rohit kumar
This patch fixes error handling case when
buffer->pagesallocation fails. Also, it removes unreachable code of checking ret variable although it is not updated.
Quoted 54 lines
Signed-off-by Rohit kumar <[email protected]>--- drivers/staging/android/ion/ion.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)drivers/staging/android/ion/ion.c +5
-9@@ -213,10 +213,10 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, "heap->ops->map_dma should return ERR_PTR on error")) table =ERR_PTR (-EINVAL );if (IS_ERR (table)) { - heap->ops->free (buffer); -kfree (buffer); -return ERR_CAST (table); + ret = -EINVAL ; + goto err1; } + buffer->sg_table = table;if (ion_buffer_fault_user_mappings (buffer)) {int num_pages =PAGE_ALIGN (buffer->size) /PAGE_SIZE ;@@ -226,7 +226,7 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, buffer->pages =vmalloc (sizeof (struct page *) * num_pages);if (!buffer->pages) { ret = -ENOMEM ; - goto err1; + goto err; }for_each_sg (table->sgl, sg, table->nents, i) {@@ -235,9 +235,6 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,for (j =0 ; j < sg->length /PAGE_SIZE ; j++) buffer->pages[k++] = page++; } - -if (ret) - goto err; } buffer->dev = dev;@@ -261,9 +258,8 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, err: heap->ops->unmap_dma (heap, buffer); - heap->ops->free (buffer); err1: -vfree (buffer->pages); + heap->ops->free (buffer); err2:kfree (buffer);return ERR_PTR (ret);
PINTU KUMAR
Reviewed-byQuoted 73 lines
-----Original Message-----
From: Laura Abbott [mailto:[email protected]]
Sent: Wednesday, September 30, 2015 11:42 PM
To: Rohit kumar; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; akpm@linux- foundation.org; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/1] staging: ion: Fix error handling inion_buffer_createQuoted 4 lines · Rohit kumar
This patch fixes error handling case when
buffer->pagesallocation fails. Also, it removes unreachable code of checking ret variable although it is not updated.Reviewed-by Laura Abbott <[email protected]>drivers/staging/android/ion/ion.c static struct ion_buffer *ion_buffer_create(struct
Quoted 11 lines
Signed-off-by Rohit kumar <[email protected]>--- drivers/staging/android/ion/ion.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)drivers/staging/android/ion/ion.c +0
-0@@ -213,10 +213,10 @@ static struct ion_buffer *ion_buffer_create(struct
ion_heap*heap,drivers/staging/android/ion/ion.c static struct ion_buffer *ion_buffer_create(struct · line 213
Quoted 1 line
drivers/staging/android/ion/ion.c +0
-0"heap->ops->map_dma should return ERR_PTR onerror"))
drivers/staging/android/ion/ion.c static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
Quoted 12 lines
drivers/staging/android/ion/ion.c +3
-3table =ERR_PTR (-EINVAL );if (IS_ERR (table)) { - heap->ops->free (buffer); -kfree (buffer); -return ERR_CAST (table); + ret = -EINVAL ; + goto err1; } + buffer->sg_table = table;if (ion_buffer_fault_user_mappings (buffer)) { int num_pages = PAGE_ALIGN(buffer->size) / PAGE_SIZE; @@ -226,7
drivers/staging/android/ion/ion.c static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
Quoted 9 lines
+226,7 @@ static struct
ion_buffer*ion_buffer_create(struction_heap*heap,
buffer->pages=vmalloc(sizeof(struct page *) * num_pages); if (!buffer->pages) {
ret =-ENOMEM;drivers/staging/android/ion/ion.c +1
-1- goto err1; + goto err; } for_each_sg(table->sgl, sg, table->nents, i) { @@ -235,9 +235,6@@
Quoted 13 lines
static struct
ion_buffer*ion_buffer_create(struction_heap*heap,
for (j = 0; j <sg->length/PAGE_SIZE; j++)
buffer->pages[k++] = page++;
}drivers/staging/android/ion/ion.c +0
-3- -if (ret) - goto err; } buffer->dev = dev;@@ -261,9 +258,8 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
Quoted 10 lines
Quoted 10 lines
drivers/staging/android/ion/ion.c +1
-2err: heap->ops->unmap_dma (heap, buffer); - heap->ops->free (buffer); err1: -vfree (buffer->pages); + heap->ops->free (buffer); err2:kfree (buffer);return ERR_PTR(ret);
Gioh Kim
Reviewed-by2015-10-01 오후 2:31에 PINTU KUMAR 이(가) 쓴 글:
Quoted 73 lines
Quoted 73 lines
-----Original Message-----
From: Laura Abbott [mailto:[email protected]]
Sent: Wednesday, September 30, 2015 11:42 PM
To: Rohit kumar; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; akpm@linux- foundation.org; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/1] staging: ion: Fix error handling inion_buffer_createQuoted 4 lines · Rohit kumar
This patch fixes error handling case when
buffer->pagesallocation fails. Also, it removes unreachable code of checking ret variable although it is not updated.Reviewed-by Laura Abbott <[email protected]>drivers/staging/android/ion/ion.c static struct ion_buffer *ion_buffer_create(struct
Quoted 11 lines
Signed-off-by Rohit kumar <[email protected]>--- drivers/staging/android/ion/ion.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)drivers/staging/android/ion/ion.c +0
-0@@ -213,10 +213,10 @@ static struct ion_buffer *ion_buffer_create(struct
ion_heap*heap,drivers/staging/android/ion/ion.c static struct ion_buffer *ion_buffer_create(struct · line 213
Quoted 1 line
drivers/staging/android/ion/ion.c +0
-0"heap->ops->map_dma should return ERR_PTR onerror"))
drivers/staging/android/ion/ion.c static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
Quoted 12 lines
drivers/staging/android/ion/ion.c +3
-3table =ERR_PTR (-EINVAL );if (IS_ERR (table)) { - heap->ops->free (buffer); -kfree (buffer); -return ERR_CAST (table); + ret = -EINVAL ; + goto err1; } + buffer->sg_table = table;if (ion_buffer_fault_user_mappings (buffer)) { int num_pages = PAGE_ALIGN(buffer->size) / PAGE_SIZE; @@ -226,7
drivers/staging/android/ion/ion.c static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
Quoted 9 lines
+226,7 @@ static struct
ion_buffer*ion_buffer_create(struction_heap*heap,buffer->pages = vmalloc(sizeof(struct page *) * num_pages); if (!buffer->pages) { ret = -ENOMEM;drivers/staging/android/ion/ion.c +1
-1- goto err1; + goto err; } for_each_sg(table->sgl, sg, table->nents, i) { @@ -235,9 +235,6@@
Quoted 13 lines
static struct
ion_buffer*ion_buffer_create(struction_heap*heap,
for (j = 0; j <sg->length/PAGE_SIZE; j++)buffer->pages[k++] = page++; }drivers/staging/android/ion/ion.c +0
-3- -if (ret) - goto err; } buffer->dev = dev;@@ -261,9 +258,8 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
Quoted 16 lines
Quoted 10 lines
Quoted 10 lines
drivers/staging/android/ion/ion.c +1
-2err: heap->ops->unmap_dma (heap, buffer); - heap->ops->free (buffer); err1: -vfree (buffer->pages); + heap->ops->free (buffer); err2:kfree (buffer);return ERR_PTR(ret);Suggested-by Pintu Kumar <[email protected]>Reviewed-by Pintu Kumar <[email protected]>
It's nice!