[PATCH 0/2] bcache paches for Linux v5.16 (2nd wave)

STALE1746d

Revision v1 of 2 in this series.

4 messages, 2 authors, 2021-10-29 · open the first message on its own page

[PATCH 0/2] bcache paches for Linux v5.16 (2nd wave)

From: Coly Li <hidden>
Date: 2021-10-29 06:09:36

Hi Jens,

This is the second wave of bcache patches for Linux v5.16.

The first patch is suggested by Arnd Bergmann and Christoph
Hellwig that the bcache.h should not belong to include/uapi/
directory, and I compose the change.

The second patch is code cleanup to remove coccicheck warning
which suggests to use scnprintf to replace snprintf(), Qing
Wang posts the change to remove the warning by using sysfs_emit().

Please take them for Linux v5.16 and thanks in advance.

Coly Li 
---

Coly Li (1):
  bcache: move uapi header bcache.h to bcache code directory

Qing Wang (1):
  bcache: replace snprintf in show functions with sysfs_emit

 drivers/md/bcache/bcache.h                     |  2 +-
 .../md/bcache/bcache_ondisk.h                  |  0
 drivers/md/bcache/bset.h                       |  2 +-
 drivers/md/bcache/features.c                   |  2 +-
 drivers/md/bcache/features.h                   |  3 ++-
 drivers/md/bcache/sysfs.h                      | 18 ++++++++++++++++--
 drivers/md/bcache/util.h                       | 17 -----------------
 7 files changed, 21 insertions(+), 23 deletions(-)
 rename include/uapi/linux/bcache.h => drivers/md/bcache/bcache_ondisk.h (100%)

-- 
2.31.1

[PATCH 1/2] bcache: move uapi header bcache.h to bcache code directory

From: Coly Li <hidden>
Date: 2021-10-29 06:09:41

The header file include/uapi/linux/bcache.h is not really a user space
API heaer. This file defines the ondisk format of bcache internal meta
data but no one includes it from user space, bcache-tools has its own
copy of this header with minor modification.

Therefore, this patch moves include/uapi/linux/bcache.h to bcache code
directory as drivers/md/bcache/bcache_ondisk.h.

Suggested-by: Arnd Bergmann <arnd@kernel.org>
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Coly Li <redacted>
---
 drivers/md/bcache/bcache.h                                     | 2 +-
 .../uapi/linux/bcache.h => drivers/md/bcache/bcache_ondisk.h   | 0
 drivers/md/bcache/bset.h                                       | 2 +-
 drivers/md/bcache/features.c                                   | 2 +-
 drivers/md/bcache/features.h                                   | 3 ++-
 5 files changed, 5 insertions(+), 4 deletions(-)
 rename include/uapi/linux/bcache.h => drivers/md/bcache/bcache_ondisk.h (100%)
diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
index 941685409c68..9ed9c955add7 100644
--- a/drivers/md/bcache/bcache.h
+++ b/drivers/md/bcache/bcache.h
@@ -178,7 +178,6 @@
 
 #define pr_fmt(fmt) "bcache: %s() " fmt, __func__
 
-#include <linux/bcache.h>
 #include <linux/bio.h>
 #include <linux/kobject.h>
 #include <linux/list.h>
@@ -190,6 +189,7 @@
 #include <linux/workqueue.h>
 #include <linux/kthread.h>
 
+#include "bcache_ondisk.h"
 #include "bset.h"
 #include "util.h"
 #include "closure.h"
diff --git a/include/uapi/linux/bcache.h b/drivers/md/bcache/bcache_ondisk.h
similarity index 100%
rename from include/uapi/linux/bcache.h
rename to drivers/md/bcache/bcache_ondisk.h
diff --git a/drivers/md/bcache/bset.h b/drivers/md/bcache/bset.h
index a50dcfda656f..d795c84246b0 100644
--- a/drivers/md/bcache/bset.h
+++ b/drivers/md/bcache/bset.h
@@ -2,10 +2,10 @@
 #ifndef _BCACHE_BSET_H
 #define _BCACHE_BSET_H
 
-#include <linux/bcache.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
 
+#include "bcache_ondisk.h"
 #include "util.h" /* for time_stats */
 
 /*
diff --git a/drivers/md/bcache/features.c b/drivers/md/bcache/features.c
index 6d2b7b84a7b7..634922c5601d 100644
--- a/drivers/md/bcache/features.c
+++ b/drivers/md/bcache/features.c
@@ -6,7 +6,7 @@
  * Copyright 2020 Coly Li <colyli@suse.de>
  *
  */
-#include <linux/bcache.h>
+#include "bcache_ondisk.h"
 #include "bcache.h"
 #include "features.h"
 
diff --git a/drivers/md/bcache/features.h b/drivers/md/bcache/features.h
index d1c8fd3977fc..09161b89c63e 100644
--- a/drivers/md/bcache/features.h
+++ b/drivers/md/bcache/features.h
@@ -2,10 +2,11 @@
 #ifndef _BCACHE_FEATURES_H
 #define _BCACHE_FEATURES_H
 
-#include <linux/bcache.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
 
+#include "bcache_ondisk.h"
+
 #define BCH_FEATURE_COMPAT		0
 #define BCH_FEATURE_RO_COMPAT		1
 #define BCH_FEATURE_INCOMPAT		2
-- 
2.31.1

[PATCH 2/2] bcache: replace snprintf in show functions with sysfs_emit

From: Coly Li <hidden>
Date: 2021-10-29 06:09:43

From: Qing Wang <redacted>

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 <redacted>
Signed-off-by: Qing Wang <redacted>
Signed-off-by: Coly Li <redacted>
---
 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 215df32f567b..c1752ba2e05b 100644
--- 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 6274d6a17e5e..cdb165517d0b 100644
--- 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.31.1

Re: [PATCH 0/2] bcache paches for Linux v5.16 (2nd wave)

From: Jens Axboe <axboe@kernel.dk>
Date: 2021-10-29 12:43:42

On Fri, 29 Oct 2021 14:09:28 +0800, Coly Li wrote:
This is the second wave of bcache patches for Linux v5.16.

The first patch is suggested by Arnd Bergmann and Christoph
Hellwig that the bcache.h should not belong to include/uapi/
directory, and I compose the change.

The second patch is code cleanup to remove coccicheck warning
which suggests to use scnprintf to replace snprintf(), Qing
Wang posts the change to remove the warning by using sysfs_emit().

[...]
Applied, thanks!

[1/2] bcache: move uapi header bcache.h to bcache code directory
      commit: cf2197ca4b8c199d188593ca6800ea1827c42171
[2/2] bcache: replace snprintf in show functions with sysfs_emit
      commit: 1b86db5f4e025840e0bf7cef2b10e84531954386

Best regards,
-- 
Jens Axboe

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help