[PATCH 05/11] lib/scatterlist: Extract scatterlist free from __sg_free_table

Tvrtko Ursulin tursulin at ursulin.net
Thu Mar 1 13:28:38 UTC 2018


From: Tvrtko Ursulin <tvrtko.ursulin at intel.com>

Separating out freeing of the table will come useful in the following
patch.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
Cc: Bart Van Assche <bart.vanassche at wdc.com>
Cc: Hannes Reinecke <hare at suse.com>
Cc: Johannes Thumshirn <jthumshirn at suse.de>
Cc: Jens Axboe <axboe at kernel.dk>
---
 lib/scatterlist.c | 55 ++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 32 insertions(+), 23 deletions(-)

diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index e137de4c36c9..e11421142cc5 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -189,30 +189,15 @@ static void sg_kfree(struct scatterlist *sg, unsigned int nents)
 		kfree(sg);
 }
 
-/**
- * __sg_free_table - Free a previously mapped sg table
- * @table:	The sg table header to use
- * @max_ents:	The maximum number of entries per single scatterlist
- * @skip_first_chunk: don't free the (preallocated) first scatterlist chunk
- * @free_fn:	Free function
- *
- *  Description:
- *    Free an sg table previously allocated and setup with
- *    __sg_alloc_table().  The @max_ents value must be identical to
- *    that previously used with __sg_alloc_table().
- *
- **/
-void __sg_free_table(struct sg_table *table, unsigned int max_ents,
-		     bool skip_first_chunk, sg_free_fn *free_fn)
+static void
+__sg_free_scatterlist(struct scatterlist *sgl, unsigned int orig_nents,
+		      unsigned int max_ents, bool skip_first_chunk,
+		      sg_free_fn *free_fn)
 {
-	struct scatterlist *sgl, *next;
+	struct scatterlist *next;
 
-	if (unlikely(!table->sgl))
-		return;
-
-	sgl = table->sgl;
-	while (table->orig_nents) {
-		unsigned int alloc_size = table->orig_nents;
+	while (orig_nents) {
+		unsigned int alloc_size = orig_nents;
 		unsigned int sg_size;
 
 		/*
@@ -230,14 +215,38 @@ void __sg_free_table(struct sg_table *table, unsigned int max_ents,
 			next = NULL;
 		}
 
-		table->orig_nents -= sg_size;
+		orig_nents -= sg_size;
 		if (skip_first_chunk)
 			skip_first_chunk = false;
 		else
 			free_fn(sgl, alloc_size);
 		sgl = next;
 	}
+}
+
+/**
+ * __sg_free_table - Free a previously mapped sg table
+ * @table:	The sg table header to use
+ * @max_ents:	The maximum number of entries per single scatterlist
+ * @skip_first_chunk: don't free the (preallocated) first scatterlist chunk
+ * @free_fn:	Free function
+ *
+ *  Description:
+ *    Free an sg table previously allocated and setup with
+ *    __sg_alloc_table().  The @max_ents value must be identical to
+ *    that previously used with __sg_alloc_table().
+ *
+ **/
+void __sg_free_table(struct sg_table *table, unsigned int max_ents,
+		     bool skip_first_chunk, sg_free_fn *free_fn)
+{
+	if (unlikely(!table->sgl))
+		return;
+
+	__sg_free_scatterlist(table->sgl, table->orig_nents, max_ents,
+			      skip_first_chunk, free_fn);
 
+	table->orig_nents = 0;
 	table->sgl = NULL;
 }
 EXPORT_SYMBOL(__sg_free_table);
-- 
2.14.1



More information about the Intel-gfx-trybot mailing list