author: Jeffrey Carlyle <jeff.carlyle@motorola.com> 2010-08-30 19:55:09 +0200
committer: Jens Axboe <jaxboe@fusionio.com> 2010-08-30 19:55:09 +0200
commit: edce6820a9fdda85521211cb334a183e34cc455e
parent: b76b4014f9d988d2412b873e4d4c13c7f9afc4e4
Commit Summary:
Diffstat:
1 file changed, 11 insertions, 2 deletions
diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index a5ec42868f99..4ceb05d772ae 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -248,8 +248,18 @@ int __sg_alloc_table(struct sg_table *table, unsigned int nents,
left -= sg_size;
sg = alloc_fn(alloc_size, gfp_mask);
- if (unlikely(!sg))
- return -ENOMEM;
+ if (unlikely(!sg)) {
+ /*
+ * Adjust entry count to reflect that the last
+ * entry of the previous table won't be used for
+ * linkage. Without this, sg_kfree() may get
+ * confused.
+ */
+ if (prv)
+ table->nents = ++table->orig_nents;
+
+ return -ENOMEM;
+ }
sg_init_table(sg, alloc_size);
table->nents = table->orig_nents += sg_size;