read_block() only returns a record when it encounters an empty line. If the input ends directly after a complete record, the function returns -1 and main() silently drops that record. Return the accumulated record at EOF when it contains data. Keep the existing failure result when the buffer fills before reaching EOF. Fixes: 48c96a368579 ("mm/page_owner: keep track of page owners") Signed-off-by: Zhu Jun --- tools/mm/page_owner_sort.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/mm/page_owner_sort.c b/tools/mm/page_owner_sort.c index 6c2ac5d9dc4b..48c403d3de4f 100644 --- a/tools/mm/page_owner_sort.c +++ b/tools/mm/page_owner_sort.c @@ -134,6 +134,9 @@ int read_block(char *buf, char *ext_buf, int buf_size, FILE *fin) curr += strlen(curr); } + if (feof(fin) && curr != buf) + return curr - buf; + return -1; /* EOF or no space left in buf. */ }