mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Warren Xiong <warren.xiong@ugreen.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] tools/mm: prevent page_owner_sort from truncating input
Date: Thu, 30 Jul 2026 13:45:29 -0700	[thread overview]
Message-ID: <20260730134529.29151e44a6da7430a4caf10c@linux-foundation.org> (raw)
In-Reply-To: <20260730015809.3819606-1-warren.xiong@ugreen.com>

On Thu, 30 Jul 2026 09:58:09 +0800 Warren Xiong <warren.xiong@ugreen.com> wrote:

> page_owner_sort opens the output file with "w" before reading the input.
> If both paths refer to the same file, this truncates the input and the
> tool silently processes zero records before returning success.
> 
> Delay opening the output file until all input records have been loaded
> into memory. This allows the tool to sort a file in place without
> truncating data before it has been consumed.

Far nicer, thanks.

However I spotted a thing which Sashiko missed!

> @@ -874,6 +873,13 @@ int main(int argc, char **argv)
>  			goto out_free;
>  	}
>  
> +	fout = fopen(argv[optind + 1], "w");
> +	if (!fout) {
> +		usage();
> +		perror("open: ");
> +		exit(1);
> +	}

usage() calls printf(), which can set errno.  So perror() might print
the wrong thing.

Not that I care very much ;)

      reply	other threads:[~2026-07-30 20:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29  5:38 [PATCH] " Warren Xiong
2026-07-30  0:31 ` Andrew Morton
2026-07-30  1:30   ` 熊卧龙
2026-07-30  1:58 ` [PATCH v2] " Warren Xiong
2026-07-30 20:45   ` Andrew Morton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260730134529.29151e44a6da7430a4caf10c@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=warren.xiong@ugreen.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®