public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/xe: use %z format string for ptrdiff_t
@ 2026-03-16 22:43 Arnd Bergmann
  2026-03-16 22:51 ` Matt Roper
  0 siblings, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2026-03-16 22:43 UTC (permalink / raw)
  To: Matthew Brost, Thomas Hellström, Rodrigo Vivi, David Airlie,
	Simona Vetter, Dnyaneshwar Bhadane, Matt Roper
  Cc: Arnd Bergmann, Lucas De Marchi, Tvrtko Ursulin,
	Umesh Nerlige Ramappa, Raag Jadav, Niranjana Vishwanathapura,
	intel-xe, dri-devel, linux-kernel

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
targets, the wrong one produces this warning:

drivers/gpu/drm/xe/xe_lrc.c:1913:7: error: format specifies type 'unsigned long' but the argument has type '__ptrdiff_t' (aka 'int') [-Werror,-Wformat]
 1912 |                 drm_printf(p, "LRC[%#5lx]  =  [%#010x] MI_NOOP (%d dwords)\n",
      |                                    ~~~~~
      |                                    %#5tx
 1913 |                            dw - num_noop - start, inst_header, num_noop);
      |                            ^~~~~~~~~~~~~~~~~~~~~

Fixes: 65fcf19cb36b ("drm/xe: Include running dword offset in default_lrc dumps")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/gpu/drm/xe/xe_lrc.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_lrc.c b/drivers/gpu/drm/xe/xe_lrc.c
index 5ab088e5e13d..c528818e8853 100644
--- a/drivers/gpu/drm/xe/xe_lrc.c
+++ b/drivers/gpu/drm/xe/xe_lrc.c
@@ -1909,17 +1909,17 @@ static int dump_mi_command(struct drm_printer *p,
 		while (num_noop < remaining_dw &&
 		       (*(++dw) & REG_GENMASK(31, 23)) == MI_NOOP)
 			num_noop++;
-		drm_printf(p, "LRC[%#5lx]  =  [%#010x] MI_NOOP (%d dwords)\n",
+		drm_printf(p, "LRC[%#5zx]  =  [%#010x] MI_NOOP (%d dwords)\n",
 			   dw - num_noop - start, inst_header, num_noop);
 		return num_noop;
 
 	case MI_TOPOLOGY_FILTER:
-		drm_printf(p, "LRC[%#5lx]  =  [%#010x] MI_TOPOLOGY_FILTER\n",
+		drm_printf(p, "LRC[%#5zx]  =  [%#010x] MI_TOPOLOGY_FILTER\n",
 			   dw - start, inst_header);
 		return 1;
 
 	case MI_BATCH_BUFFER_END:
-		drm_printf(p, "LRC[%#5lx]  =  [%#010x] MI_BATCH_BUFFER_END\n",
+		drm_printf(p, "LRC[%#5zx]  =  [%#010x] MI_BATCH_BUFFER_END\n",
 			   dw - start, inst_header);
 		/* Return 'remaining_dw' to consume the rest of the LRC */
 		return remaining_dw;
@@ -1934,35 +1934,35 @@ static int dump_mi_command(struct drm_printer *p,
 
 	switch (inst_header & MI_OPCODE) {
 	case MI_LOAD_REGISTER_IMM:
-		drm_printf(p, "LRC[%#5lx]  =  [%#010x] MI_LOAD_REGISTER_IMM: %d regs\n",
+		drm_printf(p, "LRC[%#5zx]  =  [%#010x] MI_LOAD_REGISTER_IMM: %d regs\n",
 			   dw - start, inst_header, (numdw - 1) / 2);
 		for (int i = 1; i < numdw; i += 2)
-			drm_printf(p, "LRC[%#5lx]  =  - %#6x = %#010x\n",
+			drm_printf(p, "LRC[%#5zx]  =  - %#6x = %#010x\n",
 				   &dw[i] - start, dw[i], dw[i + 1]);
 		return numdw;
 
 	case MI_LOAD_REGISTER_MEM & MI_OPCODE:
-		drm_printf(p, "LRC[%#5lx]  =  [%#010x] MI_LOAD_REGISTER_MEM: %s%s\n",
+		drm_printf(p, "LRC[%#5zx]  =  [%#010x] MI_LOAD_REGISTER_MEM: %s%s\n",
 			   dw - start, inst_header,
 			   dw[0] & MI_LRI_LRM_CS_MMIO ? "CS_MMIO " : "",
 			   dw[0] & MI_LRM_USE_GGTT ? "USE_GGTT " : "");
 		if (numdw == 4)
-			drm_printf(p, "LRC[%#5lx]  =  - %#6x = %#010llx\n",
+			drm_printf(p, "LRC[%#5zx]  =  - %#6x = %#010llx\n",
 				   dw - start,
 				   dw[1], ((u64)(dw[3]) << 32 | (u64)(dw[2])));
 		else
-			drm_printf(p, "LRC[%#5lx]  =  - %*ph (%s)\n",
+			drm_printf(p, "LRC[%#5zx]  =  - %*ph (%s)\n",
 				   dw - start, (int)sizeof(u32) * (numdw - 1),
 				   dw + 1, numdw < 4 ? "truncated" : "malformed");
 		return numdw;
 
 	case MI_FORCE_WAKEUP:
-		drm_printf(p, "LRC[%#5lx]  =  [%#010x] MI_FORCE_WAKEUP\n",
+		drm_printf(p, "LRC[%#5zx]  =  [%#010x] MI_FORCE_WAKEUP\n",
 			   dw - start, inst_header);
 		return numdw;
 
 	default:
-		drm_printf(p, "LRC[%#5lx]  =  [%#010x] unknown MI opcode %#x, likely %d dwords\n",
+		drm_printf(p, "LRC[%#5zx]  =  [%#010x] unknown MI opcode %#x, likely %d dwords\n",
 			   dw - start, inst_header, opcode, numdw);
 		return numdw;
 	}
@@ -1989,12 +1989,12 @@ static int dump_gfxpipe_command(struct drm_printer *p,
 	switch (*dw & GFXPIPE_MATCH_MASK) {
 #define MATCH(cmd) \
 	case cmd: \
-		drm_printf(p, "LRC[%#5lx]  =  [%#010x] " #cmd " (%d dwords)\n", \
+		drm_printf(p, "LRC[%#5zx]  =  [%#010x] " #cmd " (%d dwords)\n", \
 			   dw - start, *dw, numdw); \
 		return numdw
 #define MATCH3D(cmd) \
 	case CMD_##cmd: \
-		drm_printf(p, "LRC[%#5lx]  =  [%#010x] " #cmd " (%d dwords)\n", \
+		drm_printf(p, "LRC[%#5zx]  =  [%#010x] " #cmd " (%d dwords)\n", \
 			   dw - start, *dw, numdw); \
 		return numdw
 
@@ -2127,7 +2127,7 @@ static int dump_gfxpipe_command(struct drm_printer *p,
 	MATCH3D(3DSTATE_SLICE_TABLE_STATE_POINTER_2);
 
 	default:
-		drm_printf(p, "LRC[%#5lx]  =  [%#010x] unknown GFXPIPE command (pipeline=%#x, opcode=%#x, subopcode=%#x), likely %d dwords\n",
+		drm_printf(p, "LRC[%#5zx]  =  [%#010x] unknown GFXPIPE command (pipeline=%#x, opcode=%#x, subopcode=%#x), likely %d dwords\n",
 			   dw - start, *dw, pipeline, opcode, subopcode, numdw);
 		return numdw;
 	}
@@ -2153,7 +2153,7 @@ static int dump_gfx_state_command(struct drm_printer *p,
 	MATCH(STATE_WRITE_INLINE);
 
 	default:
-		drm_printf(p, "LRC[%#5lx]  =  [%#010x] unknown GFX_STATE command (opcode=%#x), likely %d dwords\n",
+		drm_printf(p, "LRC[%#5zx]  =  [%#010x] unknown GFX_STATE command (opcode=%#x), likely %d dwords\n",
 			   dw - start, *dw, opcode, numdw);
 		return numdw;
 	}
@@ -2188,7 +2188,7 @@ void xe_lrc_dump_default(struct drm_printer *p,
 			num_dw = dump_gfx_state_command(p, gt, start, dw, remaining_dw);
 		} else {
 			num_dw = min(instr_dw(*dw), remaining_dw);
-			drm_printf(p, "LRC[%#5lx]  =  [%#10x] Unknown instruction of type %#x, likely %d dwords\n",
+			drm_printf(p, "LRC[%#5zx]  =  [%#10x] Unknown instruction of type %#x, likely %d dwords\n",
 				   dw - start,
 				   *dw, REG_FIELD_GET(XE_INSTR_CMD_TYPE, *dw),
 				   num_dw);
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/xe: use %z format string for ptrdiff_t
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Matt Roper @ 2026-03-16 22:51 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Matthew Brost, Thomas Hellström, Rodrigo Vivi, David Airlie,
	Simona Vetter, Dnyaneshwar Bhadane, Arnd Bergmann,
	Lucas De Marchi, Tvrtko Ursulin, Umesh Nerlige Ramappa,
	Raag Jadav, Niranjana Vishwanathapura, intel-xe, dri-devel,
	linux-kernel

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?


Matt

> targets, the wrong one produces this warning:
> 
> drivers/gpu/drm/xe/xe_lrc.c:1913:7: error: format specifies type 'unsigned long' but the argument has type '__ptrdiff_t' (aka 'int') [-Werror,-Wformat]
>  1912 |                 drm_printf(p, "LRC[%#5lx]  =  [%#010x] MI_NOOP (%d dwords)\n",
>       |                                    ~~~~~
>       |                                    %#5tx
>  1913 |                            dw - num_noop - start, inst_header, num_noop);
>       |                            ^~~~~~~~~~~~~~~~~~~~~
> 
> Fixes: 65fcf19cb36b ("drm/xe: Include running dword offset in default_lrc dumps")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/gpu/drm/xe/xe_lrc.c | 30 +++++++++++++++---------------
>  1 file changed, 15 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_lrc.c b/drivers/gpu/drm/xe/xe_lrc.c
> index 5ab088e5e13d..c528818e8853 100644
> --- a/drivers/gpu/drm/xe/xe_lrc.c
> +++ b/drivers/gpu/drm/xe/xe_lrc.c
> @@ -1909,17 +1909,17 @@ static int dump_mi_command(struct drm_printer *p,
>  		while (num_noop < remaining_dw &&
>  		       (*(++dw) & REG_GENMASK(31, 23)) == MI_NOOP)
>  			num_noop++;
> -		drm_printf(p, "LRC[%#5lx]  =  [%#010x] MI_NOOP (%d dwords)\n",
> +		drm_printf(p, "LRC[%#5zx]  =  [%#010x] MI_NOOP (%d dwords)\n",
>  			   dw - num_noop - start, inst_header, num_noop);
>  		return num_noop;
>  
>  	case MI_TOPOLOGY_FILTER:
> -		drm_printf(p, "LRC[%#5lx]  =  [%#010x] MI_TOPOLOGY_FILTER\n",
> +		drm_printf(p, "LRC[%#5zx]  =  [%#010x] MI_TOPOLOGY_FILTER\n",
>  			   dw - start, inst_header);
>  		return 1;
>  
>  	case MI_BATCH_BUFFER_END:
> -		drm_printf(p, "LRC[%#5lx]  =  [%#010x] MI_BATCH_BUFFER_END\n",
> +		drm_printf(p, "LRC[%#5zx]  =  [%#010x] MI_BATCH_BUFFER_END\n",
>  			   dw - start, inst_header);
>  		/* Return 'remaining_dw' to consume the rest of the LRC */
>  		return remaining_dw;
> @@ -1934,35 +1934,35 @@ static int dump_mi_command(struct drm_printer *p,
>  
>  	switch (inst_header & MI_OPCODE) {
>  	case MI_LOAD_REGISTER_IMM:
> -		drm_printf(p, "LRC[%#5lx]  =  [%#010x] MI_LOAD_REGISTER_IMM: %d regs\n",
> +		drm_printf(p, "LRC[%#5zx]  =  [%#010x] MI_LOAD_REGISTER_IMM: %d regs\n",
>  			   dw - start, inst_header, (numdw - 1) / 2);
>  		for (int i = 1; i < numdw; i += 2)
> -			drm_printf(p, "LRC[%#5lx]  =  - %#6x = %#010x\n",
> +			drm_printf(p, "LRC[%#5zx]  =  - %#6x = %#010x\n",
>  				   &dw[i] - start, dw[i], dw[i + 1]);
>  		return numdw;
>  
>  	case MI_LOAD_REGISTER_MEM & MI_OPCODE:
> -		drm_printf(p, "LRC[%#5lx]  =  [%#010x] MI_LOAD_REGISTER_MEM: %s%s\n",
> +		drm_printf(p, "LRC[%#5zx]  =  [%#010x] MI_LOAD_REGISTER_MEM: %s%s\n",
>  			   dw - start, inst_header,
>  			   dw[0] & MI_LRI_LRM_CS_MMIO ? "CS_MMIO " : "",
>  			   dw[0] & MI_LRM_USE_GGTT ? "USE_GGTT " : "");
>  		if (numdw == 4)
> -			drm_printf(p, "LRC[%#5lx]  =  - %#6x = %#010llx\n",
> +			drm_printf(p, "LRC[%#5zx]  =  - %#6x = %#010llx\n",
>  				   dw - start,
>  				   dw[1], ((u64)(dw[3]) << 32 | (u64)(dw[2])));
>  		else
> -			drm_printf(p, "LRC[%#5lx]  =  - %*ph (%s)\n",
> +			drm_printf(p, "LRC[%#5zx]  =  - %*ph (%s)\n",
>  				   dw - start, (int)sizeof(u32) * (numdw - 1),
>  				   dw + 1, numdw < 4 ? "truncated" : "malformed");
>  		return numdw;
>  
>  	case MI_FORCE_WAKEUP:
> -		drm_printf(p, "LRC[%#5lx]  =  [%#010x] MI_FORCE_WAKEUP\n",
> +		drm_printf(p, "LRC[%#5zx]  =  [%#010x] MI_FORCE_WAKEUP\n",
>  			   dw - start, inst_header);
>  		return numdw;
>  
>  	default:
> -		drm_printf(p, "LRC[%#5lx]  =  [%#010x] unknown MI opcode %#x, likely %d dwords\n",
> +		drm_printf(p, "LRC[%#5zx]  =  [%#010x] unknown MI opcode %#x, likely %d dwords\n",
>  			   dw - start, inst_header, opcode, numdw);
>  		return numdw;
>  	}
> @@ -1989,12 +1989,12 @@ static int dump_gfxpipe_command(struct drm_printer *p,
>  	switch (*dw & GFXPIPE_MATCH_MASK) {
>  #define MATCH(cmd) \
>  	case cmd: \
> -		drm_printf(p, "LRC[%#5lx]  =  [%#010x] " #cmd " (%d dwords)\n", \
> +		drm_printf(p, "LRC[%#5zx]  =  [%#010x] " #cmd " (%d dwords)\n", \
>  			   dw - start, *dw, numdw); \
>  		return numdw
>  #define MATCH3D(cmd) \
>  	case CMD_##cmd: \
> -		drm_printf(p, "LRC[%#5lx]  =  [%#010x] " #cmd " (%d dwords)\n", \
> +		drm_printf(p, "LRC[%#5zx]  =  [%#010x] " #cmd " (%d dwords)\n", \
>  			   dw - start, *dw, numdw); \
>  		return numdw
>  
> @@ -2127,7 +2127,7 @@ static int dump_gfxpipe_command(struct drm_printer *p,
>  	MATCH3D(3DSTATE_SLICE_TABLE_STATE_POINTER_2);
>  
>  	default:
> -		drm_printf(p, "LRC[%#5lx]  =  [%#010x] unknown GFXPIPE command (pipeline=%#x, opcode=%#x, subopcode=%#x), likely %d dwords\n",
> +		drm_printf(p, "LRC[%#5zx]  =  [%#010x] unknown GFXPIPE command (pipeline=%#x, opcode=%#x, subopcode=%#x), likely %d dwords\n",
>  			   dw - start, *dw, pipeline, opcode, subopcode, numdw);
>  		return numdw;
>  	}
> @@ -2153,7 +2153,7 @@ static int dump_gfx_state_command(struct drm_printer *p,
>  	MATCH(STATE_WRITE_INLINE);
>  
>  	default:
> -		drm_printf(p, "LRC[%#5lx]  =  [%#010x] unknown GFX_STATE command (opcode=%#x), likely %d dwords\n",
> +		drm_printf(p, "LRC[%#5zx]  =  [%#010x] unknown GFX_STATE command (opcode=%#x), likely %d dwords\n",
>  			   dw - start, *dw, opcode, numdw);
>  		return numdw;
>  	}
> @@ -2188,7 +2188,7 @@ void xe_lrc_dump_default(struct drm_printer *p,
>  			num_dw = dump_gfx_state_command(p, gt, start, dw, remaining_dw);
>  		} else {
>  			num_dw = min(instr_dw(*dw), remaining_dw);
> -			drm_printf(p, "LRC[%#5lx]  =  [%#10x] Unknown instruction of type %#x, likely %d dwords\n",
> +			drm_printf(p, "LRC[%#5zx]  =  [%#10x] Unknown instruction of type %#x, likely %d dwords\n",
>  				   dw - start,
>  				   *dw, REG_FIELD_GET(XE_INSTR_CMD_TYPE, *dw),
>  				   num_dw);
> -- 
> 2.39.5
> 

-- 
Matt Roper
Graphics Software Engineer
Linux GPU Platform Enablement
Intel Corporation

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/xe: use %z format string for ptrdiff_t
  2026-03-16 22:51 ` Matt Roper
