[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ZxDRmlDbtjEaTH8z@mail.google.com>
Date: Thu, 17 Oct 2024 21:58:02 +1300
From: Paulo Miguel Almeida <paulo.miguel.almeida.rodenas@...il.com>
To: "Maciej W. Rozycki" <macro@...am.me.uk>
Cc: Thomas Bogendoerfer <tsbogend@...ha.franken.de>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
zhanggenjian@...inos.cn, ricardo@...liere.net, bvanassche@....org,
linux-mips@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-hardening@...r.kernel.org
Subject: Re: [PATCH][next] mips: sgi-ip22: Replace "s[n]?printf" with
sysfs_emit in sysfs callbacks
On Tue, Oct 15, 2024 at 03:01:13AM +0100, Maciej W. Rozycki wrote:
> On Tue, 15 Oct 2024, Paulo Miguel Almeida wrote:
>
> > snprintf() has the documented, but still rather strange trait of
> > returning the length of the data that *would have been* written to the
> > array if space were available, rather than the arguably more useful
> > length of data *actually* written, [...]
>
> Why do you think that just returning `n - 1' in the case of a length
> overflow would be more useful than returning the unmet buffer length
> requirement? I think the opposite is the case: the value returned lets
> you reallocate the buffer for more space and retry, and there's no other
> way to figure out how much this would be. And if you need to know how
> many characters were actually written, then `min(n - 1, snprintf(...))'
> will do (and code you propose to replace does exactly that, open-coded).
>
> The change itself makes sense to me, but not your proposed description
> I'm afraid. Just replacing open-coded pieces with calls to `sysfs_emit'
> is enough justification.
>
> Maciej
Thanks for taking the time to review this patch.
Will submit a v2 with the description you pointed out.
- Paulo A.
Powered by blists - more mailing lists