diff mbox series

sgl_alloc_order: memory leak

Message ID 20200920053607.35002-1-dgilbert@interlog.com (mailing list archive)
State New, archived
Headers show
Series sgl_alloc_order: memory leak | expand

Commit Message

Douglas Gilbert Sept. 20, 2020, 5:36 a.m. UTC
Noticed that when sgl_alloc_order() failed with order > 0 that
free memory on my machine shrank. That function shouldn't call
sgl_free() on its error path since that is only correct when
order==0 .

Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>
---
 lib/scatterlist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Bart Van Assche Sept. 20, 2020, 3:29 p.m. UTC | #1
On 2020-09-19 22:36, Douglas Gilbert wrote:
> Noticed that when sgl_alloc_order() failed with order > 0 that
> free memory on my machine shrank. That function shouldn't call
> sgl_free() on its error path since that is only correct when
> order==0 .
> 
> Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>
> ---
>  lib/scatterlist.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/scatterlist.c b/lib/scatterlist.c
> index 5d63a8857f36..c448642e0f78 100644
> --- a/lib/scatterlist.c
> +++ b/lib/scatterlist.c
> @@ -514,7 +514,7 @@ struct scatterlist *sgl_alloc_order(unsigned long long length,
>  		elem_len = min_t(u64, length, PAGE_SIZE << order);
>  		page = alloc_pages(gfp, order);
>  		if (!page) {
> -			sgl_free(sgl);
> +			sgl_free_order(sgl, order);
>  			return NULL;
>  		}

Reviewed-by: Bart Van Assche <bvanassche@acm.org>
diff mbox series

Patch

diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index 5d63a8857f36..c448642e0f78 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -514,7 +514,7 @@  struct scatterlist *sgl_alloc_order(unsigned long long length,
 		elem_len = min_t(u64, length, PAGE_SIZE << order);
 		page = alloc_pages(gfp, order);
 		if (!page) {
-			sgl_free(sgl);
+			sgl_free_order(sgl, order);
 			return NULL;
 		}