* [PATCH] cpumask: Preserve short reads in cpumap printing helpers
@ 2026-10-20 17:01 Hungyu Lin
2026-10-21 14:42 ` Tobias Klauser
2026-10-28 15:25 ` Yury Norov
0 siblings, 2 replies; 3+ messages in thread
From: Hungyu Lin @ 2026-10-20 17:01 UTC (permalink / raw)
To: yury.norov; +Cc: linux, tklauser, linux-kernel, Hungyu Lin
The cpumap printing helpers unconditionally subtract one from the bitmap
helper's return value to exclude a terminating NUL. A partial read may
not reach that NUL, so this also subtracts a data byte from the returned
length. A one-byte read therefore returns zero even when data remains.
For example, this command prints nothing despite the file being nonempty:
head -c 1 /sys/devices/system/cpu/cpu0/topology/core_cpus_list
Subtract one only when the copied range actually ends in NUL. This
preserves short reads, EOF and negative error returns while continuing
to exclude the terminator from complete sysfs reads.
Fixes: c86a2d9058c5 ("cpumask: Omit terminating null byte in cpumap_print_{list,bitmask}_to_buf")
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
include/linux/cpumask.h | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 4c8bb6953107..2caeae982faf 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -1334,8 +1334,14 @@ static __always_inline
ssize_t cpumap_print_bitmask_to_buf(char *buf, const struct cpumask *mask,
loff_t off, size_t count)
{
- return bitmap_print_bitmask_to_buf(buf, cpumask_bits(mask),
- nr_cpu_ids, off, count) - 1;
+ ssize_t n;
+
+ n = bitmap_print_bitmask_to_buf(buf, cpumask_bits(mask),
+ nr_cpu_ids, off, count);
+ if (n > 0 && buf[n - 1] == '\0')
+ n--;
+
+ return n;
}
/**
@@ -1356,8 +1362,14 @@ static __always_inline
ssize_t cpumap_print_list_to_buf(char *buf, const struct cpumask *mask,
loff_t off, size_t count)
{
- return bitmap_print_list_to_buf(buf, cpumask_bits(mask),
- nr_cpu_ids, off, count) - 1;
+ ssize_t n;
+
+ n = bitmap_print_list_to_buf(buf, cpumask_bits(mask),
+ nr_cpu_ids, off, count);
+ if (n > 0 && buf[n - 1] == '\0')
+ n--;
+
+ return n;
}
#if NR_CPUS <= BITS_PER_LONG
base-commit: a73b4d1fa7d334a5f7de5bb0a14726530f66196e
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] cpumask: Preserve short reads in cpumap printing helpers
2026-10-20 17:01 [PATCH] cpumask: Preserve short reads in cpumap printing helpers Hungyu Lin
@ 2026-10-21 14:42 ` Tobias Klauser
2026-10-28 15:25 ` Yury Norov
1 sibling, 0 replies; 3+ messages in thread
From: Tobias Klauser @ 2026-10-21 14:42 UTC (permalink / raw)
To: Hungyu Lin; +Cc: yury.norov, linux, linux-kernel
On 2026-10-20 at 19:01:26 +0200, Hungyu Lin <dennylin0707@gmail.com> wrote:
> The cpumap printing helpers unconditionally subtract one from the bitmap
> helper's return value to exclude a terminating NUL. A partial read may
> not reach that NUL, so this also subtracts a data byte from the returned
> length. A one-byte read therefore returns zero even when data remains.
> For example, this command prints nothing despite the file being nonempty:
>
> head -c 1 /sys/devices/system/cpu/cpu0/topology/core_cpus_list
>
> Subtract one only when the copied range actually ends in NUL. This
> preserves short reads, EOF and negative error returns while continuing
> to exclude the terminator from complete sysfs reads.
>
> Fixes: c86a2d9058c5 ("cpumask: Omit terminating null byte in cpumap_print_{list,bitmask}_to_buf")
> Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
Reviewed-by: Tobias Klauser <tklauser@distanz.ch>
Thanks
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] cpumask: Preserve short reads in cpumap printing helpers
2026-10-20 17:01 [PATCH] cpumask: Preserve short reads in cpumap printing helpers Hungyu Lin
2026-10-21 14:42 ` Tobias Klauser
@ 2026-10-28 15:25 ` Yury Norov
1 sibling, 0 replies; 3+ messages in thread
From: Yury Norov @ 2026-10-28 15:25 UTC (permalink / raw)
To: Hungyu Lin; +Cc: yury.norov, linux, tklauser, linux-kernel
On Tue, Oct 20, 2026 at 05:01:26PM +0000, Hungyu Lin wrote:
> The cpumap printing helpers unconditionally subtract one from the bitmap
> helper's return value to exclude a terminating NUL. A partial read may
> not reach that NUL, so this also subtracts a data byte from the returned
> length. A one-byte read therefore returns zero even when data remains.
> For example, this command prints nothing despite the file being nonempty:
>
> head -c 1 /sys/devices/system/cpu/cpu0/topology/core_cpus_list
>
> Subtract one only when the copied range actually ends in NUL. This
> preserves short reads, EOF and negative error returns while continuing
> to exclude the terminator from complete sysfs reads.
>
> Fixes: c86a2d9058c5 ("cpumask: Omit terminating null byte in cpumap_print_{list,bitmask}_to_buf")
> Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
Added in bitmap-for-next. Thanks!
> ---
> include/linux/cpumask.h | 20 ++++++++++++++++----
> 1 file changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
> index 4c8bb6953107..2caeae982faf 100644
> --- a/include/linux/cpumask.h
> +++ b/include/linux/cpumask.h
> @@ -1334,8 +1334,14 @@ static __always_inline
> ssize_t cpumap_print_bitmask_to_buf(char *buf, const struct cpumask *mask,
> loff_t off, size_t count)
> {
> - return bitmap_print_bitmask_to_buf(buf, cpumask_bits(mask),
> - nr_cpu_ids, off, count) - 1;
> + ssize_t n;
> +
> + n = bitmap_print_bitmask_to_buf(buf, cpumask_bits(mask),
> + nr_cpu_ids, off, count);
> + if (n > 0 && buf[n - 1] == '\0')
> + n--;
> +
> + return n;
> }
>
> /**
> @@ -1356,8 +1362,14 @@ static __always_inline
> ssize_t cpumap_print_list_to_buf(char *buf, const struct cpumask *mask,
> loff_t off, size_t count)
> {
> - return bitmap_print_list_to_buf(buf, cpumask_bits(mask),
> - nr_cpu_ids, off, count) - 1;
> + ssize_t n;
> +
> + n = bitmap_print_list_to_buf(buf, cpumask_bits(mask),
> + nr_cpu_ids, off, count);
> + if (n > 0 && buf[n - 1] == '\0')
> + n--;
> +
> + return n;
> }
>
> #if NR_CPUS <= BITS_PER_LONG
>
> base-commit: a73b4d1fa7d334a5f7de5bb0a14726530f66196e
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-28 15:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-20 17:01 [PATCH] cpumask: Preserve short reads in cpumap printing helpers Hungyu Lin
2026-10-21 14:42 ` Tobias Klauser
2026-10-28 15:25 ` Yury Norov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®