Skip to contentSkip to conversation

bcache: Compiler, sparse and smatch fixes

PATCH In review Bart Van Assche 4 participants 51 messages Mar 15, 2018 – Mar 17, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover bcache: Compiler, sparse and smatch fixes

Hello Michael, Coly and Christoph,

A few weeks ago I analyzed the compiler (W=1), sparse and smatch warnings triggered by the bcache driver. This patch series is what I came up with. Although none of these patches have been tested I think these patches are worth a closer look. Feedback is welcome.

Thanks,

Bart.

Bart Van Assche (16):
bcache: Fix indentation
bcache: Add __printf annotation to __bch_check_keys()
bcache: Annotate switch fall-through
bcache: Fix kernel-doc warnings
bcache: Remove an unused variable
bcache: Suppress more warnings about set-but-not-used variables
bcache: Reduce the number of sparse complaints about lock imbalances
bcache: Fix a compiler warning in bcache_device_init()
bcache: Remove a redundant assignment
bcache: Suppress a compiler warning in bch_##name##_h()
bcache: Check the d->disk pointer before using it
bcache: Make it easier for static analyzers to analyze
bch_allocator_thread()
bcache: Make bch_dump_read() fail if copying to user space fails
bcache: Make csum_set() implementation easier to read
bcache: Fix an endianness bug
bcache: Fix endianness annotations

 drivers/md/bcache/alloc.c     |   7 +--
 drivers/md/bcache/bcache.h    |  22 ++++++--
 drivers/md/bcache/bset.c      |   4 +-
 drivers/md/bcache/bset.h      |   5 +-
 drivers/md/bcache/btree.c     |   4 +-
 drivers/md/bcache/closure.c   |   8 +--
 drivers/md/bcache/debug.c     |   5 +-
 drivers/md/bcache/extents.c   |   2 -
 drivers/md/bcache/journal.c   |   4 +-
 drivers/md/bcache/request.c   |   1 +
 drivers/md/bcache/super.c     |  23 ++++----
 drivers/md/bcache/util.c      |  33 +++++++-----
 drivers/md/bcache/writeback.h |   2 +-
 include/uapi/linux/bcache.h   | 118 ++++++++++++++++++++++--------------------
 14 files changed, 131 insertions(+), 107 deletions(-)
Signature · 1 line
2.16.2
#1 lore raw

PATCH 1/16 bcache: Fix indentation

This patch avoids that smatch complains about inconsistent indentation.

---
 drivers/md/bcache/btree.c     | 2 +-
 drivers/md/bcache/writeback.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/md/bcache/btree.c +1 -1
index fad9fe8817eb..c30609c54c03 100644
@@ -2170,7 +2170,7 @@ int bch_btree_insert_check_key(struct btree *b, struct btree_op *op,
 
 		if (b->key.ptr[0] != btree_ptr ||
                    b->seq != seq + 1) {
-                       op->lock = b->level;
+			op->lock = b->level;
 			goto out;
                }
 	}
drivers/md/bcache/writeback.h +1 -1
index 587b25599856..a102d40a58bc 100644
@@ -39,7 +39,7 @@ static inline uint64_t  bcache_flash_devs_sectors_dirty(struct cache_set *c)
 
 		if (!d || !UUID_FLASH_ONLY(&c->uuids[i]))
 			continue;
-	   ret += bcache_dev_sectors_dirty(d);
+		ret += bcache_dev_sectors_dirty(d);
 	}
 
 	mutex_unlock(&bch_register_lock);
Signature · 1 line
2.16.2
Reviewed-by on v1 1/16
#2 lore raw

Re: [PATCH 01/16] bcache: Fix indentation

Quoted 3 lines · Bart Van Assche

This patch avoids that smatch complains about inconsistent indentation.

Thanks.

Coly Li

Quoted 32 lines
---
 drivers/md/bcache/btree.c     | 2 +-
 drivers/md/bcache/writeback.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/md/bcache/btree.c +1 -1
index fad9fe8817eb..c30609c54c03 100644
@@ -2170,7 +2170,7 @@ int bch_btree_insert_check_key(struct btree *b, struct btree_op *op,
 
 		if (b->key.ptr[0] != btree_ptr ||
                    b->seq != seq + 1) {
-                       op->lock = b->level;
+			op->lock = b->level;
 			goto out;
                }
 	}
drivers/md/bcache/writeback.h +1 -1
index 587b25599856..a102d40a58bc 100644
@@ -39,7 +39,7 @@ static inline uint64_t  bcache_flash_devs_sectors_dirty(struct cache_set *c)
 
 		if (!d || !UUID_FLASH_ONLY(&c->uuids[i]))
 			continue;
-	   ret += bcache_dev_sectors_dirty(d);
+		ret += bcache_dev_sectors_dirty(d);
 	}
 
 	mutex_unlock(&bch_register_lock);
Reviewed-by on v1 1/16
#3 lore raw

Re: [PATCH 01/16] bcache: Fix indentation

In reply to Bart Van Assche
Quoted 3 lines · Bart Van Assche

This patch avoids that smatch complains about inconsistent indentation.

Thanks.

Coly Li

Quoted 32 lines
---
 drivers/md/bcache/btree.c     | 2 +-
 drivers/md/bcache/writeback.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/md/bcache/btree.c +1 -1
index fad9fe8817eb..c30609c54c03 100644
@@ -2170,7 +2170,7 @@ int bch_btree_insert_check_key(struct btree *b, struct btree_op *op,
 
 		if (b->key.ptr[0] != btree_ptr ||
                    b->seq != seq + 1) {
-                       op->lock = b->level;
+			op->lock = b->level;
 			goto out;
                }
 	}
drivers/md/bcache/writeback.h +1 -1
index 587b25599856..a102d40a58bc 100644
@@ -39,7 +39,7 @@ static inline uint64_t  bcache_flash_devs_sectors_dirty(struct cache_set *c)
 
 		if (!d || !UUID_FLASH_ONLY(&c->uuids[i]))
 			continue;
-	   ret += bcache_dev_sectors_dirty(d);
+		ret += bcache_dev_sectors_dirty(d);
 	}
 
 	mutex_unlock(&bch_register_lock);
#5 lore raw

PATCH 2/16 bcache: Add __printf annotation to __bch_check_keys()

In reply to Bart Van Assche

Make it possible for the compiler to verify the consistency of the format string passed to __bch_check_keys() and the arguments that should be formatted according to that format string.

---
 drivers/md/bcache/bset.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/md/bcache/bset.h +3 -2
index fa506c1aa524..0c24280f3b98 100644
@@ -531,14 +531,15 @@ int __bch_keylist_realloc(struct keylist *, unsigned);
 #ifdef CONFIG_BCACHE_DEBUG
 
 int __bch_count_data(struct btree_keys *);
-void __bch_check_keys(struct btree_keys *, const char *, ...);
+void __printf(2, 3) __bch_check_keys(struct btree_keys *, const char *, ...);
 void bch_dump_bset(struct btree_keys *, struct bset *, unsigned);
 void bch_dump_bucket(struct btree_keys *);
 
 #else
 
 static inline int __bch_count_data(struct btree_keys *b) { return -1; }
-static inline void __bch_check_keys(struct btree_keys *b, const char *fmt, ...) {}
+static inline void __printf(2, 3)
+	__bch_check_keys(struct btree_keys *b, const char *fmt, ...) {}
 static inline void bch_dump_bucket(struct btree_keys *b) {}
 void bch_dump_bset(struct btree_keys *, struct bset *, unsigned);
 
Signature · 1 line
2.16.2
#6 lore raw

Re: [PATCH 02/16] bcache: Add __printf annotation to __bch_check_keys()

Quoted 5 lines · Bart Van Assche

Make it possible for the compiler to verify the consistency of the format string passed to __bch_check_keys() and the arguments that should be formatted according to that format string.

LGTM, applying.

#7 lore raw

PATCH 3/16 bcache: Annotate switch fall-through

In reply to Bart Van Assche

This patch avoids that building with W=1 triggers complaints about switch fall-throughs.

---
 drivers/md/bcache/util.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/md/bcache/util.c +7 -0
index a23cd6a14b74..6198041f0ee2 100644
@@ -32,20 +32,27 @@ int bch_ ## name ## _h(const char *cp, type *res)		\
 	case 'y':						\
 	case 'z':						\
 		u++;						\
+		/* fall through */				\
 	case 'e':						\
 		u++;						\
+		/* fall through */				\
 	case 'p':						\
 		u++;						\
+		/* fall through */				\
 	case 't':						\
 		u++;						\
+		/* fall through */				\
 	case 'g':						\
 		u++;						\
+		/* fall through */				\
 	case 'm':						\
 		u++;						\
+		/* fall through */				\
 	case 'k':						\
 		u++;						\
 		if (e++ == cp)					\
 			return -EINVAL;				\
+		/* fall through */				\
 	case '\n':						\
 	case '\0':						\
 		if (*e == '\n')					\
Signature · 1 line
2.16.2
Reviewed-by on v1 3/16
#8 lore raw

Re: [PATCH 03/16] bcache: Annotate switch fall-through

Quoted 4 lines · Bart Van Assche

This patch avoids that building with W=1 triggers complaints about switch fall-throughs.

Thanks.

Coly Li

Quoted 37 lines
---
 drivers/md/bcache/util.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/md/bcache/util.c +7 -0
index a23cd6a14b74..6198041f0ee2 100644
@@ -32,20 +32,27 @@ int bch_ ## name ## _h(const char *cp, type *res)		\
 	case 'y':						\
 	case 'z':						\
 		u++;						\
+		/* fall through */				\
 	case 'e':						\
 		u++;						\
