* [PATCH V2] bcache: replace snprintf in show functions with sysfs_emit
@ 2021-10-13 11:58 Qing Wang
2021-10-18 14:47 ` Coly Li
0 siblings, 1 reply; 2+ messages in thread
From: Qing Wang @ 2021-10-13 11:58 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 following coccicheck warning:
drivers/md/bcache/sysfs.h:54:12-20: WARNING: use scnprintf or sprintf.
Implement sysfs_print() by sysfs_emit() and remove snprint() since no one
uses it any more.
Suggested-by: Coly Li <colyli@suse.de>
Signed-off-by: Qing Wang <wangqing@vivo.com>
---
drivers/md/bcache/sysfs.h | 18 ++++++++++++++++--
drivers/md/bcache/util.h | 17 -----------------
2 files changed, 16 insertions(+), 19 deletions(-)
diff --git a/drivers/md/bcache/sysfs.h b/drivers/md/bcache/sysfs.h
index 215df32..c1752ba
--- a/drivers/md/bcache/sysfs.h
+++ b/drivers/md/bcache/sysfs.h
@@ -51,13 +51,27 @@ 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) \
do { \
if (attr == &sysfs_ ## file) \
- return snprint(buf, PAGE_SIZE, var); \
+ return sysfs_emit(buf, \
+ __builtin_types_compatible_p(typeof(var), int) \
+ ? "%i\n" : \
+ __builtin_types_compatible_p(typeof(var), unsigned int) \
+ ? "%u\n" : \
+ __builtin_types_compatible_p(typeof(var), long) \
+ ? "%li\n" : \
+ __builtin_types_compatible_p(typeof(var), unsigned long)\
+ ? "%lu\n" : \
+ __builtin_types_compatible_p(typeof(var), int64_t) \
+ ? "%lli\n" : \
+ __builtin_types_compatible_p(typeof(var), uint64_t) \
+ ? "%llu\n" : \
+ __builtin_types_compatible_p(typeof(var), const char *) \
+ ? "%s\n" : "%i\n", var); \
} while (0)
#define sysfs_hprint(file, val) \
diff --git a/drivers/md/bcache/util.h b/drivers/md/bcache/util.h
index b64460a..fecdea1
--- a/drivers/md/bcache/util.h
+++ b/drivers/md/bcache/util.h
@@ -340,23 +340,6 @@ static inline int bch_strtoul_h(const char *cp, long *res)
_r; \
})
-#define snprint(buf, size, var) \
- snprintf(buf, size, \
- __builtin_types_compatible_p(typeof(var), int) \
- ? "%i\n" : \
- __builtin_types_compatible_p(typeof(var), unsigned int) \
- ? "%u\n" : \
- __builtin_types_compatible_p(typeof(var), long) \
- ? "%li\n" : \
- __builtin_types_compatible_p(typeof(var), unsigned long)\
- ? "%lu\n" : \
- __builtin_types_compatible_p(typeof(var), int64_t) \
- ? "%lli\n" : \
- __builtin_types_compatible_p(typeof(var), uint64_t) \
- ? "%llu\n" : \
- __builtin_types_compatible_p(typeof(var), const char *) \
- ? "%s\n" : "%i\n", var)
-
ssize_t bch_hprint(char *buf, int64_t v);
bool bch_is_zero(const char *p, size_t n);
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH V2] bcache: replace snprintf in show functions with sysfs_emit
2021-10-13 11:58 [PATCH V2] bcache: replace snprintf in show functions with sysfs_emit Qing Wang
@ 2021-10-18 14:47 ` Coly Li
0 siblings, 0 replies; 2+ messages in thread
From: Coly Li @ 2021-10-18 14:47 UTC (permalink / raw)
To: Qing Wang; +Cc: Kent Overstreet, linux-bcache, linux-kernel
On 10/13/21 7:58 PM, Qing Wang wrote:
> coccicheck complains about the use of snprintf() in sysfs show functions.
>
> Fix the following coccicheck warning:
> drivers/md/bcache/sysfs.h:54:12-20: WARNING: use scnprintf or sprintf.
>
> Implement sysfs_print() by sysfs_emit() and remove snprint() since no one
> uses it any more.
>
> Suggested-by: Coly Li <colyli@suse.de>
> Signed-off-by: Qing Wang <wangqing@vivo.com>
It looks fine to me. Let me add it into my for-test directory.
Thanks for the fix up.
Coly Li
> ---
> drivers/md/bcache/sysfs.h | 18 ++++++++++++++++--
> drivers/md/bcache/util.h | 17 -----------------
> 2 files changed, 16 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/md/bcache/sysfs.h b/drivers/md/bcache/sysfs.h
> index 215df32..c1752ba
> --- a/drivers/md/bcache/sysfs.h
> +++ b/drivers/md/bcache/sysfs.h
> @@ -51,13 +51,27 @@ 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) \
> do { \
> if (attr == &sysfs_ ## file) \
> - return snprint(buf, PAGE_SIZE, var); \
> + return sysfs_emit(buf, \
> + __builtin_types_compatible_p(typeof(var), int) \
> + ? "%i\n" : \
> + __builtin_types_compatible_p(typeof(var), unsigned int) \
> + ? "%u\n" : \
> + __builtin_types_compatible_p(typeof(var), long) \
> + ? "%li\n" : \
> + __builtin_types_compatible_p(typeof(var), unsigned long)\
> + ? "%lu\n" : \
> + __builtin_types_compatible_p(typeof(var), int64_t) \
> + ? "%lli\n" : \
> + __builtin_types_compatible_p(typeof(var), uint64_t) \
> + ? "%llu\n" : \
> + __builtin_types_compatible_p(typeof(var), const char *) \
> + ? "%s\n" : "%i\n", var); \
> } while (0)
>
> #define sysfs_hprint(file, val) \
> diff --git a/drivers/md/bcache/util.h b/drivers/md/bcache/util.h
> index b64460a..fecdea1
> --- a/drivers/md/bcache/util.h
> +++ b/drivers/md/bcache/util.h
> @@ -340,23 +340,6 @@ static inline int bch_strtoul_h(const char *cp, long *res)
> _r; \
> })
>
> -#define snprint(buf, size, var) \
> - snprintf(buf, size, \
> - __builtin_types_compatible_p(typeof(var), int) \
> - ? "%i\n" : \
> - __builtin_types_compatible_p(typeof(var), unsigned int) \
> - ? "%u\n" : \
> - __builtin_types_compatible_p(typeof(var), long) \
> - ? "%li\n" : \
> - __builtin_types_compatible_p(typeof(var), unsigned long)\
> - ? "%lu\n" : \
> - __builtin_types_compatible_p(typeof(var), int64_t) \
> - ? "%lli\n" : \
> - __builtin_types_compatible_p(typeof(var), uint64_t) \
> - ? "%llu\n" : \
> - __builtin_types_compatible_p(typeof(var), const char *) \
> - ? "%s\n" : "%i\n", var)
> -
> ssize_t bch_hprint(char *buf, int64_t v);
>
> bool bch_is_zero(const char *p, size_t n);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-18 14:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-13 11:58 [PATCH V2] bcache: replace snprintf in show functions with sysfs_emit Qing Wang
2021-10-18 14:47 ` 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).