[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.DEB.2.21.2410150220160.40463@angie.orcam.me.uk>
Date: Tue, 15 Oct 2024 03:01:13 +0100 (BST)
From: "Maciej W. Rozycki" <macro@...am.me.uk>
To: Paulo Miguel Almeida <paulo.miguel.almeida.rodenas@...il.com>
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, 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
Powered by blists - more mailing lists