lkml.org 
[lkml]   [2018]   [Mar]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
SubjectRe: [PATCH 3/6] lib/scatterlist: Do not leak pages when high-order allocation fails
Date
On Wed, 2018-03-07 at 12:47 +0000, Tvrtko Ursulin wrote:
> diff --git a/lib/scatterlist.c b/lib/scatterlist.c
> index 9884be50a2c0..e13a759c5c49 100644
> --- a/lib/scatterlist.c
> +++ b/lib/scatterlist.c
> @@ -493,7 +493,7 @@ struct scatterlist *sgl_alloc_order(unsigned long length, unsigned int order,
> {
> unsigned int chunk_len = PAGE_SIZE << order;
> struct scatterlist *sgl, *sg;
> - unsigned int nent;
> + unsigned int nent, i;
>
> nent = round_up(length, chunk_len) >> (PAGE_SHIFT + order);
>
> @@ -517,11 +517,12 @@ struct scatterlist *sgl_alloc_order(unsigned long length, unsigned int order,
>
> sg_init_table(sgl, nent);
> sg = sgl;
> + i = 0;
> while (length) {
> struct page *page = alloc_pages(gfp, order);
>
> if (!page) {
> - sgl_free(sgl);
> + sgl_free_n_order(sgl, i, order);
> return NULL;
> }
>
> @@ -529,6 +530,7 @@ struct scatterlist *sgl_alloc_order(unsigned long length, unsigned int order,
> sg_set_page(sg, page, chunk_len, 0);
> length -= chunk_len;
> sg = sg_next(sg);
> + i++;
> }

Since the entire sg-list is zero-initialized before this loop starts, since
the sg-list is not chained onto another sg-list before this function returns
and since sgl_free_n_order() checks whether or not each page pointer is NULL
before freeing it I think we don't need the new loop variable 'i' and that
we can call sgl_free_order() instead of sgl_free_n_order().

Bart.
\
 
 \ /
  Last update: 2018-03-07 17:17    [W:0.150 / U:1.324 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site