+		/* fall through */				\
 	case 'p':						\
 		u++;						\
+		/* fall through */				\
 	case 't':						\
 		u++;						\
+		/* fall through */				\
 	case 'g':						\
 		u++;						\
+		/* fall through */				\
 	case 'm':						\
 		u++;						\
+		/* fall through */				\
 	case 'k':						\
 		u++;						\
 		if (e++ == cp)					\
 			return -EINVAL;				\
+		/* fall through */				\
 	case '\n':						\
 	case '\0':						\
 		if (*e == '\n')					\
#10 lore raw

PATCH 4/16 bcache: Fix kernel-doc warnings

In reply to Bart Van Assche

Avoid that building with W=1 triggers warnings about the kernel-doc headers.

---
 drivers/md/bcache/btree.c   |  2 +-
 drivers/md/bcache/closure.c |  8 ++++----
 drivers/md/bcache/request.c |  1 +
 drivers/md/bcache/util.c    | 18 ++++++++----------
 4 files changed, 14 insertions(+), 15 deletions(-)
drivers/md/bcache/btree.c +1 -1
index c30609c54c03..d20f963799b6 100644
@@ -959,7 +959,7 @@ static struct btree *mca_alloc(struct cache_set *c, struct btree_op *op,
 	return b;
 }
 
-/**
+/*
  * bch_btree_node_get - find a btree node in the cache and lock it, reading it
  * in from disk if necessary.
  *
drivers/md/bcache/closure.c +4 -4
index 7f12920c14f7..87c45dfa7c38 100644
@@ -46,7 +46,7 @@ void closure_sub(struct closure *cl, int v)
 }
 EXPORT_SYMBOL(closure_sub);
 
-/**
+/*
  * closure_put - decrement a closure's refcount
  */
 void closure_put(struct closure *cl)
@@ -55,7 +55,7 @@ void closure_put(struct closure *cl)
 }
 EXPORT_SYMBOL(closure_put);
 
-/**
+/*
  * closure_wake_up - wake up all closures on a wait list, without memory barrier
  */
 void __closure_wake_up(struct closure_waitlist *wait_list)
@@ -79,9 +79,9 @@ EXPORT_SYMBOL(__closure_wake_up);
 
 /**
  * closure_wait - add a closure to a waitlist
- *
- * @waitlist will own a ref on @cl, which will be released when
+ * @waitlist: will own a ref on @cl, which will be released when
  * closure_wake_up() is called on @waitlist.
+ * @cl: closure pointer.
  *
  */
 bool closure_wait(struct closure_waitlist *waitlist, struct closure *cl)
drivers/md/bcache/request.c +1 -0
index 6422846b546e..ed129ba557a8 100644
@@ -295,6 +295,7 @@ static void bch_data_insert_start(struct closure *cl)
 
 /**
  * bch_data_insert - stick some data in the cache
+ * @cl: closure pointer.
  *
  * This is the starting point for any data to end up in a cache device; it could
  * be from a normal write, or a writeback write, or a write to a flash only
drivers/md/bcache/util.c +8 -10
index 6198041f0ee2..74febd5230df 100644
@@ -82,10 +82,9 @@ STRTO_H(strtoll, long long)
 STRTO_H(strtoull, unsigned long long)
 
 /**
- * bch_hprint() - formats @v to human readable string for sysfs.
- *
- * @v - signed 64 bit integer
- * @buf - the (at least 8 byte) buffer to format the result into.
+ * bch_hprint - formats @v to human readable string for sysfs.
+ * @buf: the (at least 8 byte) buffer to format the result into.
+ * @v: signed 64 bit integer
  *
  * Returns the number of bytes used by format.
  */
