Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] Fix for shmem_truncate_range() BUG_ON()

Ran into BUG() while doing madvise(REMOVE) testing. If we are punching a
hole into shared memory segment using madvise(REMOVE) and the entire hole
is below the indirect blocks, we hit following assert.

BUG_ON(limit <= SHMEM_NR_DIRECT);

Signed-off-by: Badari Pulavarty <pbadari@us.ibm.com>
Cc: Hugh Dickins <hugh@veritas.com>
Cc: <stable@kernel.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Badari Pulavarty and committed by
Linus Torvalds
92a3d03a ba008404

+6 -1
+6 -1
mm/shmem.c
··· 515 515 size = SHMEM_NR_DIRECT; 516 516 nr_swaps_freed = shmem_free_swp(ptr+idx, ptr+size); 517 517 } 518 - if (!topdir) 518 + 519 + /* 520 + * If there are no indirect blocks or we are punching a hole 521 + * below indirect blocks, nothing to be done. 522 + */ 523 + if (!topdir || (punch_hole && (limit <= SHMEM_NR_DIRECT))) 519 524 goto done2; 520 525 521 526 BUG_ON(limit <= SHMEM_NR_DIRECT);