Skip to contentSkip to conversation

drm/ttm: handle undefined printf arg evaluation order in debugfs

PATCH In review Dave Airlie 2 participants 2 messages Jun 3, 2025 – Jun 4, 2025

Subsystems (3)
lore
Share & tools
lore

Dave Airlie

author maintainer
#0 lore raw

PATCH 1/1 drm/ttm: handle undefined printf arg evaluation order in debugfs

From: Dave Airlie <[email protected]>

When you read this debugfs file it's isn't guaranteed the count will happen before the scan, but I think the intent is that it does.

printf argument evaluation order is undefined.

Cc Christian Koenig <[email protected]>
---
 drivers/gpu/drm/ttm/ttm_pool.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_pool.c +3 -1
index 4b16946d3248..14f5aee69ee5 100644
@@ -1280,9 +1280,11 @@ static int ttm_pool_debugfs_shrink_show(struct seq_file *m, void *data)
 		.gfp_mask = GFP_NOFS,
 		.nr_to_scan = TTM_SHRINKER_BATCH,
 	};
+	unsigned long count;
 
 	fs_reclaim_acquire(GFP_KERNEL);
-	seq_printf(m, "%lu/%lu\n", ttm_pool_shrinker_count(mm_shrinker, &sc),
+	count = ttm_pool_shrinker_count(mm_shrinker, &sc),
+	seq_printf(m, "%lu/%lu\n", count,
 		   ttm_pool_shrinker_scan(mm_shrinker, &sc));
 	fs_reclaim_release(GFP_KERNEL);
 
Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Dave Airlie

From: Dave Airlie <[email protected]>

When you read this debugfs file it's isn't guaranteed the count will happen before the scan, but I think the intent is that it does.

printf argument evaluation order is undefined.

Cc Christian Koenig <[email protected]>
Quoted 21 lines
---
 drivers/gpu/drm/ttm/ttm_pool.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_pool.c +3 -1
index 4b16946d3248..14f5aee69ee5 100644
@@ -1280,9 +1280,11 @@ static int ttm_pool_debugfs_shrink_show(struct seq_file *m, void *data)
 		.gfp_mask = GFP_NOFS,
 		.nr_to_scan = TTM_SHRINKER_BATCH,
 	};
+	unsigned long count;
 
 	fs_reclaim_acquire(GFP_KERNEL);
-	seq_printf(m, "%lu/%lu\n", ttm_pool_shrinker_count(mm_shrinker, &sc),
+	count = ttm_pool_shrinker_count(mm_shrinker, &sc),
+	seq_printf(m, "%lu/%lu\n", count,
 		   ttm_pool_shrinker_scan(mm_shrinker, &sc));
 	fs_reclaim_release(GFP_KERNEL);