From: "Song Bao Hua (Barry Song)" <song.bao.hua@hisilicon.com>
To: Tobias Klauser <tklauser@distanz.ch>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jonathan Cameron <jonathan.cameron@huawei.com>,
"tiantao (H)" <tiantao6@hisilicon.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Yury Norov <yury.norov@gmail.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] cpumask: Omit terminating null byte in cpumap_print_{list,bitmask}_to_buf
Date: Thu, 16 Sep 2021 22:53:39 +0000 [thread overview]
Message-ID: <aa4bc59c44b345ae814c61f6593a7178@hisilicon.com> (raw)
In-Reply-To: <20210916222705.13554-1-tklauser@distanz.ch>
> -----Original Message-----
> From: Tobias Klauser [mailto:tklauser@distanz.ch]
> Sent: Friday, September 17, 2021 10:27 AM
> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>; Jonathan Cameron
> <jonathan.cameron@huawei.com>; tiantao (H) <tiantao6@hisilicon.com>; Song Bao
> Hua (Barry Song) <song.bao.hua@hisilicon.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>; Andy Shevchenko
> <andriy.shevchenko@linux.intel.com>; Yury Norov <yury.norov@gmail.com>; Peter
> Zijlstra <peterz@infradead.org>; linux-kernel@vger.kernel.org
> Subject: [PATCH] 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.
If we don't use xxd, I don't see any actual harm of this NULL byte
by cat, lscpu, numactl etc. this doesn't break them at all.
if we only want to make sure the output is exactly same with before
for every single character, this patch is right.
>
> 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.co
> m/
>
> Fixes: 1fae562983ca ("cpumask: introduce cpumap_print_list/bitmask_to_buf to
> support large bitmask and list")
> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
> ---
> include/linux/cpumask.h | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
> index 5d4d07a9e1ed..1e7399fc69c0 100644
> --- a/include/linux/cpumask.h
> +++ b/include/linux/cpumask.h
> @@ -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
> * 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
> 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);
> + nr_cpu_ids, off, count) - 1;
> }
>
> /**
> @@ -1018,7 +1019,7 @@ 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);
> + nr_cpu_ids, off, count) - 1;
> }
>
> #if NR_CPUS <= BITS_PER_LONG
> --
> 2.33.0
Thanks
Barry
next prev parent reply other threads:[~2021-09-16 22:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-16 22:27 [PATCH] cpumask: Omit terminating null byte in cpumap_print_{list,bitmask}_to_buf Tobias Klauser
2021-09-16 22:53 ` Song Bao Hua (Barry Song) [this message]
2021-09-16 23:19 ` Yury Norov
2021-09-17 8:45 ` Tobias Klauser
2021-09-19 7:33 ` Barry Song
2021-09-19 7:52 ` Greg Kroah-Hartman
2021-09-30 10:30 ` Antti Kervinen
2021-09-30 10:43 ` Greg KH
2021-09-30 12:29 ` Antti Kervinen
2021-09-30 10:46 ` Barry Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aa4bc59c44b345ae814c61f6593a7178@hisilicon.com \
--to=song.bao.hua@hisilicon.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=jonathan.cameron@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=tiantao6@hisilicon.com \
--cc=tklauser@distanz.ch \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.