From: Tony Battersby Date: Thu, 23 Oct 2014 19:10:21 +0000 (-0400) Subject: lib/scatterlist: fix memory leak with scsi-mq X-Git-Tag: v3.17.3~71 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a58c28f66aca396c19f297b6c29835971a1e2886;p=thirdparty%2Fkernel%2Fstable.git lib/scatterlist: fix memory leak with scsi-mq commit c21e59d8dc04b2107bdb4ff0f412a9b7ae3349f3 upstream. Fix a memory leak with scsi-mq triggered by commands with large data transfer length. Fixes: c53c6d6a68b1 ("scatterlist: allow chaining to preallocated chunks") Signed-off-by: Tony Battersby Reviewed-by: Martin K. Petersen Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- diff --git a/lib/scatterlist.c b/lib/scatterlist.c index 9cdf62f8accde..c9f2e8c6ccc99 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c @@ -203,10 +203,10 @@ void __sg_free_table(struct sg_table *table, unsigned int max_ents, } table->orig_nents -= sg_size; - if (!skip_first_chunk) { - free_fn(sgl, alloc_size); + if (skip_first_chunk) skip_first_chunk = false; - } + else + free_fn(sgl, alloc_size); sgl = next; }