bcache: replace snprintf in show functions with sysfs_emit
PATCH 1/1 bcache: replace snprintf in show functions with sysfs_emit
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.
--- drivers/md/bcache/sysfs.c | 2 +- drivers/md/bcache/sysfs.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/md/bcache/sysfs.c +1 -1
@@ -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"
drivers/md/bcache/sysfs.h +1 -1
@@ -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) \
Signature · 1 line
2.7.4
Quoted 18 lines · Qing Wang
coccicheck complains about the use of
snprintf()in sysfs show functions.Fix the coccicheck warning:
WARNING: use scnprintf or sprintf.Use
sysfs_emitinstead of scnprintf or sprintf makes more sense.Signed-off-by Qing Wang <[email protected]>--- drivers/md/bcache/sysfs.c | 2 +- drivers/md/bcache/sysfs.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/md/bcache/sysfs.c +0
-0
drivers/md/bcache/sysfs.c static int bch_bset_print_stats(struct cache_set *c, char *buf) · line 645
Quoted 8 lines
drivers/md/bcache/sysfs.c +1
-1@@ -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.
drivers/md/bcache/sysfs.h STORE(fn) \ · line 57
Quoted 13 lines
drivers/md/bcache/sysfs.h +1
-1@@ -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
A message that is not in the archive (sent off-list or not yet received): AI*[email protected]
Quoted 20 lines
Quoted 13 lines
drivers/md/bcache/sysfs.h +1
-1@@ -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)Quoted 2 lines
#definesysfs_print(file, var)\IMHO I like this change :-) BTW, for
snprint()fromutil.h, it seems only to be used bysysfs_print()insyfs.h, would you like to change it to usesysfs_emittoo ?
Quoted 4 lines
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
Quoted 17 lines · 王擎
Quoted 17 lines
drivers/md/bcache/sysfs.h STORE(fn) \ · line 57
Quoted 13 lines
drivers/md/bcache/sysfs.h +1
-1@@ -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()fromutil.h, it seems only to be used bysysfs_print()insyfs.h, would you like to change it to usesysfs_emittoo ?
Quoted 6 lines
Quoted 4 lines
Thanks for the patch.
Coly Li
sysfs_print()should also be modified if size is a fixed valuePAGE_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