page_owner_sort does not check its output stream for errors and relies on process exit to flush buffered data. For example, writing a small result to /dev/full returns success even though no output is saved. Check for earlier stream errors and explicitly close the output before reporting success, so errors flushing the final buffer also produce a failing exit status. Fixes: 48c96a368579 ("mm/page_owner: keep track of page owners") Signed-off-by: Zhu Jun --- tools/mm/page_owner_sort.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/mm/page_owner_sort.c b/tools/mm/page_owner_sort.c index 48c403d3de4f..13166199ef0d 100644 --- a/tools/mm/page_owner_sort.c +++ b/tools/mm/page_owner_sort.c @@ -1024,6 +1024,11 @@ int main(int argc, char **argv) } } + if (ferror(fout) || fclose(fout)) { + perror("write output"); + exit(1); + } + out_free: if (ext_buf) free(ext_buf);