Skip to content

Commit c86a2d9

Browse files
tklausergregkh
authored andcommitted
cpumask: Omit terminating null byte in cpumap_print_{list,bitmask}_to_buf
The changes in the patch series [1] introduced a terminating null byte when reading from cpulist or cpumap sysfs files, for example: $ xxd /sys/devices/system/node/node0/cpulist 00000000: 302d 310a 00 0-1.. Before this change, the output looked as follows: $ xxd /sys/devices/system/node/node0/cpulist 00000000: 302d 310a 0-1. Fix this regression by excluding the terminating null byte from the returned length in cpumap_print_list_to_buf and cpumap_print_bitmask_to_buf. [1] https://lore.kernel.org/all/[email protected]/ Fixes: 1fae562 ("cpumask: introduce cpumap_print_list/bitmask_to_buf to support large bitmask and list") Acked-by: Barry Song <[email protected]> Acked-by: Yury Norov <[email protected]> Signed-off-by: Tobias Klauser <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent af505ca commit c86a2d9

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

include/linux/cpumask.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -996,14 +996,15 @@ cpumap_print_to_pagebuf(bool list, char *buf, const struct cpumask *mask)
996996
* cpumask; Typically used by bin_attribute to export cpumask bitmask
997997
* ABI.
998998
*
999-
* Returns the length of how many bytes have been copied.
999+
* Returns the length of how many bytes have been copied, excluding
1000+
* terminating '\0'.
10001001
*/
10011002
static inline ssize_t
10021003
cpumap_print_bitmask_to_buf(char *buf, const struct cpumask *mask,
10031004
loff_t off, size_t count)
10041005
{
10051006
return bitmap_print_bitmask_to_buf(buf, cpumask_bits(mask),
1006-
nr_cpu_ids, off, count);
1007+
nr_cpu_ids, off, count) - 1;
10071008
}
10081009

10091010
/**
@@ -1018,7 +1019,7 @@ cpumap_print_list_to_buf(char *buf, const struct cpumask *mask,
10181019
loff_t off, size_t count)
10191020
{
10201021
return bitmap_print_list_to_buf(buf, cpumask_bits(mask),
1021-
nr_cpu_ids, off, count);
1022+
nr_cpu_ids, off, count) - 1;
10221023
}
10231024

10241025
#if NR_CPUS <= BITS_PER_LONG

0 commit comments

Comments
 (0)