The patch titled Subject: lib/lru_cache: fix error free handing in lc_create has been added to the -mm mm-nonmm-unstable branch. Its filename is lib-lru_cache-fix-error-free-handing-in-lc_create.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/lib-lru_cache-fix-error-free-handing-in-lc_create.patch This patch will later appear in the mm-nonmm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: wuchi <wuchi.zero@xxxxxxxxx> Subject: lib/lru_cache: fix error free handing in lc_create Date: Sat, 18 Jun 2022 16:25:21 +0800 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@xxxxxxxxx Signed-off-by: wuchi <wuchi.zero@xxxxxxxxx> Cc: Philipp Reisner <philipp.reisner@xxxxxxxxxx> Cc: Lars Ellenberg <lars.ellenberg@xxxxxxxxxx> Cc: Christoph Bhmwalder <christoph.boehmwalder@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- lib/lru_cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/lib/lru_cache.c~lib-lru_cache-fix-error-free-handing-in-lc_create +++ a/lib/lru_cache.c @@ -147,8 +147,8 @@ struct lru_cache *lc_create(const char * 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); _ Patches currently in -mm which might be from wuchi.zero@xxxxxxxxx are lib-debugobjects-fix-stat-count-and-optimize-debug_objects_mem_init.patch lib-lru_cache-fix-error-free-handing-in-lc_create.patch