diff --git a/[refs] b/[refs] index 6d5c764bb5b3..68a1dbdf605a 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: b76b4014f9d988d2412b873e4d4c13c7f9afc4e4 +refs/heads/master: edce6820a9fdda85521211cb334a183e34cc455e diff --git a/trunk/lib/scatterlist.c b/trunk/lib/scatterlist.c index a5ec42868f99..4ceb05d772ae 100644 --- a/trunk/lib/scatterlist.c +++ b/trunk/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;