lib/scatterlist: fix memory leak with scsi-mq
authorTony Battersby <tonyb@cybernetics.com>
Thu, 23 Oct 2014 19:10:21 +0000 (15:10 -0400)
committerJens Axboe <axboe@fb.com>
Tue, 28 Oct 2014 16:27:10 +0000 (10:27 -0600)
Fix a memory leak with scsi-mq triggered by commands with large data
transfer length.

Fixes: c53c6d6a68b1 ("scatterlist: allow chaining to preallocated chunks")
Cc: <stable@vger.kernel.org> # 3.17.x
Signed-off-by: Tony Battersby <tonyb@cybernetics.com>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
lib/scatterlist.c

index 9cdf62f..c9f2e8c 100644 (file)
@@ -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;
        }