From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Michal Pecio <michal.pecio@gmail.com>
Cc: Niklas Neronin <niklas.neronin@linux.intel.com>,
mathias.nyman@linux.intel.com, linux-usb@vger.kernel.org
Subject: Re: [PATCH 2/7] usb: xhci: use '%pad' specifier for DMA address printing
Date: Mon, 15 Sep 2025 10:20:33 +0300 [thread overview]
Message-ID: <aMe-QcrnE5hMHC5E@smile.fi.intel.com> (raw)
In-Reply-To: <20250913101246.515abfc4.michal.pecio@gmail.com>
On Sat, Sep 13, 2025 at 10:12:46AM +0200, Michal Pecio wrote:
> On Fri, 12 Sep 2025 21:02:23 +0300, Andy Shevchenko wrote:
> > Again, imagine the loop that goes above 4G on a 64-bit machine. Out
> > of a sudden %08llx will be expanded to cover the 64-bit addresses and
> > becomes one digit at a time creating a ladder (ugly looking) output.
> > This is incorrect.
>
> If I equated correctness with ugliness I would equally confidently
Ugliness?! No, the full information printed is way too better than
whatever pieces of it are (even if it's correct in some cases).
We are doing 64-bit hardware, we have to deal with 64-bit pointers.
Period. Shortcutting and premature optimizing is always a slippery slope
when we enter to the debugging field.
> state that unnecessary zero-padding is incorrect. But I don't.
Right, because it won't be incorrect, there is no such thing as unnecessary
zero-padding for the pointers.
> This is exactly the absurd argument I previously made for padding all
> %x and %d formats to full width. Pad tables, not lone log messages.
> > No, it's other way around, we should not put explicit casts in printf() in C
> > as there are plenty of the format specifiers that allows us to be sure that
> > the printed value is correct independently on architecture, endianess, etc.
>
> At least if you do it, the compiler will also do the right thing:
> - if the cast doesn't match the format, warn (xhci needs a patch here)
Of course this doesn't work properly on the types that are less than int. So,
this is fragile argument to support explicit castings.
> - if it matches, widen the provided value as necessary
>
> And it works consistently regardless of whether the variable is a
> dma_addr_t or u64, on all architectures, with or without PAE.
Yes, with "unnecessary" zero-paddings (that case when they are not needed).
> Reminder: this drivers handles DMAs as u64 too, so it will *never*
> print all DMAs as %pad. And if it tries, it will be a silent bug.
Yes, and the problem here is not in the printf() specifiers, the problem is
in the (used) data types. For the printf() it's crystal clear, if the type of
the variable is dma_addr_t, we have %pad. No need to reinvent the wheel.
> > > This brings up another problem with %pad: it is unknown to compilers
> > > so they don't type check it.
> > >
> > > but if I switch to %pad and later change my mind and extend 'addr' to
> > > u64 without updating this format, the compiler will eat it up and once
> > > again garbage will be printed on some systems.
> >
> > This topic was risen a few times in the past. Somebody proposed to have a GCC
> > plugin with that, somebody else proposed to completely rewrite the %p
> > extensions to be more like Pyhon or C++ ones (when you just specify argument
> > and handler for it). None so far is implemented AFAIK.
>
> Indeed, not holding my breath for the %pad situation improving.
> This includes impossibility of passing it by value - it's forced
> by compilers being unaware of %pad and following usual %p rules.
>
> > But this is not particular problem of %pad, it's for all %p
> > extensions. And the extensions exist for a purpose. What you are
> > proposing here behind the lines is to kill that completely.
>
> Surely people would laugh me off if I actually suggested that.
> If those formats work for their cases, use them.
Sure, there are thousands of the cases in the kernel when we print our custom
data types in a better format and this works and will continue working
independently on the legacy of the compilers or C standard modifications.
Removing them is like suggesting Americans to drop automatic gear in favour of
the manual to the promoting eco-transportation (horses + carts). I don't believe
this is valuable proposal.
P.S.
I'm sorry, but I lost the objective of this discussion. Can you summarize,
please, what's wrong with the patch?
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2025-09-15 7:20 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-03 17:01 [PATCH 0/7] usb: xhci: enhancements to address printing Niklas Neronin
2025-09-03 17:01 ` [PATCH 1/7] usb: xhci-dbgcap: correct DMA address handling Niklas Neronin
2025-09-09 10:13 ` Michal Pecio
2025-09-10 8:00 ` Neronin, Niklas
2025-09-10 8:15 ` Michal Pecio
2025-09-03 17:01 ` [PATCH 2/7] usb: xhci: use '%pad' specifier for DMA address printing Niklas Neronin
2025-09-09 9:59 ` Michal Pecio
2025-09-09 11:29 ` Andy Shevchenko
2025-09-09 20:44 ` Michal Pecio
2025-09-10 5:56 ` Michal Pecio
2025-09-11 7:41 ` Andy Shevchenko
2025-09-11 9:34 ` Michal Pecio
2025-09-11 20:13 ` Andy Shevchenko
2025-09-12 9:46 ` Michal Pecio
2025-09-12 18:02 ` Andy Shevchenko
2025-09-13 8:12 ` Michal Pecio
2025-09-15 7:20 ` Andy Shevchenko [this message]
2025-09-15 10:22 ` Michal Pecio
2025-09-15 12:32 ` Neronin, Niklas
2025-09-16 9:32 ` Michal Pecio
2025-09-16 9:36 ` Michal Pecio
2025-09-15 14:22 ` Andy Shevchenko
2025-09-10 9:04 ` Michal Pecio
2025-09-10 9:17 ` Michal Pecio
2025-09-03 17:01 ` [PATCH 3/7] usb: xhci: improve Stream Context register debugging Niklas Neronin
2025-09-09 9:23 ` Michal Pecio
2025-09-03 17:01 ` [PATCH 4/7] usb: xhci: improve Endpoint " Niklas Neronin
2025-09-09 9:20 ` Michal Pecio
2025-09-09 10:24 ` Michal Pecio
2025-09-15 12:45 ` Neronin, Niklas
2025-09-03 17:01 ` [PATCH 5/7] usb: xhci: improve Command Ring Control " Niklas Neronin
2025-09-09 9:17 ` Michal Pecio
2025-09-09 10:20 ` Michal Pecio
2025-09-03 17:01 ` [PATCH 6/7] usb: xhci: improve Event Ring Dequeue Pointer Register debugging Niklas Neronin
2025-09-03 17:01 ` [PATCH 7/7] usb: xhci: standardize address format Niklas Neronin
2025-09-09 9:06 ` Michal Pecio
2025-09-15 13:24 ` Neronin, Niklas
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=aMe-QcrnE5hMHC5E@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@linux.intel.com \
--cc=michal.pecio@gmail.com \
--cc=niklas.neronin@linux.intel.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