@ 2026-03-16 23:07   ` Arnd Bergmann
  2026-03-17 14:56     ` David Laight
  0 siblings, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2026-03-16 23:07 UTC (permalink / raw)
  To: Matt Roper, Arnd Bergmann
  Cc: Matthew Brost, Thomas Hellström, Rodrigo Vivi, Dave Airlie,
	Simona Vetter, Dnyaneshwar Bhadane, Lucas De Marchi,
	Tvrtko Ursulin, Umesh Nerlige Ramappa, Raag Jadav,
	Niranjana Vishwanathapura, intel-xe, dri-devel, linux-kernel

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.

      Arnd

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/xe: use %z format string for ptrdiff_t
  2026-03-16 23:07   ` Arnd Bergmann
@ 2026-03-17 14:56     ` David Laight
  2026-03-17 16:46       ` David Laight
  0 siblings, 1 reply; 5+ messages in thread
From: David Laight @ 2026-03-17 14:56 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Matt Roper, Arnd Bergmann, Matthew Brost, Thomas Hellström,
	Rodrigo Vivi, Dave Airlie, Simona Vetter, Dnyaneshwar Bhadane,
	Lucas De Marchi, Tvrtko Ursulin, Umesh Nerlige Ramappa,
	Raag Jadav, Niranjana Vishwanathapura, intel-xe, dri-devel,
	linux-kernel

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
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/xe: use %z format string for ptrdiff_t
  2026-03-17 14:56     ` David Laight
@ 2026-03-17 16:46       ` David Laight
  0 siblings, 0 replies; 5+ messages in thread
From: David Laight @ 2026-03-17 16:46 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Matt Roper, Arnd Bergmann, Matthew Brost, Thomas Hellström,
	Rodrigo Vivi, Dave Airlie, Simona Vetter, Dnyaneshwar Bhadane,
	Lucas De Marchi, Tvrtko Ursulin, Umesh Nerlige Ramappa,
	Raag Jadav, Niranjana Vishwanathapura, intel-xe, dri-devel,
	linux-kernel

On Tue, 17 Mar 2026 14:56:47 +0000
David Laight <david.laight.linux@gmail.com> wrote:

> 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'.

I should have said 'the same size as long'.

> 
> 	David
> 
> 
> > 
> >       Arnd
> >   
> 
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-03-17 16:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-03-17 16:46       ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox