The badblocks helper functions that modify the bad blocks state are only called from inside write_seqlock_irq*(&bb->lock) / write_sequnlock_irq*(&bb->lock) sections. Annotate these functions with __must_hold(&bb->lock): - front_merge() - front_combine() - front_overwrite() - insert_at() - badblocks_update_acked() - try_adjacent_combine() - front_clear() - front_splitting_clear() The helper functions that only read the bad blocks table are called either from inside a write_seqlock_irq*() section or by _badblocks_check() from inside a read_seqbegin() / read_seqretry() section. Clang's context analysis treats the latter as holding bb->lock shared. Hence, annotate these functions with __must_hold_shared(&bb->lock): - prev_by_hint() - prev_badblocks() - can_merge_front() - can_combine_front() - overlap_front() - overlap_behind() - can_front_overwrite() - _badblocks_check() Signed-off-by: Bart Van Assche --- block/badblocks.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/block/badblocks.c b/block/badblocks.c index ece64e76fe8f..2528b4481ea8 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -455,6 +455,7 @@ * table. */ static int prev_by_hint(struct badblocks *bb, sector_t s, int hint) + __must_hold_shared(&bb->lock) { int hint_end = hint + 2; u64 *p = bb->page; @@ -480,6 +481,7 @@ static int prev_by_hint(struct badblocks *bb, sector_t s, int hint) */ static int prev_badblocks(struct badblocks *bb, struct badblocks_context *bad, int hint) + __must_hold_shared(&bb->lock) { sector_t s = bad->start; int ret = -1; @@ -533,6 +535,7 @@ static int prev_badblocks(struct badblocks *bb, struct badblocks_context *bad, */ static bool can_merge_front(struct badblocks *bb, int prev, struct badblocks_context *bad) + __must_hold_shared(&bb->lock) { sector_t s = bad->start; u64 *p = bb->page; @@ -550,6 +553,7 @@ static bool can_merge_front(struct badblocks *bb, int prev, * merged from bad->len. */ static int front_merge(struct badblocks *bb, int prev, struct badblocks_context *bad) + __must_hold(&bb->lock) { sector_t sectors = bad->len; sector_t s = bad->start; @@ -587,6 +591,7 @@ static int front_merge(struct badblocks *bb, int prev, struct badblocks_context */ static bool can_combine_front(struct badblocks *bb, int prev, struct badblocks_context *bad) + __must_hold_shared(&bb->lock) { u64 *p = bb->page; @@ -607,6 +612,7 @@ static bool can_combine_front(struct badblocks *bb, int prev, * it is unnecessary to clear p[perv] after front merge. */ static void front_combine(struct badblocks *bb, int prev) + __must_hold(&bb->lock) { u64 *p = bb->page; @@ -625,6 +631,7 @@ static void front_combine(struct badblocks *bb, int prev) */ static bool overlap_front(struct badblocks *bb, int front, struct badblocks_context *bad) + __must_hold_shared(&bb->lock) { u64 *p = bb->page; @@ -640,6 +647,7 @@ static bool overlap_front(struct badblocks *bb, int front, */ static bool overlap_behind(struct badblocks *bb, struct badblocks_context *bad, int behind) + __must_hold_shared(&bb->lock) { u64 *p = bb->page; @@ -672,6 +680,7 @@ static bool overlap_behind(struct badblocks *bb, struct badblocks_context *bad, */ static bool can_front_overwrite(struct badblocks *bb, int prev, struct badblocks_context *bad, int *extra) + __must_hold_shared(&bb->lock) { u64 *p = bb->page; int len; @@ -715,6 +724,7 @@ static bool can_front_overwrite(struct badblocks *bb, int prev, */ static int front_overwrite(struct badblocks *bb, int prev, struct badblocks_context *bad, int extra) + __must_hold(&bb->lock) { u64 *p = bb->page; sector_t orig_end = BB_END(p[prev]); @@ -776,6 +786,7 @@ static int front_overwrite(struct badblocks *bb, int prev, * the location is indexed by 'at'. */ static int insert_at(struct badblocks *bb, int at, struct badblocks_context *bad) + __must_hold(&bb->lock) { u64 *p = bb->page; int len; @@ -791,6 +802,7 @@ static int insert_at(struct badblocks *bb, int at, struct badblocks_context *bad } static void badblocks_update_acked(struct badblocks *bb) + __must_hold(&bb->lock) { bool unacked = false; u64 *p = bb->page; @@ -815,6 +827,7 @@ static void badblocks_update_acked(struct badblocks *bb) * overlapped with the bad range (from bad table) indexed by 'behind'. */ static bool try_adjacent_combine(struct badblocks *bb, int prev) + __must_hold(&bb->lock) { u64 *p = bb->page; @@ -987,6 +1000,7 @@ static bool _badblocks_set(struct badblocks *bb, sector_t s, sector_t sectors, */ static int front_clear(struct badblocks *bb, int prev, struct badblocks_context *bad, int *deleted) + __must_hold(&bb->lock) { sector_t sectors = bad->len; sector_t s = bad->start; @@ -1030,6 +1044,7 @@ static int front_clear(struct badblocks *bb, int prev, */ static int front_splitting_clear(struct badblocks *bb, int prev, struct badblocks_context *bad) + __must_hold(&bb->lock) { u64 *p = bb->page; u64 end = BB_END(p[prev]); @@ -1185,6 +1200,7 @@ static bool _badblocks_clear(struct badblocks *bb, sector_t s, sector_t sectors) /* Do the exact work to check bad blocks range from the bad block table */ static int _badblocks_check(struct badblocks *bb, sector_t s, sector_t sectors, sector_t *first_bad, sector_t *bad_sectors) + __must_hold_shared(&bb->lock) { int prev = -1, hint = -1, set = 0; struct badblocks_context bad;