mm/oom_kill: Remove unnecessary integer promotion in format string
Subsystems (2)
PATCH 1/1 mm/oom_kill: Remove unnecessary integer promotion in format string
The 'h' length modifier in '%hd' is unnecessary as short integers are promoted to int in variadic functions. Use '%d' instead.
--- mm/oom_kill.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/oom_kill.c +2 -2
@@ -458,7 +458,7 @@ static void dump_oom_victim(struct oom_control *oc, struct task_struct *victim)static void dump_header (struct oom_control *oc) { -pr_warn ("%s invoked oom-killer: gfp_mask=%#x(%pGg), order=%d, oom_score_adj=%hd\n" , +pr_warn ("%s invoked oom-killer: gfp_mask=%#x(%pGg), order=%d, oom_score_adj=%d\n" , current->comm, oc->gfp_mask, &oc->gfp_mask, oc->order, current->signal->oom_score_adj);if (!IS_ENABLED (CONFIG_COMPACTION ) && oc->order)
@@ -958,7 +958,7 @@ static void __oom_kill_process(struct task_struct *victim, const char *message)*/ do_send_sig_info (SIGKILL ,SEND_SIG_PRIV , victim,PIDTYPE_TGID );mark_oom_victim (victim); - pr_err("%s: Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB, UID:%u pgtables:%lukB oom_score_adj:%hd\n", + pr_err("%s: Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB, UID:%u pgtables:%lukB oom_score_adj:%d\n", message, task_pid_nr(victim), victim->comm, K(mm->total_vm), K(get_mm_counter(mm, MM_ANONPAGES)), K(get_mm_counter(mm, MM_FILEPAGES)),
Signature · 1 line
2.43.0
Quoted 4 lines · Dipendra Khadka
The 'h' length modifier in '%hd' is unnecessary as short integers are promoted to int in variadic functions. Use '%d' instead.
Signed-off-by Dipendra Khadka <[email protected]>
I don't have a strong opinion given this will result in the same output.
Michal Hocko
maintainerQuoted 4 lines · Dipendra Khadka
The 'h' length modifier in '%hd' is unnecessary as short integers are promoted to int in variadic functions. Use '%d' instead.
Signed-off-by Dipendra Khadka <[email protected]>
Why should we change the currently correct code in the first place? What is an added value?
Signature · 2 lines
Michal Hocko SUSE Labs
Andrew Morton
maintainerQuoted 8 lines · On Mon, 29 Dec 2025 09:27:18 +0100 Michal Hocko <[email protected]> wrote:
Quoted 4 lines · Dipendra Khadka
The 'h' length modifier in '%hd' is unnecessary as short integers are promoted to int in variadic functions. Use '%d' instead.
Signed-off-by Dipendra Khadka <[email protected]>Why should we change the currently correct code in the first place? What is an added value?
It reduces vmlinux by 2 bytes ;)
It's a teeny issue but I do like the present code - be very explicit and careful about the types we're dealing with, don't rely on unobvious C rules.
Quoted 3 lines
It's a teeny issue but I do like the present code - be very explicit and careful about the types we're dealing with, don't rely on unobvious C rules.
Actually, the scenario here is that while printing a short, it is **promoted** to int due to C's variadic argument promotion rules.
Yes, we must use %hd when the **semantic type** is short. However, due to integer promotion, the value is already passed as a 4-byte int on the stack. The %hd format specifier then casts it back to short for display.
Since the value is already promoted to int internally, using %d is simpler and avoids the unnecessary cast. The checkpatch warning confirms this:
```
WARNING: Integer promotion: Using 'h' in '%hd' is unnecessary
#461: FILE: mm/oom_kill.c:461:
+ pr_warn("%s invoked oom-killer: gfp_mask=%#x(%pGg), order=%d, oom_score_adj=%hd\n",
+ current->comm, oc->gfp_mask, &oc->gfp_mask, oc->order,
+ current->signal->oom_score_adj);
WARNING: Integer promotion: Using 'h' in '%hd' is unnecessary
#961: FILE: mm/oom_kill.c:961:
+ pr_err("%s: Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB, UID:%u pgtables:%lukB oom_score_adj:%hd\n",
+ message, task_pid_nr(victim), victim->comm, K(mm->total_vm),
+ K(get_mm_counter(mm, MM_ANONPAGES)),
+ K(get_mm_counter(mm, MM_FILEPAGES)),
+ K(get_mm_counter(mm, MM_SHMEMPAGES)),
+ from_kuid(&init_user_ns, task_uid(victim)),
+ mm_pgtables_bytes(mm) >> 10, victim->signal->oom_score_adj);
```Checkpatch flags the 'h' modifier as unnecessary for this reason, and many other subsystems have moved to using %d for promoted types. Hence, I think this patch aligns with kernel coding practices.
Best Rgards,
Dipendra Khadka
Andrew Morton
maintainerQuoted 23 lines · On Wed, 31 Dec 2025 12:21:17 +0000 Dipendra Khadka <[email protected]>…
Since the value is already promoted to int internally, using %d is simpler and avoids the unnecessary cast. The checkpatch warning confirms this:
```
WARNING: Integer promotion: Using 'h' in '%hd' is unnecessary #461: FILE:mm/oom_kill.c:461:(quoted diff) +3
-0+ pr_warn("%s invoked oom-killer: gfp_mask=%#x(%pGg), order=%d, oom_score_adj=%hd\n", + current->comm, oc->gfp_mask, &oc->gfp_mask, oc->order, + current->signal->oom_score_adj);WARNING: Integer promotion: Using 'h' in '%hd' is unnecessary #961: FILE:
mm/oom_kill.c:961:(quoted diff) +7
-0+ pr_err("%s: Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB, UID:%u pgtables:%lukB oom_score_adj:%hd\n", + message, task_pid_nr(victim), victim->comm, K(mm->total_vm), + K(get_mm_counter(mm, MM_ANONPAGES)), + K(get_mm_counter(mm, MM_FILEPAGES)), + K(get_mm_counter(mm, MM_SHMEMPAGES)), + from_kuid(&init_user_ns, task_uid(victim)), + mm_pgtables_bytes(mm) >> 10, victim->signal->oom_score_adj);```
Quoted 3 lines
Checkpatch flags the 'h' modifier as unnecessary for this reason, and many other subsystems have moved to using %d for promoted types. Hence, I think this patch aligns with kernel coding practices.
hm, OK, this code is pretty lonely.
hp2:/usr/src/linux-6.19-rc3> grep -r "%hd" . | wc -l 50
Consistency is good.
On Wed 31-12-25 12:21:17, Dipendra Khadka wrote:
[...]
Quoted 3 lines
Checkpatch flags the 'h' modifier as unnecessary for this reason, and many other subsystems have moved to using %d for promoted types. Hence, I think this patch aligns with kernel coding practices.
And here, this is the actual argument to push change like that. On its own this is not really worth it. But if there is a general push to remove %hd then sure change like this makes us closer to do that and quite honestly I am not a great fan of %hd. I will not miss it.
Please update the changelog and then feel free to add
Thanks!
Signature · 2 lines
Michal Hocko SUSE Labs