lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251231122117.7683-1-kdipendra88@gmail.com>
Date: Wed, 31 Dec 2025 12:21:17 +0000
From: Dipendra Khadka <kdipendra88@...il.com>
To: akpm@...ux-foundation.org
Cc: kdipendra88@...il.com,
	linux-kernel@...r.kernel.org,
	linux-mm@...ck.org,
	mhocko@...e.com,
	rientjes@...gle.com,
	shakeel.butt@...ux.dev
Subject: Re: [PATCH] mm/oom_kill: Remove unnecessary integer promotion in format string

>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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