* [PATCH] bcache: replace snprintf in show functions with sysfs_emit
@ 2021-10-13 3:27 Qing Wang
2021-10-13 6:59 ` Coly Li
[not found] ` <AI*ALgD1Em5Q2PfGyVlLhqrx.9.1634108359294.Hmail.wangqing@vivo.com>
0 siblings, 2 replies; 4+ messages in thread
From: Qing Wang @ 2021-10-13 3:27 UTC (permalink / raw)
To: Coly Li, Kent Overstreet, linux-bcache, linux-kernel; +Cc: Qing Wang
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@vivo.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"
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) \
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] bcache: replace snprintf in show functions with sysfs_emit
2021-10-13 3:27 [PATCH] bcache: replace snprintf in show functions with sysfs_emit Qing Wang
@ 2021-10-13 6:59 ` Coly Li
[not found] ` <AI*ALgD1Em5Q2PfGyVlLhqrx.9.1634108359294.Hmail.wangqing@vivo.com>
1 sibling, 0 replies; 4+ messages in thread
From: Coly Li @ 2021-10-13 6:59 UTC (permalink / raw)
To: Qing Wang; +Cc: Kent Overstreet, linux-bcache, linux-kernel
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@vivo.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
^ permalink raw reply [flat|nested] 4+ messages in thread
* 回复: [PATCH] bcache: replace snprintf in show functions with sysfs_emit
[not found] ` <AI*ALgD1Em5Q2PfGyVlLhqrx.9.1634108359294.Hmail.wangqing@vivo.com>
@ 2021-10-13 7:39 ` 王擎
2021-10-13 7:51 ` Coly Li
0 siblings, 1 reply; 4+ messages in thread
From: 王擎 @ 2021-10-13 7:39 UTC (permalink / raw)
To: Coly Li; +Cc: linux-bcache, linux-kernel
>>
>> 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
>
sysfs_print() should also be modified if size is a fixed value PAGE_SIZE,
but here is param, it would be appreciate if you have better method.
Thanks,
Qing
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: 回复: [PATCH] bcache: replace snprintf in show functions with sysfs_emit
2021-10-13 7:39 ` 回复: " 王擎
@ 2021-10-13 7:51 ` Coly Li
0 siblings, 0 replies; 4+ messages in thread
From: Coly Li @ 2021-10-13 7:51 UTC (permalink / raw)
To: 王擎; +Cc: linux-bcache, linux-kernel
On 10/13/21 3:39 PM, 王擎 wrote:
>>> 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
>>
> sysfs_print() should also be modified if size is a fixed value PAGE_SIZE,
> but here is param, it would be appreciate if you have better method.
Yes, I meant you may implement sysfs_print() by sysfs_emit() directly in
the way as snprint() does. Then you may remove snprint() since no one
uses it any more.
Coly Li
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-10-13 7:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-13 3:27 [PATCH] bcache: replace snprintf in show functions with sysfs_emit Qing Wang
2021-10-13 6:59 ` Coly Li
[not found] ` <AI*ALgD1Em5Q2PfGyVlLhqrx.9.1634108359294.Hmail.wangqing@vivo.com>
2021-10-13 7:39 ` 回复: " 王擎
2021-10-13 7:51 ` Coly Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).