From: David Laight <david.laight.linux@gmail.com>
To: "Arnd Bergmann" <arnd@arndb.de>
Cc: "Matt Roper" <matthew.d.roper@intel.com>,
"Arnd Bergmann" <arnd@kernel.org>,
"Matthew Brost" <matthew.brost@intel.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Dave Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Dnyaneshwar Bhadane" <dnyaneshwar.bhadane@intel.com>,
"Lucas De Marchi" <demarchi@kernel.org>,
"Tvrtko Ursulin" <tvrtko.ursulin@igalia.com>,
"Umesh Nerlige Ramappa" <umesh.nerlige.ramappa@intel.com>,
"Raag Jadav" <raag.jadav@intel.com>,
"Niranjana Vishwanathapura" <niranjana.vishwanathapura@intel.com>,
intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/xe: use %z format string for ptrdiff_t
Date: Tue, 17 Mar 2026 14:56:47 +0000 [thread overview]
Message-ID: <20260317145647.0d5de2a1@pumpkin> (raw)
In-Reply-To: <e46c3681-6f5f-4a41-b5bf-72627b4ec87a@app.fastmail.com>
On Tue, 17 Mar 2026 00:07:57 +0100
"Arnd Bergmann" <arnd@arndb.de> wrote:
> On Mon, Mar 16, 2026, at 23:51, Matt Roper wrote:
> > On Mon, Mar 16, 2026 at 11:43:46PM +0100, Arnd Bergmann wrote:
> >> From: Arnd Bergmann <arnd@arndb.de>
> >>
> >> ptrdiff_t, size_t and long are the same size on all supported architectures,
> >> but gcc requires the use of the %zx modifier instead of %lx. On 32-bit
> >
> > Nathan Chancellor just sent a fix here:
> >
> > https://lore.kernel.org/all/20260316-drm-xe-fix-32-bit-wformat-ptrdiff-v1-1-0108b10b2b6b@kernel.org/
> >
> > His solution uses %tx rather than %zx, which according to
> > Documentation/core-api/printk-formats.rst sounds like it's probably the
> > most accurate format string for this case?
> >
>
> Right, Nathan's version is correct. I wasn't aware that size_t
> and ptrdiff_t have different modifiers.
Consider:
void foo(size_t len)
{
char *p = malloc(len);
char *end = p + len;
ptrdiff_t diff = p - end;
printf("len %zu, diff %td\n", len, diff);
free(p);
}
Clearly foo(5) output "5 -5".
But what about foo(5u << 29) on a 32bit system with a large unlimit and
a big enough hole in the address space.
More likely would be something running on an x86 in real mode.
There malloc(65000) might be reasonable, so size_t would be unsigned int
but ptrdiff_t would need to be a signed 32bit type.
Of course, in linux, they are all 'long'.
David
>
> Arnd
>
next prev parent reply other threads:[~2026-03-17 14:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-16 22:43 [PATCH] drm/xe: use %z format string for ptrdiff_t Arnd Bergmann
2026-03-16 22:51 ` Matt Roper
2026-03-16 23:07 ` Arnd Bergmann
2026-03-17 14:56 ` David Laight [this message]
2026-03-17 16:46 ` David Laight
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=20260317145647.0d5de2a1@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=airlied@gmail.com \
--cc=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=demarchi@kernel.org \
--cc=dnyaneshwar.bhadane@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matthew.brost@intel.com \
--cc=matthew.d.roper@intel.com \
--cc=niranjana.vishwanathapura@intel.com \
--cc=raag.jadav@intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=simona@ffwll.ch \
--cc=thomas.hellstrom@linux.intel.com \
--cc=tvrtko.ursulin@igalia.com \
--cc=umesh.nerlige.ramappa@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