[PATCH v4 3/5] lib/vsprintf: Use in_task() for restricted pointer context check

From: Thomas Weißschuh

Date: Mon Jun 08 2026 - 10:28:24 EST


in_task() is a easier to read and slightly more efficient variant of
the existing tests.

Suggested-by: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Link: https://lore.kernel.org/lkml/20260504130044.GU3126523@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx>
---
lib/vsprintf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 33e0778fca52..6095b5f0d022 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -874,7 +874,7 @@ char *restricted_pointer(char *buf, char *end, const void *ptr,
* kptr_restrict==1 cannot be used in IRQ context
* because its test for CAP_SYSLOG would be meaningless.
*/
- if (in_hardirq() || in_serving_softirq() || in_nmi()) {
+ if (!in_task()) {
if (spec.field_width == -1)
spec.field_width = 2 * sizeof(ptr);
return error_string(buf, end, "pK-error", spec);

--
2.54.0