Re: [RFC V2 3/3] mm: Replace pgtable entry prints with new format
From: Andy Shevchenko
Date: Wed Jul 01 2026 - 05:04:35 EST
On Tue, Jun 30, 2026 at 03:36:58PM +0200, David Hildenbrand (Arm) wrote:
> On 6/16/26 08:19, Hugh Dickins wrote:
> > On Mon, 15 Jun 2026, David Hildenbrand (Arm) wrote:
> >> On 6/12/26 23:26, Hugh Dickins wrote:
...
> +#define PTVAL_STR_MAX (sizeof(u64) * 4 + 1)
> +
> +static void ptval_bytes_to_str(char *buf, size_t buf_size,
> + const void *entry, size_t entry_size)
> +{
> + if (WARN_ON_ONCE(buf_size < entry_size * 2 + 1)) {
> + snprintf(buf, buf_size, "overflow");
> + return;
> + }
If you want to make this available for dynamically allocated buffers of
the exact size, this function should return the result of snprintf()
as int along with accepting NULL, 0 case.
> + switch (entry_size) {
> + case sizeof(u32):
> + snprintf(buf, buf_size, "%08x", *(const u32 *)entry);
> + break;
> + case sizeof(u64):
> + snprintf(buf, buf_size, "%016llx",
> + (unsigned long long)*(const u64 *)entry);
Not sure why castings are needed here and below.
> + break;
> + case sizeof(u64) * 2: {
> + const u64 *val = entry;
> +
> + if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
> + snprintf(buf, buf_size, "%016llx%016llx",
> + (unsigned long long)val[0],
> + (unsigned long long)val[1]);
> + else
> + snprintf(buf, buf_size, "%016llx%016llx",
> + (unsigned long long)val[1],
> + (unsigned long long)val[0]);
> + break;
> + }
> + default:
> + snprintf(buf, buf_size, "unsupported");
> + break;
> + }
> +}
--
With Best Regards,
Andy Shevchenko