From 00655ce3037bc1a8bce1387a63a01180f18cdafc Mon Sep 17 00:00:00 2001 From: Jeffrey Carlyle Date: Mon, 30 Aug 2010 19:55:09 +0200 Subject: [PATCH] --- yaml --- r: 210527 b: refs/heads/master c: edce6820a9fdda85521211cb334a183e34cc455e h: refs/heads/master i: 210525: ed49c35fd8ccee50df506115ae8debfc2c098cf9 210523: 1bede72ed8170861f619f369440ac5a4944cc6ba 210519: c4e40779523ab3f2e92890bc58851c71240995a8 210511: a5afb6cab74443f6b137189063fbf5d36dc219c8 210495: 8f5fc534f3aa0a7f35d24ad4c2e1ae8fdfa39203 v: v3 --- [refs] | 2 +- trunk/lib/scatterlist.c | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) 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;