[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <2df27e53-c77f-b938-abf4-4e22271ee3d7@suse.de>
Date: Wed, 13 Oct 2021 14:59:09 +0800
From: Coly Li <colyli@...e.de>
To: Qing Wang <wangqing@...o.com>
Cc: Kent Overstreet <kent.overstreet@...il.com>,
linux-bcache@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] bcache: replace snprintf in show functions with
sysfs_emit
On 10/13/21 11:27 AM, Qing Wang wrote:
> coccicheck complains about the use of snprintf() in sysfs show functions.
>
> Fix the coccicheck warning:
> WARNING: use scnprintf or sprintf.
>
> Use sysfs_emit instead of scnprintf or sprintf makes more sense.
>
> Signed-off-by: Qing Wang <wangqing@...o.com>
> ---
> drivers/md/bcache/sysfs.c | 2 +-
> drivers/md/bcache/sysfs.h | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
> index 05ac1d6..e146c9e 100644
> --- a/drivers/md/bcache/sysfs.c
> +++ b/drivers/md/bcache/sysfs.c
> @@ -639,7 +639,7 @@ static int bch_bset_print_stats(struct cache_set *c, char *buf)
> if (ret < 0)
> return ret;
>
> - return snprintf(buf, PAGE_SIZE,
> + return sysfs_emit(buf,
> "btree nodes: %zu\n"
> "written sets: %zu\n"
> "unwritten sets: %zu\n"
Let's keep this location as snprintf(), to make code style be consistent.
> diff --git a/drivers/md/bcache/sysfs.h b/drivers/md/bcache/sysfs.h
> index 215df32..8bec32d 100644
> --- a/drivers/md/bcache/sysfs.h
> +++ b/drivers/md/bcache/sysfs.h
> @@ -51,7 +51,7 @@ STORE(fn) \
> #define sysfs_printf(file, fmt, ...) \
> do { \
> if (attr == &sysfs_ ## file) \
> - return snprintf(buf, PAGE_SIZE, fmt "\n", __VA_ARGS__); \
> + return sysfs_emit(buf, fmt "\n", __VA_ARGS__); \
> } while (0)
>
> #define sysfs_print(file, var) \
IMHO I like this change :-) BTW, for snprint() from util.h, it seems
only to be used by sysfs_print() in syfs.h, would you like to change it
to use sysfs_emit too ?
Thanks for the patch.
Coly Li
Powered by blists - more mailing lists