Commit c86a2d90 authored by Tobias Klauser's avatar Tobias Klauser Committed by Greg Kroah-Hartman

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/20210806110251.560-1-song.bao.hua@hisilicon.com/

Fixes: 1fae5629 ("cpumask: introduce cpumap_print_list/bitmask_to_buf to support large bitmask and list")
Acked-by: default avatarBarry Song <song.bao.hua@hisilicon.com>
Acked-by: default avatarYury Norov <yury.norov@gmail.com>
Signed-off-by: default avatarTobias Klauser <tklauser@distanz.ch>
Link: https://lore.kernel.org/r/20210916222705.13554-1-tklauser@distanz.chSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent af505cad
...@@ -996,14 +996,15 @@ cpumap_print_to_pagebuf(bool list, char *buf, const struct cpumask *mask) ...@@ -996,14 +996,15 @@ cpumap_print_to_pagebuf(bool list, char *buf, const struct cpumask *mask)
* cpumask; Typically used by bin_attribute to export cpumask bitmask * cpumask; Typically used by bin_attribute to export cpumask bitmask
* ABI. * ABI.
* *
* Returns the length of how many bytes have been copied. * Returns the length of how many bytes have been copied, excluding
* terminating '\0'.
*/ */
static inline ssize_t static inline ssize_t
cpumap_print_bitmask_to_buf(char *buf, const struct cpumask *mask, cpumap_print_bitmask_to_buf(char *buf, const struct cpumask *mask,
loff_t off, size_t count) loff_t off, size_t count)
{ {
return bitmap_print_bitmask_to_buf(buf, cpumask_bits(mask), return bitmap_print_bitmask_to_buf(buf, cpumask_bits(mask),
nr_cpu_ids, off, count); nr_cpu_ids, off, count) - 1;
} }
/** /**
...@@ -1018,7 +1019,7 @@ cpumap_print_list_to_buf(char *buf, const struct cpumask *mask, ...@@ -1018,7 +1019,7 @@ cpumap_print_list_to_buf(char *buf, const struct cpumask *mask,
loff_t off, size_t count) loff_t off, size_t count)
{ {
return bitmap_print_list_to_buf(buf, cpumask_bits(mask), return bitmap_print_list_to_buf(buf, cpumask_bits(mask),
nr_cpu_ids, off, count); nr_cpu_ids, off, count) - 1;
} }
#if NR_CPUS <= BITS_PER_LONG #if NR_CPUS <= BITS_PER_LONG
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment