summaryrefslogtreecommitdiffstats
path: root/lib/lru_cache.c
diff options
context:
space:
mode:
authorwuchi <wuchi.zero@gmail.com>2022-06-18 10:25:21 +0200
committerakpm <akpm@linux-foundation.org>2022-07-18 02:31:37 +0200
commit5a66fce95b72e6359527415b33a7ae13f0d6b7eb (patch)
tree97ce4d8ac30d27286030f33d4a650f54d3223c5f /lib/lru_cache.c
parentinit: add "hostname" kernel parameter (diff)
downloadlinux-5a66fce95b72e6359527415b33a7ae13f0d6b7eb.tar.xz
linux-5a66fce95b72e6359527415b33a7ae13f0d6b7eb.zip
lib/lru_cache: fix error free handing in lc_create
When kmem_cache_alloc in function lc_create returns null, we will free the memory already allocated. The loop of kmem_cache_free is wrong, especially: i = 0 ==> do wrong loop i > 0 ==> do not free element[0] Link: https://lkml.kernel.org/r/20220618082521.7082-1-wuchi.zero@gmail.com Signed-off-by: wuchi <wuchi.zero@gmail.com> Cc: Philipp Reisner <philipp.reisner@linbit.com> Cc: Lars Ellenberg <lars.ellenberg@linbit.com> Cc: Christoph Bhmwalder <christoph.boehmwalder@linbit.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'lib/lru_cache.c')
-rw-r--r--lib/lru_cache.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/lru_cache.c b/lib/lru_cache.c
index 52313acbfa62..dc35464216d3 100644
--- a/lib/lru_cache.c
+++ b/lib/lru_cache.c
@@ -147,8 +147,8 @@ struct lru_cache *lc_create(const char *name, struct kmem_cache *cache,
return lc;
/* else: could not allocate all elements, give up */
- for (i--; i; i--) {
- void *p = element[i];
+ while (i) {
+ void *p = element[--i];
kmem_cache_free(cache, p - e_off);
}
kfree(lc);