@@ -225,13 +224,12 @@ void bch_time_stats_update(struct time_stats *stats, uint64_t start_time)
 }
 
 /**
- * bch_next_delay() - increment @d by the amount of work done, and return how
- * long to delay until the next time to do some work.
- *
- * @d - the struct bch_ratelimit to update
- * @done - the amount of work done, in arbitrary units
+ * bch_next_delay() - update ratelimiting statistics and calculate next delay
+ * @d: the struct bch_ratelimit to update
+ * @done: the amount of work done, in arbitrary units
  *
- * Returns the amount of time to delay by, in jiffies
+ * Increment @d by the amount of work done, and return how long to delay in
+ * jiffies until the next time to do some work.
  */
 uint64_t bch_next_delay(struct bch_ratelimit *d, uint64_t done)
 {
Signature · 1 line
2.16.2
#12 lore raw

PATCH 5/16 bcache: Remove an unused variable

In reply to Bart Van Assche
---
 drivers/md/bcache/extents.c | 2 --
 1 file changed, 2 deletions(-)
drivers/md/bcache/extents.c +0 -2
index f9d391711595..c334e6666461 100644
@@ -534,7 +534,6 @@ static bool bch_extent_bad_expensive(struct btree *b, const struct bkey *k,
 static bool bch_extent_bad(struct btree_keys *bk, const struct bkey *k)
 {
 	struct btree *b = container_of(bk, struct btree, keys);
-	struct bucket *g;
 	unsigned i, stale;
 
 	if (!KEY_PTRS(k) ||
@@ -549,7 +548,6 @@ static bool bch_extent_bad(struct btree_keys *bk, const struct bkey *k)
 		return false;
 
 	for (i = 0; i < KEY_PTRS(k); i++) {
-		g = PTR_BUCKET(b->c, k, i);
 		stale = ptr_stale(b->c, k, i);
 
 		btree_bug_on(stale > 96, b,
Signature · 1 line
2.16.2
#13 lore raw

Re: [PATCH 05/16] bcache: Remove an unused variable

Quoted 1 line · Bart Van Assche

Hi Bart,

I suggest to add at least one line commit log, thanks in advance for it :-)

Coly Li

Quoted 25 lines
---
 drivers/md/bcache/extents.c | 2 --
 1 file changed, 2 deletions(-)
drivers/md/bcache/extents.c +0 -2
index f9d391711595..c334e6666461 100644
@@ -534,7 +534,6 @@ static bool bch_extent_bad_expensive(struct btree *b, const struct bkey *k,
 static bool bch_extent_bad(struct btree_keys *bk, const struct bkey *k)
 {
 	struct btree *b = container_of(bk, struct btree, keys);
-	struct bucket *g;
 	unsigned i, stale;
 
 	if (!KEY_PTRS(k) ||
@@ -549,7 +548,6 @@ static bool bch_extent_bad(struct btree_keys *bk, const struct bkey *k)
 		return false;
 
 	for (i = 0; i < KEY_PTRS(k); i++) {
-		g = PTR_BUCKET(b->c, k, i);
 		stale = ptr_stale(b->c, k, i);
 
 		btree_bug_on(stale > 96, b,
#14 lore raw

Re: [PATCH 05/16] bcache: Remove an unused variable

In reply to Bart Van Assche
Quoted 1 line · Bart Van Assche

Hi Bart,

Could you please to add at least one line commit log ? Thanks in advance for this :-)

Coly Li

Quoted 25 lines
---
 drivers/md/bcache/extents.c | 2 --
 1 file changed, 2 deletions(-)
drivers/md/bcache/extents.c +0 -2
index f9d391711595..c334e6666461 100644
@@ -534,7 +534,6 @@ static bool bch_extent_bad_expensive(struct btree *b, const struct bkey *k,
 static bool bch_extent_bad(struct btree_keys *bk, const struct bkey *k)
 {
 	struct btree *b = container_of(bk, struct btree, keys);
-	struct bucket *g;
 	unsigned i, stale;
 
 	if (!KEY_PTRS(k) ||
@@ -549,7 +548,6 @@ static bool bch_extent_bad(struct btree_keys *bk, const struct bkey *k)
 		return false;
 
 	for (i = 0; i < KEY_PTRS(k); i++) {
-		g = PTR_BUCKET(b->c, k, i);
 		stale = ptr_stale(b->c, k, i);
 
 		btree_bug_on(stale > 96, b,
#15 lore raw

Re: [PATCH 05/16] bcache: Remove an unused variable

Quoted 7 lines · Coly Li
Quoted 1 line · Bart Van Assche

Hi Bart,

Could you please to add at least one line commit log ? Thanks in advance for this :-)

Hi subject line perfectly describes the patch, so why?

#16 lore raw

Re: [PATCH 05/16] bcache: Remove an unused variable

Quoted 11 lines · Christoph Hellwig
Quoted 7 lines · Coly Li
Quoted 1 line · Bart Van Assche

Hi Bart,

Could you please to add at least one line commit log ? Thanks in advance for this :-)

Hi subject line perfectly describes the patch, so why?

Hi Christoph,

We are trying to avoid patches with empty commit log for bcache patches. A patch without commit log works, but just like the fixes to remove smatch/sparse warning, adding commit log is preferred.

Thanks.

Coly Li

#18 lore raw

PATCH 6/16 bcache: Suppress more warnings about set-but-not-used variables

In reply to Bart Van Assche

This patch does not change any functionality.

---
 drivers/md/bcache/bset.c    | 4 ++--
 drivers/md/bcache/journal.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/md/bcache/bset.c +2 -2
index e56d3ecdbfcb..579c696a5fe0 100644
@@ -1072,7 +1072,7 @@ EXPORT_SYMBOL(bch_btree_iter_init);
 static inline struct bkey *__bch_btree_iter_next(struct btree_iter *iter,
 						 btree_iter_cmp_fn *cmp)
 {
-	struct btree_iter_set unused;
+	struct btree_iter_set b __maybe_unused;
 	struct bkey *ret = NULL;
 
 	if (!btree_iter_end(iter)) {
@@ -1087,7 +1087,7 @@ static inline struct bkey *__bch_btree_iter_next(struct btree_iter *iter,
 		}
 
 		if (iter->data->k == iter->data->end)
-			heap_pop(iter, unused, cmp);
+			heap_pop(iter, b, cmp);
 		else
 			heap_sift(iter, 0, cmp);
 	}
drivers/md/bcache/journal.c +1 -1
index 1b736b860739..605368ff13c9 100644
@@ -493,7 +493,7 @@ static void journal_reclaim(struct cache_set *c)
 	struct cache *ca;
 	uint64_t last_seq;
 	unsigned iter, n = 0;
-	atomic_t p;
+	atomic_t p __maybe_unused;
 
 	atomic_long_inc(&c->reclaim);
 
Signature · 1 line
2.16.2
#19 lore raw

Re: [PATCH 06/16] bcache: Suppress more warnings about set-but-not-used variables

Quoted 3 lines · Bart Van Assche

This patch does not change any functionality.

Hi Bart,

This patch looks good to me. A question is, does GCC later than 4.3 supports such annotation like '__maybe_unused' ?

Thanks.

Coly Li

Quoted 41 lines
---
 drivers/md/bcache/bset.c    | 4 ++--
 drivers/md/bcache/journal.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/md/bcache/bset.c +2 -2
index e56d3ecdbfcb..579c696a5fe0 100644
@@ -1072,7 +1072,7 @@ EXPORT_SYMBOL(bch_btree_iter_init);
 static inline struct bkey *__bch_btree_iter_next(struct btree_iter *iter,
 						 btree_iter_cmp_fn *cmp)
 {
-	struct btree_iter_set unused;
+	struct btree_iter_set b __maybe_unused;
 	struct bkey *ret = NULL;
 
 	if (!btree_iter_end(iter)) {
@@ -1087,7 +1087,7 @@ static inline struct bkey *__bch_btree_iter_next(struct btree_iter *iter,
 		}
 
 		if (iter->data->k == iter->data->end)
-			heap_pop(iter, unused, cmp);
+			heap_pop(iter, b, cmp);
 		else
 			heap_sift(iter, 0, cmp);
 	}
drivers/md/bcache/journal.c +1 -1
index 1b736b860739..605368ff13c9 100644
@@ -493,7 +493,7 @@ static void journal_reclaim(struct cache_set *c)
 	struct cache *ca;
 	uint64_t last_seq;
 	unsigned iter, n = 0;
-	atomic_t p;
+	atomic_t p __maybe_unused;
 
 	atomic_long_inc(&c->reclaim);
 
#20 lore raw

Re: [PATCH 06/16] bcache: Suppress more warnings about set-but-not-used variables

T24gRnJpLCAyMDE4LTAzLTE2IGF0IDAwOjIwICswODAwLCBDb2x5IExpIHdyb3RlOg0KPiBPbiAx NS8wMy8yMDE4IDExOjA4IFBNLCBCYXJ0IFZhbiBBc3NjaGUgd3JvdGU6DQo+ID4gVGhpcyBwYXRj aCBkb2VzIG5vdCBjaGFuZ2UgYW55IGZ1bmN0aW9uYWxpdHkuDQo+ID4gDQo+ID4gU2lnbmVkLW9m Zi1ieTogQmFydCBWYW4gQXNzY2hlIDxiYXJ0LnZhbmFzc2NoZUB3ZGMuY29tPg0KPiANCj4gSGkg QmFydCwNCj4gDQo+IFRoaXMgcGF0Y2ggbG9va3MgZ29vZCB0byBtZS4gQSBxdWVzdGlvbiBpcywg ZG9lcyBHQ0MgbGF0ZXIgdGhhbiA0LjMNCj4gc3VwcG9ydHMgc3VjaCBhbm5vdGF0aW9uIGxpa2Ug J19fbWF5YmVfdW51c2VkJyA/DQoNCkhlbGxvIENvbHksDQoNCllvdSBtYXkgd2FudCB0byBoYXZl IGEgbG9vayBhdCB0aGUgZm9sbG93aW5nIGNvbW1pdDoNCg0KY29tbWl0IDBkN2ViYmJjNmVhYTU1 MzlmNzhhYjIwZWQ2ZmYxNzI1YTRlMzMyZWYNCkF1dGhvcjogRGF2aWQgUmllbnRqZXMgPHJpZW50 amVzQGdvb2dsZS5jb20+DQpEYXRlOiAgIFdlZCBNYXkgOSAwMjozNToyNyAyMDA3IC0wNzAwDQoN CiAgICBjb21waWxlcjogaW50cm9kdWNlIF9fdXNlZCBhbmQgX19tYXliZV91bnVzZWQNCg0KICAg IF9fdXNlZCBpcyBkZWZpbmVkIHRvIGJlIF9fYXR0cmlidXRlX18oKHVudXNlZCkpIGZvciBhbGwg cHJlLTMuMyBnY2MNCiAgICBjb21waWxlcnMgdG8gc3VwcHJlc3Mgd2FybmluZ3MgZm9yIHVudXNl ZCBmdW5jdGlvbnMgYmVjYXVzZSBwZXJoYXBzIHRoZXkNCiAgICBhcmUgcmVmZXJlbmNlZCBvbmx5 IGluIGlubGluZSBhc3NlbWJseS4gIEl0IGlzIGRlZmluZWQgdG8gYmUNCiAgICBfX2F0dHJpYnV0 ZV9fKCh1c2VkKSkgZm9yIGdjYyAzLjMgYW5kIGxhdGVyIHNvIHRoYXQgdGhlIGNvZGUgaXMgc3Rp bGwNCiAgICBlbWl0dGVkIGZvciBzdWNoIGZ1bmN0aW9ucy4NCg0KDQoNClRoYW5rcywNCg0KQmFy dC4NCg0KDQo=

Reviewed-by
#21 lore raw

Re: [PATCH 06/16] bcache: Suppress more warnings about set-but-not-used variables

Quoted 19 lines · Bart Van Assche
Quoted 9 lines · Coly Li
Quoted 3 lines · Bart Van Assche

This patch does not change any functionality.

Hi Bart,

This patch looks good to me. A question is, does GCC later than 4.3 supports such annotation like '__maybe_unused' ?

Hello Coly,

You may want to have a look at the following commit:

commit 0d7ebbbc6eaa5539f78ab20ed6ff1725a4e332ef

Author: David Rientjes <[email protected]>
Date:   Wed May 9 02:35:27 2007 -0700
Quoted 8 lines

compiler: introduce __used and __maybe_unused

__used is defined to be __attribute__((unused)) for all pre-3.3 gcc compilers to suppress warnings for unused functions because perhaps they are referenced only in inline assembly. It is defined to be __attribute__((used)) for gcc 3.3 and later so that the code is still emitted for such functions.

Hi Bart,

Thanks for the hint, I don't need to worry about it.

Coly Li

#22 lore raw

PATCH 7/16 bcache: Reduce the number of sparse complaints about lock imbalances

In reply to Bart Van Assche

Add more annotations for sparse to inform it about which functions do not have the same number of spin_lock() and spin_unlock() calls.

---
 drivers/md/bcache/journal.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/md/bcache/journal.c +2 -0
index 605368ff13c9..a191fd04212f 100644
@@ -594,6 +594,7 @@ static void journal_write_done(struct closure *cl)
 }
 
 static void journal_write_unlock(struct closure *cl)
+	__releases(&c->journal.lock)
 {
 	struct cache_set *c = container_of(cl, struct cache_set, journal.io);
 
@@ -705,6 +706,7 @@ static void journal_try_write(struct cache_set *c)
 
 static struct journal_write *journal_wait_for_write(struct cache_set *c,
 						    unsigned nkeys)
+	__acquires(&c->journal.lock)
 {
 	size_t sectors;
 	struct closure cl;
Signature · 1 line
2.16.2
#23 lore raw

Re: [PATCH 07/16] bcache: Reduce the number of sparse complaints about lock imbalances

Quoted 4 lines · Bart Van Assche

Add more annotations for sparse to inform it about which functions do not have the same number of spin_lock() and spin_unlock() calls.

LGTM, applying. -mpl

#24 lore raw

PATCH 8/16 bcache: Fix a compiler warning in bcache_device_init()

In reply to Bart Van Assche

Avoid that building with W=1 triggers the following compiler warning:

drivers/md/bcache/super.c:776:20: warning: comparison is always false due to limited range of data type [-Wtype-limits]

      d->nr_stripes > SIZE_MAX / sizeof(atomic_t)) {
                    ^
---
 drivers/md/bcache/super.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/bcache/super.c +3 -3
index e8dfa804bd98..87c1f853bbb3 100644
@@ -769,6 +769,8 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size,
 			      sector_t sectors)
 {
 	struct request_queue *q;
+	const size_t max_stripes = min_t(size_t, INT_MAX,
+					 SIZE_MAX / sizeof(atomic_t));
 	size_t n;
 	int idx;
 
@@ -777,9 +779,7 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size,
 
 	d->nr_stripes = DIV_ROUND_UP_ULL(sectors, d->stripe_size);
 
-	if (!d->nr_stripes ||
-	    d->nr_stripes > INT_MAX ||
-	    d->nr_stripes > SIZE_MAX / sizeof(atomic_t)) {
+	if (!d->nr_stripes || d->nr_stripes > max_stripes) {
 		pr_err("nr_stripes too large or invalid: %u (start sector beyond end of disk?)",
 			(unsigned)d->nr_stripes);
 		return -ENOMEM;
Signature · 1 line
2.16.2
Reviewed-by on v1 8/16
#25 lore raw

Re: [PATCH 08/16] bcache: Fix a compiler warning in bcache_device_init()

Quoted 7 lines · Bart Van Assche

Avoid that building with W=1 triggers the following compiler warning:

drivers/md/bcache/super.c:776:20: warning: comparison is always false due to limited range of data type [-Wtype-limits]

      d->nr_stripes > SIZE_MAX / sizeof(atomic_t)) {
                    ^

Thanks.

Coly Li

Quoted 29 lines
---
 drivers/md/bcache/super.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/bcache/super.c +3 -3
index e8dfa804bd98..87c1f853bbb3 100644
@@ -769,6 +769,8 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size,
 			      sector_t sectors)
 {
 	struct request_queue *q;
+	const size_t max_stripes = min_t(size_t, INT_MAX,
+					 SIZE_MAX / sizeof(atomic_t));
 	size_t n;
 	int idx;
 
@@ -777,9 +779,7 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size,
 
 	d->nr_stripes = DIV_ROUND_UP_ULL(sectors, d->stripe_size);
 
-	if (!d->nr_stripes ||
-	    d->nr_stripes > INT_MAX ||
-	    d->nr_stripes > SIZE_MAX / sizeof(atomic_t)) {
+	if (!d->nr_stripes || d->nr_stripes > max_stripes) {
 		pr_err("nr_stripes too large or invalid: %u (start sector beyond end of disk?)",
 			(unsigned)d->nr_stripes);
 		return -ENOMEM;
#26 lore raw

Re: [PATCH 08/16] bcache: Fix a compiler warning in bcache_device_init()

In reply to Bart Van Assche
Quoted 7 lines · Bart Van Assche

Avoid that building with W=1 triggers the following compiler warning:

drivers/md/bcache/super.c:776:20: warning: comparison is always false due to limited range of data type [-Wtype-limits]

      d->nr_stripes > SIZE_MAX / sizeof(atomic_t)) {
                    ^

LGTM, applying.

#27 lore raw

PATCH 9/16 bcache: Remove a redundant assignment

In reply to Bart Van Assche

A bio_set_op_attrs() call a little further down overwrites bio->bi_opf. That means that the bio->bi_opf assignment is redundant. Hence remove it. See also commit ad0d9e76a412 ("bcache: use bio op accessors").

Cc Mike Christie <[email protected]>
Cc Hannes Reinecke <[email protected]>
---
 drivers/md/bcache/super.c | 1 -
 1 file changed, 1 deletion(-)
drivers/md/bcache/super.c +0 -1
index 87c1f853bbb3..d19a44cd1fd7 100644
@@ -353,7 +353,6 @@ static void uuid_io(struct cache_set *c, int op, unsigned long op_flags,
 	for (i = 0; i < KEY_PTRS(k); i++) {
 		struct bio *bio = bch_bbio_alloc(c);
 
-		bio->bi_opf = REQ_SYNC | REQ_META | op_flags;
 		bio->bi_iter.bi_size = KEY_SIZE(k) << 9;
 
 		bio->bi_end_io	= uuid_endio;
Signature · 1 line
2.16.2
Reviewed-by on v1 9/16
#28 lore raw

Re: [PATCH 09/16] bcache: Remove a redundant assignment

Quoted 7 lines · Bart Van Assche

A bio_set_op_attrs() call a little further down overwrites bio->bi_opf. That means that the bio->bi_opf assignment is redundant. Hence remove it. See also commit ad0d9e76a412 ("bcache: use bio op accessors").

Cc Mike Christie <[email protected]>
Cc Hannes Reinecke <[email protected]>

Thanks.

Coly Li

Quoted 17 lines
---
 drivers/md/bcache/super.c | 1 -
 1 file changed, 1 deletion(-)
drivers/md/bcache/super.c +0 -1
index 87c1f853bbb3..d19a44cd1fd7 100644
@@ -353,7 +353,6 @@ static void uuid_io(struct cache_set *c, int op, unsigned long op_flags,
 	for (i = 0; i < KEY_PTRS(k); i++) {
 		struct bio *bio = bch_bbio_alloc(c);
 
-		bio->bi_opf = REQ_SYNC | REQ_META | op_flags;
 		bio->bi_iter.bi_size = KEY_SIZE(k) << 9;
 
 		bio->bi_end_io	= uuid_endio;
#29 lore raw

PATCH 10/16 bcache: Suppress a compiler warning in bch_##name##_h()

In reply to Bart Van Assche

Avoid that building with W=1 triggers the following compiler warning:

drivers/md/bcache/util.c: In function 'bch_strtoull_h':
drivers/md/bcache/util.c:70:10: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]

       (i < 0 && -ANYSINT_MAX(type) / 1024 > i)) \
          ^

The only functional change in this patch is that (type) ~0 is changed into ~(type)0. That makes a difference for unsigned types for which sizeof(type) > sizeof(int). I think this change is a bug fix.

---
 drivers/md/bcache/util.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/md/bcache/util.c +4 -4
index 74febd5230df..755523474649 100644
@@ -25,6 +25,7 @@ int bch_ ## name ## _h(const char *cp, type *res)		\
 	int u = 0;						\
 	char *e;						\
 	type i = simple_ ## name(cp, &e, 10);			\
+	const type zero = 0;					\
 								\
 	switch (tolower(*e)) {					\
 	default:						\
@@ -63,11 +64,10 @@ int bch_ ## name ## _h(const char *cp, type *res)		\
 		return -EINVAL;					\
 								\
 	while (u--) {						\
-		if ((type) ~0 > 0 &&				\
-		    (type) ~0 / 1024 <= i)			\
+		if (~zero > 0 && ~zero / 1024 <= i)		\
 			return -EINVAL;				\
-		if ((i > 0 && ANYSINT_MAX(type) / 1024 < i) ||	\
-		    (i < 0 && -ANYSINT_MAX(type) / 1024 > i))	\
+		if ((i > zero && ANYSINT_MAX(type) / 1024 < i) ||\
+		    (i < zero && -ANYSINT_MAX(type) / 1024 > i))\
 			return -EINVAL;				\
 		i *= 1024;					\
 	}							\
Signature · 1 line
2.16.2
#30 lore raw

PATCH 11/16 bcache: Check the d->disk pointer before using it

In reply to Bart Van Assche

Since bcache_device_free() checks the d->disk pointer I think that means that that pointer can be NULL. Hence test that pointer before using it. This was detected by smatch.

---
 drivers/md/bcache/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/super.c +1 -1
index d19a44cd1fd7..39bec137f636 100644
@@ -742,7 +742,7 @@ static void bcache_device_free(struct bcache_device *d)
 {
 	lockdep_assert_held(&bch_register_lock);
 
-	pr_info("%s stopped", d->disk->disk_name);
+	pr_info("%s stopped", d->disk ? d->disk->disk_name : "(?)");
 
 	if (d->c)
 		bcache_device_detach(d);
Signature · 1 line
2.16.2
Reviewed-by on v1 11/16
#31 lore raw

Re: [PATCH 11/16] bcache: Check the d->disk pointer before using it

Quoted 5 lines · Bart Van Assche

Since bcache_device_free() checks the d->disk pointer I think that means that that pointer can be NULL. Hence test that pointer before using it. This was detected by smatch.

Thanks.

Coly Li

Quoted 18 lines
---
 drivers/md/bcache/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/super.c +1 -1
index d19a44cd1fd7..39bec137f636 100644
@@ -742,7 +742,7 @@ static void bcache_device_free(struct bcache_device *d)
 {
 	lockdep_assert_held(&bch_register_lock);
 
-	pr_info("%s stopped", d->disk->disk_name);
+	pr_info("%s stopped", d->disk ? d->disk->disk_name : "(?)");
 
 	if (d->c)
 		bcache_device_detach(d);
#32 lore raw

PATCH 12/16 bcache: Make it easier for static analyzers to analyze bch_allocator_thread()

In reply to Bart Van Assche

This patch does not change any functionality but avoids that smatch reports the following:

drivers/md/bcache/alloc.c:334: bch_allocator_thread() error: uninitialized symbol 'bucket'.

---
 drivers/md/bcache/alloc.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/md/bcache/alloc.c +2 -5
index 458e1d38577d..6a98d48c5f5f 100644
@@ -316,6 +316,7 @@ static int bch_allocator_push(struct cache *ca, long bucket)
 static int bch_allocator_thread(void *arg)
 {
 	struct cache *ca = arg;
+	long bucket;
 
 	mutex_lock(&ca->set->bucket_lock);
 
@@ -325,11 +326,7 @@ static int bch_allocator_thread(void *arg)
 		 * possibly issue discards to them, then we add the bucket to
 		 * the free list:
 		 */
-		while (!fifo_empty(&ca->free_inc)) {
-			long bucket;
-
-			fifo_pop(&ca->free_inc, bucket);
-
+		while (fifo_pop(&ca->free_inc, bucket)) {
 			if (ca->discard) {
 				mutex_unlock(&ca->set->bucket_lock);
 				blkdev_issue_discard(ca->bdev,
Signature · 1 line
2.16.2
#33 lore raw

Re: [PATCH 12/16] bcache: Make it easier for static analyzers to analyze bch_allocator_thread()

Quoted 6 lines · Bart Van Assche

This patch does not change any functionality but avoids that smatch reports the following:

drivers/md/bcache/alloc.c:334: bch_allocator_thread() error: uninitialized symbol 'bucket'.

Hi Bart,

Your change is OK to me, but the original code seems OK too. Can I say this is a bug should be fixed from smatch ?

Thanks.

Coly Li

Quoted 30 lines
---
 drivers/md/bcache/alloc.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/md/bcache/alloc.c +2 -5
index 458e1d38577d..6a98d48c5f5f 100644
@@ -316,6 +316,7 @@ static int bch_allocator_push(struct cache *ca, long bucket)
 static int bch_allocator_thread(void *arg)
 {
 	struct cache *ca = arg;
+	long bucket;
 
 	mutex_lock(&ca->set->bucket_lock);
 
@@ -325,11 +326,7 @@ static int bch_allocator_thread(void *arg)
 		 * possibly issue discards to them, then we add the bucket to
 		 * the free list:
 		 */
-		while (!fifo_empty(&ca->free_inc)) {
-			long bucket;
-
-			fifo_pop(&ca->free_inc, bucket);
-
+		while (fifo_pop(&ca->free_inc, bucket)) {
 			if (ca->discard) {
 				mutex_unlock(&ca->set->bucket_lock);
 				blkdev_issue_discard(ca->bdev,
#34 lore raw

Re: [PATCH 12/16] bcache: Make it easier for static analyzers to analyze bch_allocator_thread()

T24gRnJpLCAyMDE4LTAzLTE2IGF0IDAwOjI5ICswODAwLCBDb2x5IExpIHdyb3RlOg0KPiBPbiAx NS8wMy8yMDE4IDExOjA4IFBNLCBCYXJ0IFZhbiBBc3NjaGUgd3JvdGU6DQo+ID4gVGhpcyBwYXRj aCBkb2VzIG5vdCBjaGFuZ2UgYW55IGZ1bmN0aW9uYWxpdHkgYnV0IGF2b2lkcyB0aGF0IHNtYXRj aA0KPiA+IHJlcG9ydHMgdGhlIGZvbGxvd2luZzoNCj4gPiANCj4gPiBkcml2ZXJzL21kL2JjYWNo ZS9hbGxvYy5jOjMzNDogYmNoX2FsbG9jYXRvcl90aHJlYWQoKSBlcnJvcjogdW5pbml0aWFsaXpl ZCBzeW1ib2wgJ2J1Y2tldCcuDQo+ID4gDQo+ID4gU2lnbmVkLW9mZi1ieTogQmFydCBWYW4gQXNz Y2hlIDxiYXJ0LnZhbmFzc2NoZUB3ZGMuY29tPg0KPiANCj4gSGkgQmFydCwNCj4gDQo+IFlvdXIg Y2hhbmdlIGlzIE9LIHRvIG1lLCBidXQgdGhlIG9yaWdpbmFsIGNvZGUgc2VlbXMgT0sgdG9vLiBD YW4gSSBzYXkNCj4gdGhpcyBpcyBhIGJ1ZyBzaG91bGQgYmUgZml4ZWQgZnJvbSBzbWF0Y2ggPw0K DQpIZWxsbyBDb2x5LA0KDQpJdCB3b3VsZCBiZSBncmVhdCBpZiBzbWF0Y2ggd291bGQgYmUgbW9k aWZpZWQgc3VjaCB0aGF0IGl0IGRvZXMgbm90IGNvbXBsYWluDQphYm91dCB0aGlzIGNvZGUuIEJ1 dCBJIHRoaW5rIHRoYXQgdGhpcyBwYXRjaCBkb2VzIG5vdCBvbmx5IG1ha2UgdGhlIGNvZGUNCmVh c2llciB0byBhbmFseXplIGZvciBzdGF0aWMgYW5hbHl6ZXJzIGJ1dCBhbHNvIGZvciBodW1hbnMu IFNvIHBsZWFzZSBldmFsdWF0ZQ0KdGhpcyBwYXRjaCBmcm9tIHRoYXQgcGVyc3BlY3RpdmUuDQoN ClRoYW5rcywNCg0KQmFydC4NCg0KDQo=

Reviewed-by
#35 lore raw

Re: [PATCH 12/16] bcache: Make it easier for static analyzers to analyze bch_allocator_thread()

Quoted 14 lines · Bart Van Assche
Quoted 4 lines · Coly Li
Quoted 3 lines · Bart Van Assche

This patch does not change any functionality but avoids that smatch reports the following:

Quoted 8 lines
Quoted 3 lines

drivers/md/bcache/alloc.c:334: bch_allocator_thread() error: uninitialized symbol 'bucket'.

Hi Bart,

Your change is OK to me, but the original code seems OK too. Can I say this is a bug should be fixed from smatch ?

Quoted 6 lines

Hello Coly,

It would be great if smatch would be modified such that it does not complain about this code. But I think that this patch does not only make the code easier to analyze for static analyzers but also for humans. So please evaluate this patch from that perspective.

Hi Bart,

It's fair enough, I am convinced. Thanks.

Coly Li

#36 lore raw

PATCH 13/16 bcache: Make bch_dump_read() fail if copying to user space fails

In reply to Bart Van Assche

copy_to_user() returns the number of remaining bytes. Avoid that a larger value is returned than the number of bytes that have been copied by returning -EFAULT if not all bytes have been copied.

---
 drivers/md/bcache/debug.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/md/bcache/debug.c +2 -3
index af89408befe8..376899cfcbf1 100644
@@ -175,9 +175,8 @@ static ssize_t bch_dump_read(struct file *file, char __user *buf,
 		struct keybuf_key *w;
 		unsigned bytes = min(i->bytes, size);
 
-		int err = copy_to_user(buf, i->buf, bytes);
-		if (err)
-			return err;
+		if (copy_to_user(buf, i->buf, bytes))
+			return -EFAULT;
 
 		ret	 += bytes;
 		buf	 += bytes;
Signature · 1 line
2.16.2
#37 lore raw

Re: [PATCH 13/16] bcache: Make bch_dump_read() fail if copying to user space fails

Quoted 14 lines · Bart Van Assche

copy_to_user() returns the number of remaining bytes. Avoid that a larger value is returned than the number of bytes that have been copied by returning -EFAULT if not all bytes have been copied.

---
 drivers/md/bcache/debug.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/md/bcache/debug.c +0 -0
index af89408befe8..376899cfcbf1 100644

drivers/md/bcache/debug.c static ssize_t bch_dump_read(struct file *file, char __user *buf, · line 180

Quoted 9 lines
drivers/md/bcache/debug.c +2 -3
@@ -175,9 +175,8 @@ static ssize_t bch_dump_read(struct file *file, char __user *buf,
 		struct keybuf_key *w;
 		unsigned bytes = min(i->bytes, size);
 
-		int err = copy_to_user(buf, i->buf, bytes);
-		if (err)
-			return err;
+		if (copy_to_user(buf, i->buf, bytes))
+			return -EFAULT;
 

Hi Bart,

I am not sure whether this change is correct. -EFAULT seems not an expected return value of read(2), while -1 is the expected return value when error occurs.

Maybe if copy_to_user() returns value in (0, size], "ret + (size - err)" should be returned. An exception is when copy_to_user() returns 0 and ret is 0 too, in this situation -1 should be returned.

Correct me if I am wrong.

Coly Li

Quoted 3 lines
drivers/md/bcache/debug.c +0 -0
 		ret	 += bytes;
 		buf	 += bytes;
#38 lore raw

Re: [PATCH 13/16] bcache: Make bch_dump_read() fail if copying to user space fails

T24gRnJpLCAyMDE4LTAzLTE2IGF0IDAxOjAwICswODAwLCBDb2x5IExpIHdyb3RlOg0KPiBPbiAx NS8wMy8yMDE4IDExOjA4IFBNLCBCYXJ0IFZhbiBBc3NjaGUgd3JvdGU6DQo+ID4gY29weV90b191 c2VyKCkgcmV0dXJucyB0aGUgbnVtYmVyIG9mIHJlbWFpbmluZyBieXRlcy4gQXZvaWQgdGhhdA0K PiA+IGEgbGFyZ2VyIHZhbHVlIGlzIHJldHVybmVkIHRoYW4gdGhlIG51bWJlciBvZiBieXRlcyB0 aGF0IGhhdmUNCj4gPiBiZWVuIGNvcGllZCBieSByZXR1cm5pbmcgLUVGQVVMVCBpZiBub3QgYWxs IGJ5dGVzIGhhdmUgYmVlbiBjb3BpZWQuDQo+ID4gDQo+ID4gU2lnbmVkLW9mZi1ieTogQmFydCBW YW4gQXNzY2hlIDxiYXJ0LnZhbmFzc2NoZUB3ZGMuY29tPg0KPiA+IC0tLQ0KPiA+ICBkcml2ZXJz L21kL2JjYWNoZS9kZWJ1Zy5jIHwgNSArKy0tLQ0KPiA+ICAxIGZpbGUgY2hhbmdlZCwgMiBpbnNl cnRpb25zKCspLCAzIGRlbGV0aW9ucygtKQ0KPiA+IA0KPiA+IGRpZmYgLS1naXQgYS9kcml2ZXJz L21kL2JjYWNoZS9kZWJ1Zy5jIGIvZHJpdmVycy9tZC9iY2FjaGUvZGVidWcuYw0KPiA+IGluZGV4 IGFmODk0MDhiZWZlOC4uMzc2ODk5Y2ZjYmYxIDEwMDY0NA0KPiA+IC0tLSBhL2RyaXZlcnMvbWQv YmNhY2hlL2RlYnVnLmMNCj4gPiArKysgYi9kcml2ZXJzL21kL2JjYWNoZS9kZWJ1Zy5jDQo+ID4g QEAgLTE3NSw5ICsxNzUsOCBAQCBzdGF0aWMgc3NpemVfdCBiY2hfZHVtcF9yZWFkKHN0cnVjdCBm aWxlICpmaWxlLCBjaGFyIF9fdXNlciAqYnVmLA0KPiA+ICAJCXN0cnVjdCBrZXlidWZfa2V5ICp3 Ow0KPiA+ICAJCXVuc2lnbmVkIGJ5dGVzID0gbWluKGktPmJ5dGVzLCBzaXplKTsNCj4gPiAgDQo+ ID4gLQkJaW50IGVyciA9IGNvcHlfdG9fdXNlcihidWYsIGktPmJ1ZiwgYnl0ZXMpOw0KPiA+IC0J CWlmIChlcnIpDQo+ID4gLQkJCXJldHVybiBlcnI7DQo+ID4gKwkJaWYgKGNvcHlfdG9fdXNlcihi dWYsIGktPmJ1ZiwgYnl0ZXMpKQ0KPiA+ICsJCQlyZXR1cm4gLUVGQVVMVDsNCj4gPiAgDQo+IA0K PiBIaSBCYXJ0LA0KPiANCj4gSSBhbSBub3Qgc3VyZSB3aGV0aGVyIHRoaXMgY2hhbmdlIGlzIGNv cnJlY3QuIC1FRkFVTFQgc2VlbXMgbm90IGFuDQo+IGV4cGVjdGVkIHJldHVybiB2YWx1ZSBvZiBy ZWFkKDIpLCB3aGlsZSAtMSBpcyB0aGUgZXhwZWN0ZWQgcmV0dXJuIHZhbHVlDQo+IHdoZW4gZXJy b3Igb2NjdXJzLg0KPiANCj4gTWF5YmUgaWYgY29weV90b191c2VyKCkgcmV0dXJucyB2YWx1ZSBp biAoMCwgc2l6ZV0sICJyZXQgKyAoc2l6ZSAtIGVycikiDQo+IHNob3VsZCBiZSByZXR1cm5lZC4g QW4gZXhjZXB0aW9uIGlzIHdoZW4gY29weV90b191c2VyKCkgcmV0dXJucyAwIGFuZA0KPiByZXQg aXMgMCB0b28sIGluIHRoaXMgc2l0dWF0aW9uIC0xIHNob3VsZCBiZSByZXR1cm5lZC4NCj4gDQo+ IENvcnJlY3QgbWUgaWYgSSBhbSB3cm9uZy4NCg0KSGVsbG8gQ29seSwNCg0KSSdtIG5vdCBmYW1p bGlhciBlbm91Z2ggd2l0aCBiY2FjaGUgdG8gcHJvdmlkZSB0aGUgYW5zd2VyIHRvIHlvdXIgcXVl c3Rpb24gc28NCkkgd2lsbCBkcm9wIHRoaXMgcGF0Y2ggZnJvbSB0aGlzIHNlcmllcy4NCg0KVGhh bmtzLA0KDQpCYXJ0Lg0KDQoNCg==

#39 lore raw

Re: [PATCH 13/16] bcache: Make bch_dump_read() fail if copying to user space fails

Quoted 36 lines · Bart Van Assche
Quoted 35 lines · Coly Li
Quoted 14 lines · Bart Van Assche

copy_to_user() returns the number of remaining bytes. Avoid that a larger value is returned than the number of bytes that have been copied by returning -EFAULT if not all bytes have been copied.

---
 drivers/md/bcache/debug.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/md/bcache/debug.c +0 -0
index af89408befe8..376899cfcbf1 100644

drivers/md/bcache/debug.c static ssize_t bch_dump_read(struct file *file, char __user *buf, · line 180

Quoted 9 lines
drivers/md/bcache/debug.c +2 -3
@@ -175,9 +175,8 @@ static ssize_t bch_dump_read(struct file *file, char __user *buf,
 		struct keybuf_key *w;
 		unsigned bytes = min(i->bytes, size);
 
-		int err = copy_to_user(buf, i->buf, bytes);
-		if (err)
-			return err;
+		if (copy_to_user(buf, i->buf, bytes))
+			return -EFAULT;
 

Hi Bart,

I am not sure whether this change is correct. -EFAULT seems not an expected return value of read(2), while -1 is the expected return value when error occurs.

Maybe if copy_to_user() returns value in (0, size], "ret + (size - err)" should be returned. An exception is when copy_to_user() returns 0 and ret is 0 too, in this situation -1 should be returned.

Quoted 6 lines
Quoted 1 line

Correct me if I am wrong.

Hello Coly,

I'm not familiar enough with bcache to provide the answer to your question so I will drop this patch from this series.

Hi Bart,

It seems you catch a code bug here. I will look into this and handle it here.

Thanks for the hint :-)

Coly Li

#40 lore raw

PATCH 14/16 bcache: Make csum_set() implementation easier to read

In reply to Bart Van Assche

Introduce two temporary variables to avoid having to repeat expressions. This patch does not change any functionality.

---
 drivers/md/bcache/bcache.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/md/bcache/bcache.h +6 -4
index 12e5197f186c..72b1ea4576d9 100644
@@ -777,10 +777,12 @@ static inline bool ptr_available(struct cache_set *c, const struct bkey *k,
  * This is used for various on disk data structures - cache_sb, prio_set, bset,
  * jset: The checksum is _always_ the first 8 bytes of these structs
  */
-#define csum_set(i)							\
-	bch_crc64(((void *) (i)) + sizeof(uint64_t),			\
-		  ((void *) bset_bkey_last(i)) -			\
-		  (((void *) (i)) + sizeof(uint64_t)))
+#define csum_set(i) ({						\
+	const void *p = (void *)(i) + sizeof(uint64_t);		\
+	const void *q = bset_bkey_last(i);			\
+								\
+	bch_crc64(p, q - p);					\
+})
 
 /* Error handling macros */
 
Signature · 1 line
2.16.2
#41 lore raw

Re: [PATCH 14/16] bcache: Make csum_set() implementation easier to read

drivers/md/bcache/bcache.h static inline bool ptr_available(struct cache_set *c, const struct bkey *k, · line 785

Quoted 6 lines · Bart Van Assche
drivers/md/bcache/bcache.h +6 -0
+#define csum_set(i) ({						\
+	const void *p = (void *)(i) + sizeof(uint64_t);		\
+	const void *q = bset_bkey_last(i);			\
+								\
+	bch_crc64(p, q - p);					\
+})

Having this as a macro is really ugly. Any chane to turn this into a proper function?

#42 lore raw

PATCH 15/16 bcache: Fix an endianness bug

In reply to Bart Van Assche

Ensure that byte swapping occurs on big endian architectures when reading or writing the superblock.

---
 drivers/md/bcache/bcache.h | 12 ++++++++++++
 drivers/md/bcache/super.c  |  4 ++--
 2 files changed, 14 insertions(+), 2 deletions(-)
drivers/md/bcache/bcache.h +12 -0
index 72b1ea4576d9..50ddc78596bf 100644
@@ -784,6 +784,18 @@ static inline bool ptr_available(struct cache_set *c, const struct bkey *k,
 	bch_crc64(p, q - p);					\
 })
 
+/*
+ * Variant of csum_set() for data structures in which (i)->keys has type
+ * __le16.
+ */
+#define csum_set_le(i) ({						\
+	const void *p = (void *)(i) + sizeof(uint64_t);			\
+	const void *q = bkey_idx((struct bkey *)(i)->d,			\
+				 le16_to_cpu((i)->keys));		\
+									\
+	bch_crc64(p, q - p);						\
+})
+
 /* Error handling macros */
 
 #define btree_bug(b, ...)						\
drivers/md/bcache/super.c +2 -2
index 39bec137f636..31d700aecd56 100644
@@ -110,7 +110,7 @@ static const char *read_super(struct cache_sb *sb, struct block_device *bdev,
 		goto err;
 
 	err = "Bad checksum";
-	if (s->csum != csum_set(s))
+	if (s->csum != csum_set_le(s))
 		goto err;
 
 	err = "Bad UUID";
@@ -236,7 +236,7 @@ static void __write_super(struct cache_sb *sb, struct bio *bio)
 	for (i = 0; i < sb->keys; i++)
 		out->d[i] = cpu_to_le64(sb->d[i]);
 
-	out->csum = csum_set(out);
+	out->csum = csum_set_le(out);
 
 	pr_debug("ver %llu, flags %llu, seq %llu",
 		 sb->version, sb->flags, sb->seq);
Signature · 1 line
2.16.2
#43 lore raw

Re: [PATCH 15/16] bcache: Fix an endianness bug

Quoted 4 lines · Bart Van Assche

Ensure that byte swapping occurs on big endian architectures when reading or writing the superblock.

Hi Bart,

The code still does not work with your patch on big endian machine (e.g. s390x). When I fix the bcache s390x bug, I did something like this patch in my first try. It turns out more things need to be fixed, 1, some cache_sb members only swapped to cpu endianness when read in, not swapped to little endian when write out. For example data_offset, nbuckets, nr_in_set, nr_this_dev ...
2, checksum is calculated in cpu endiannness, not explicitly in little endian.

Also user space tools need to update to support the endianness issue.

How about leave the endianness problem to me? I will pick code piece from your patch and set 'From: Bart Van Assche <[email protected]>' on the patch(s), and continue my fix for bcache on s390x.

Thanks.

Coly Li

Quoted 51 lines
---
 drivers/md/bcache/bcache.h | 12 ++++++++++++
 drivers/md/bcache/super.c  |  4 ++--
 2 files changed, 14 insertions(+), 2 deletions(-)
drivers/md/bcache/bcache.h +12 -0
index 72b1ea4576d9..50ddc78596bf 100644
@@ -784,6 +784,18 @@ static inline bool ptr_available(struct cache_set *c, const struct bkey *k,
 	bch_crc64(p, q - p);					\
 })
 
+/*
+ * Variant of csum_set() for data structures in which (i)->keys has type
+ * __le16.
+ */
+#define csum_set_le(i) ({						\
+	const void *p = (void *)(i) + sizeof(uint64_t);			\
+	const void *q = bkey_idx((struct bkey *)(i)->d,			\
+				 le16_to_cpu((i)->keys));		\
+									\
+	bch_crc64(p, q - p);						\
+})
+
 /* Error handling macros */
 
 #define btree_bug(b, ...)						\
drivers/md/bcache/super.c +2 -2
index 39bec137f636..31d700aecd56 100644
@@ -110,7 +110,7 @@ static const char *read_super(struct cache_sb *sb, struct block_device *bdev,
 		goto err;
 
 	err = "Bad checksum";
-	if (s->csum != csum_set(s))
+	if (s->csum != csum_set_le(s))
 		goto err;
 
 	err = "Bad UUID";
@@ -236,7 +236,7 @@ static void __write_super(struct cache_sb *sb, struct bio *bio)
 	for (i = 0; i < sb->keys; i++)
 		out->d[i] = cpu_to_le64(sb->d[i]);
 
-	out->csum = csum_set(out);
+	out->csum = csum_set_le(out);
 
 	pr_debug("ver %llu, flags %llu, seq %llu",
 		 sb->version, sb->flags, sb->seq);
#44 lore raw

Re: [PATCH 15/16] bcache: Fix an endianness bug

T24gRnJpLCAyMDE4LTAzLTE2IGF0IDEyOjQ3ICswODAwLCBDb2x5IExpIHdyb3RlOg0KPiBUaGUg Y29kZSBzdGlsbCBkb2VzIG5vdCB3b3JrIHdpdGggeW91ciBwYXRjaCBvbiBiaWcgZW5kaWFuIG1h Y2hpbmUgKGUuZy4NCj4gczM5MHgpLiBXaGVuIEkgZml4IHRoZSBiY2FjaGUgczM5MHggYnVnLCBJ IGRpZCBzb21ldGhpbmcgbGlrZSB0aGlzIHBhdGNoDQo+IGluIG15IGZpcnN0IHRyeS4gSXQgdHVy bnMgb3V0IG1vcmUgdGhpbmdzIG5lZWQgdG8gYmUgZml4ZWQsDQo+IDEsIHNvbWUgY2FjaGVfc2Ig bWVtYmVycyBvbmx5IHN3YXBwZWQgdG8gY3B1IGVuZGlhbm5lc3Mgd2hlbiByZWFkIGluLA0KPiBu b3Qgc3dhcHBlZCB0byBsaXR0bGUgZW5kaWFuIHdoZW4gd3JpdGUgb3V0LiBGb3IgZXhhbXBsZSBk YXRhX29mZnNldCwNCj4gbmJ1Y2tldHMsIG5yX2luX3NldCwgbnJfdGhpc19kZXYgLi4uDQo+IDIs IGNoZWNrc3VtIGlzIGNhbGN1bGF0ZWQgaW4gY3B1IGVuZGlhbm5uZXNzLCBub3QgZXhwbGljaXRs eSBpbiBsaXR0bGUNCj4gZW5kaWFuLg0KPiANCj4gQWxzbyB1c2VyIHNwYWNlIHRvb2xzIG5lZWQg dG8gdXBkYXRlIHRvIHN1cHBvcnQgdGhlIGVuZGlhbm5lc3MgaXNzdWUuDQo+IA0KPiBIb3cgYWJv dXQgbGVhdmUgdGhlIGVuZGlhbm5lc3MgcHJvYmxlbSB0byBtZT8gSSB3aWxsIHBpY2sgY29kZSBw aWVjZQ0KPiBmcm9tIHlvdXIgcGF0Y2ggYW5kIHNldCAnRnJvbTogQmFydCBWYW4gQXNzY2hlIDxi YXJ0LnZhbmFzc2NoZUB3ZGMuY29tPicNCj4gb24gdGhlIHBhdGNoKHMpLCBhbmQgY29udGludWUg bXkgZml4IGZvciBiY2FjaGUgb24gczM5MHguDQoNCkhlbGxvIENvbHksDQoNClRoYXQgc291bmRz IGZpbmUgdG8gbWUuIFBsZWFzZSBsZXQgbWUga25vdyBpZiB5b3Ugd291bGQgbGlrZSBtZSB0byBy ZXBvc3QNCnRoaXMgc2VyaWVzIGFuZC9vciBhZGRyZXNzIHRoZSBmZWVkYmFjayB0aGF0IEkgcmVj ZWl2ZWQgZm9yIHRoaXMgcGF0Y2ggc2VyaWVzLg0KDQpUaGFua3MsDQoNCkJhcnQuDQoNCg0K

#45 lore raw

Re: [PATCH 15/16] bcache: Fix an endianness bug

Quoted 12 lines · Bart Van Assche
Quoted 11 lines · Coly Li

The code still does not work with your patch on big endian machine (e.g. s390x). When I fix the bcache s390x bug, I did something like this patch in my first try. It turns out more things need to be fixed, 1, some cache_sb members only swapped to cpu endianness when read in, not swapped to little endian when write out. For example data_offset, nbuckets, nr_in_set, nr_this_dev ...
2, checksum is calculated in cpu endiannness, not explicitly in little endian.

Also user space tools need to update to support the endianness issue.

Quoted 8 lines
Quoted 3 lines

How about leave the endianness problem to me? I will pick code piece from your patch and set 'From: Bart Van Assche <[email protected]>' on the patch(s), and continue my fix for bcache on s390x.

Hello Coly,

That sounds fine to me. Please let me know if you would like me to repost this series and/or address the feedback that I received for this patch series.

Hi Bart,

I see Mike already picks some of your patches, repost an updated version for the rested patch should be a good idea.

Thanks.

Coly Li

#46 lore raw

PATCH 16/16 bcache: Fix endianness annotations

In reply to Bart Van Assche

This patch avoids that sparse complains about using integer types incorrectly (u32, __le32, __be32, ...) by splitting struct cache_sb into two different structures:
- struct cache_sb in which all integer members except csum have CPU endianness.
- struct cache_sb_le in which all integer members except csum are declared as little endian.

---
 drivers/md/bcache/super.c   |  10 ++--
 include/uapi/linux/bcache.h | 118 +++++++++++++++++++++++---------------------
 2 files changed, 68 insertions(+), 60 deletions(-)
drivers/md/bcache/super.c +6 -4
index 31d700aecd56..ef659c7d72f9 100644
@@ -63,20 +63,22 @@ struct workqueue_struct *bcache_wq;
 /* limitation of bcache devices number on single system */
 #define BCACHE_DEVICE_IDX_MAX	((1U << MINORBITS)/BCACHE_MINORS)
 
+struct cache_sb_le STRUCT_CACHE_SB(le);
+
 /* Superblock */
 
 static const char *read_super(struct cache_sb *sb, struct block_device *bdev,
 			      struct page **res)
 {
 	const char *err;
-	struct cache_sb *s;
+	struct cache_sb_le *s;
 	struct buffer_head *bh = __bread(bdev, 1, SB_SIZE);
 	unsigned i;
 
 	if (!bh)
 		return "IO error";
 
-	s = (struct cache_sb *) bh->b_data;
+	s = (struct cache_sb_le *) bh->b_data;
 
 	sb->offset		= le64_to_cpu(s->offset);
 	sb->version		= le64_to_cpu(s->version);
@@ -211,7 +213,7 @@ static void write_bdev_super_endio(struct bio *bio)
 
 static void __write_super(struct cache_sb *sb, struct bio *bio)
 {
-	struct cache_sb *out = page_address(bio_first_page_all(bio));
+	struct cache_sb_le *out = page_address(bio_first_page_all(bio));
 	unsigned i;
 
 	bio->bi_iter.bi_sector	= SB_SECTOR;
@@ -959,7 +961,7 @@ void bch_cached_dev_detach(struct cached_dev *dc)
 int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c,
 			  uint8_t *set_uuid)
 {
-	uint32_t rtime = cpu_to_le32(get_seconds());
+	__le32 rtime = cpu_to_le32(get_seconds());
 	struct uuid_entry *u;
 	char buf[BDEVNAME_SIZE];
 
include/uapi/linux/bcache.h +62 -56

144 lines not on this page · raw message

Signature · 1 line
2.16.2
Reviewed-by on v1 16/16
#47 lore raw

Re: [PATCH 16/16] bcache: Fix endianness annotations

Quoted 7 lines · Bart Van Assche

This patch avoids that sparse complains about using integer types incorrectly (u32, __le32, __be32, ...) by splitting struct cache_sb into two different structures:
- struct cache_sb in which all integer members except csum have CPU endianness.
- struct cache_sb_le in which all integer members except csum are declared as little endian.

Can you call this cache_sb_disk to name it after the purpose instead of the implementation?

Except for that this looks like the right fix:

Reviewed-by on v1 16/16
#48 lore raw

Re: [PATCH 16/16] bcache: Fix endianness annotations

In reply to Bart Van Assche
Quoted 9 lines · Bart Van Assche

This patch avoids that sparse complains about using integer types incorrectly (u32, __le32, __be32, ...) by splitting struct cache_sb into two different structures:
- struct cache_sb in which all integer members except csum have CPU endianness.
- struct cache_sb_le in which all integer members except csum are declared as little endian.

Hi Bart,

This patch is good, and I like the idea of STRUCT_CACHE_SB().

How about letting me to pick this patch into my bcache s390x fixes? I will fix the structure name suggested by Christoph, and set you as the patch author.

Thanks.

Coly Li

Quoted 205 lines
---
 drivers/md/bcache/super.c   |  10 ++--
 include/uapi/linux/bcache.h | 118 +++++++++++++++++++++++---------------------
 2 files changed, 68 insertions(+), 60 deletions(-)
drivers/md/bcache/super.c +6 -4
index 31d700aecd56..ef659c7d72f9 100644
@@ -63,20 +63,22 @@ struct workqueue_struct *bcache_wq;
 /* limitation of bcache devices number on single system */
 #define BCACHE_DEVICE_IDX_MAX	((1U << MINORBITS)/BCACHE_MINORS)
 
+struct cache_sb_le STRUCT_CACHE_SB(le);
+
 /* Superblock */
 
 static const char *read_super(struct cache_sb *sb, struct block_device *bdev,
 			      struct page **res)
 {
 	const char *err;
-	struct cache_sb *s;
+	struct cache_sb_le *s;
 	struct buffer_head *bh = __bread(bdev, 1, SB_SIZE);
 	unsigned i;
 
 	if (!bh)
 		return "IO error";
 
-	s = (struct cache_sb *) bh->b_data;
+	s = (struct cache_sb_le *) bh->b_data;
 
 	sb->offset		= le64_to_cpu(s->offset);
 	sb->version		= le64_to_cpu(s->version);
@@ -211,7 +213,7 @@ static void write_bdev_super_endio(struct bio *bio)
 
 static void __write_super(struct cache_sb *sb, struct bio *bio)
 {
-	struct cache_sb *out = page_address(bio_first_page_all(bio));
+	struct cache_sb_le *out = page_address(bio_first_page_all(bio));
 	unsigned i;
 
 	bio->bi_iter.bi_sector	= SB_SECTOR;
@@ -959,7 +961,7 @@ void bch_cached_dev_detach(struct cached_dev *dc)
 int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c,
 			  uint8_t *set_uuid)
 {
-	uint32_t rtime = cpu_to_le32(get_seconds());
+	__le32 rtime = cpu_to_le32(get_seconds());
 	struct uuid_entry *u;
 	char buf[BDEVNAME_SIZE];
 
include/uapi/linux/bcache.h +62 -56
index 821f71a2e48f..772787c47772 100644
@@ -154,57 +154,63 @@ static inline struct bkey *bkey_idx(const struct bkey *k, unsigned nr_keys)
 
 #define BDEV_DATA_START_DEFAULT		16	/* sectors */
 
-struct cache_sb {
-	__u64			csum;
-	__u64			offset;	/* sector where this sb was written */
-	__u64			version;
-
-	__u8			magic[16];
-
-	__u8			uuid[16];
-	union {
-		__u8		set_uuid[16];
-		__u64		set_magic;
-	};
-	__u8			label[SB_LABEL_SIZE];
-
-	__u64			flags;
-	__u64			seq;
-	__u64			pad[8];
-
-	union {
-	struct {
-		/* Cache devices */
-		__u64		nbuckets;	/* device size */
-
-		__u16		block_size;	/* sectors */
-		__u16		bucket_size;	/* sectors */
-
-		__u16		nr_in_set;
-		__u16		nr_this_dev;
-	};
-	struct {
-		/* Backing devices */
-		__u64		data_offset;
-
-		/*
-		 * block_size from the cache device section is still used by
-		 * backing devices, so don't add anything here until we fix
-		 * things to not need it for backing devices anymore
-		 */
-	};
-	};
-
-	__u32			last_mount;	/* time_t */
-
-	__u16			first_bucket;
-	union {
-		__u16		njournal_buckets;
-		__u16		keys;
-	};
-	__u64			d[SB_JOURNAL_BUCKETS];	/* journal buckets */
+#define STRUCT_CACHE_SB(e)						\
+{									\
+	__u64			csum;					\
+	/* sector where this sb was written */				\
+	__##e##64		offset;					\
+	__##e##64		version;				\
+									\
+	__u8			magic[16];				\
+									\
+	__u8			uuid[16];				\
+	union {								\
+		__u8		set_uuid[16];				\
+		__##e##64	set_magic;				\
+	};								\
+	__u8			label[SB_LABEL_SIZE];			\
+									\
+	__##e##64		flags;					\
+	__##e##64		seq;					\
+	__##e##64		pad[8];					\
+									\
+	union {								\
+	struct {							\
+		/* Cache devices */					\
+		__##e##64	nbuckets;	/* device size */	\
+									\
+		__##e##16	block_size;	/* sectors */		\
+		__##e##16	bucket_size;	/* sectors */		\
+									\
+		__##e##16	nr_in_set;				\
+		__##e##16	nr_this_dev;				\
+	};								\
+	struct {							\
+		/* Backing devices */					\
+		__##e##64	data_offset;				\
+									\
+		/*							\
+		 * block_size from the cache device section is still	\
+		 * used by backing devices, so don't add anything here	\
+		 * until we fix things to not need it for backing	\
+		 * devices anymore					\
+		 */							\
+	};								\
+	};								\
+									\
+	__##e##32		last_mount;	/* time_t */		\
+									\
+	__##e##16		first_bucket;				\
+	union {								\
+		__##e##16	njournal_buckets;			\
+		__##e##16	keys;					\
+	};								\
+	/* journal buckets */						\
+	__##e##64		d[SB_JOURNAL_BUCKETS];			\
 };
 
+struct cache_sb STRUCT_CACHE_SB(u);
+
 static inline _Bool SB_IS_BDEV(const struct cache_sb *sb)
 {
 	return sb->version == BCACHE_SB_VERSION_BDEV
@@ -306,7 +312,7 @@ struct prio_set {
 	__u64			next_bucket;
 
 	struct bucket_disk {
-		__u16		prio;
+		__le16		prio;
 		__u8		gen;
 	} __attribute((packed)) data[];
 };
@@ -318,9 +324,9 @@ struct uuid_entry {
 		struct {
 			__u8	uuid[16];
 			__u8	label[32];
-			__u32	first_reg;
-			__u32	last_reg;
-			__u32	invalidated;
+			__le32	first_reg;
+			__le32	last_reg;
+			__le32	invalidated;
 
 			__u32	flags;
 			/* Size of flash only volumes */
@@ -366,9 +372,9 @@ struct bset {
 struct uuid_entry_v0 {
 	__u8		uuid[16];
 	__u8		label[32];
-	__u32		first_reg;
-	__u32		last_reg;
-	__u32		invalidated;
+	__le32		first_reg;
+	__le32		last_reg;
+	__le32		invalidated;
 	__u32		pad;
 };
 
#49 lore raw
In reply to Bart Van Assche

Hey Bart & everyone,

I'll dig through these. In the future can you please send things off the linux-bcache list? I'm a bit off my normal workflow this way.

Thanks,

Mike

Quoted 49 lines · Bart Van Assche

Hello Michael, Coly and Christoph,

A few weeks ago I analyzed the compiler (W=1), sparse and smatch warnings triggered by the bcache driver. This patch series is what I came up with. Although none of these patches have been tested I think these patches are worth a closer look. Feedback is welcome.

Thanks,

Bart.

Bart Van Assche (16):
bcache: Fix indentation
bcache: Add __printf annotation to __bch_check_keys()
bcache: Annotate switch fall-through
bcache: Fix kernel-doc warnings
bcache: Remove an unused variable
bcache: Suppress more warnings about set-but-not-used variables
bcache: Reduce the number of sparse complaints about lock imbalances
bcache: Fix a compiler warning in bcache_device_init()
bcache: Remove a redundant assignment
bcache: Suppress a compiler warning in bch_##name##_h()
bcache: Check the d->disk pointer before using it
bcache: Make it easier for static analyzers to analyze
bch_allocator_thread()
bcache: Make bch_dump_read() fail if copying to user space fails
bcache: Make csum_set() implementation easier to read
bcache: Fix an endianness bug
bcache: Fix endianness annotations

 drivers/md/bcache/alloc.c     |   7 +--
 drivers/md/bcache/bcache.h    |  22 ++++++--
 drivers/md/bcache/bset.c      |   4 +-
 drivers/md/bcache/bset.h      |   5 +-
 drivers/md/bcache/btree.c     |   4 +-
 drivers/md/bcache/closure.c   |   8 +--
 drivers/md/bcache/debug.c     |   5 +-
 drivers/md/bcache/extents.c   |   2 -
 drivers/md/bcache/journal.c   |   4 +-
 drivers/md/bcache/request.c   |   1 +
 drivers/md/bcache/super.c     |  23 ++++----
 drivers/md/bcache/util.c      |  33 +++++++-----
 drivers/md/bcache/writeback.h |   2 +-
 include/uapi/linux/bcache.h   | 118 ++++++++++++++++++++++--------------------
 14 files changed, 131 insertions(+), 107 deletions(-)

--
2.16.2

#50 lore raw

T24gRnJpLCAyMDE4LTAzLTE2IGF0IDExOjE2IC0wNzAwLCBNaWNoYWVsIEx5bGUgd3JvdGU6DQo+ IEknbGwgZGlnIHRocm91Z2ggdGhlc2UuICBJbiB0aGUgZnV0dXJlIGNhbiB5b3UgcGxlYXNlIHNl bmQgdGhpbmdzIG9mZg0KPiB0aGUgbGludXgtYmNhY2hlIGxpc3Q/ICBJJ20gYSBiaXQgb2ZmIG15 IG5vcm1hbCB3b3JrZmxvdyB0aGlzIHdheS4NCg0KSSB3aWxsIGRvIHRoYXQuIFRoYW5rcyBmb3Ig dGhlIHJldmlld3MhDQoNCkJhcnQuDQoNCg0KDQo=