Skip to content

Commit b16b1b6

Browse files
committed
md/bitmap: fix calculation of 'chunks' - missing shift.
commit 61a0d80 "md/bitmap: discard CHUNK_BLOCK_SHIFT macro" replaced CHUNK_BLOCK_RATIO() by the same text that was replacing CHUNK_BLOCK_SHIFT() - which is clearly wrong. The result is that 'chunks' is often too small by 1, which can sometimes result in a crash (not sure how). So use the correct replacement, and get rid of CHUNK_BLOCK_RATIO which is no longe used. Reported-by: Karl Newman <[email protected]> Tested-by: Karl Newman <[email protected]> Signed-off-by: NeilBrown <[email protected]>
1 parent 69964ea commit b16b1b6

File tree

2 files changed

+1
-5
lines changed

2 files changed

+1
-5
lines changed

drivers/md/bitmap.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,8 +1727,7 @@ int bitmap_create(struct mddev *mddev)
17271727
bitmap->chunkshift = (ffz(~mddev->bitmap_info.chunksize)
17281728
- BITMAP_BLOCK_SHIFT);
17291729

1730-
/* now that chunksize and chunkshift are set, we can use these macros */
1731-
chunks = (blocks + bitmap->chunkshift - 1) >>
1730+
chunks = (blocks + (1 << bitmap->chunkshift) - 1) >>
17321731
bitmap->chunkshift;
17331732
pages = (chunks + PAGE_COUNTER_RATIO - 1) / PAGE_COUNTER_RATIO;
17341733

drivers/md/bitmap.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ typedef __u16 bitmap_counter_t;
101101

102102
#define BITMAP_BLOCK_SHIFT 9
103103

104-
/* how many blocks per chunk? (this is variable) */
105-
#define CHUNK_BLOCK_RATIO(bitmap) ((bitmap)->mddev->bitmap_info.chunksize >> BITMAP_BLOCK_SHIFT)
106-
107104
#endif
108105

109106
/*

0 commit comments

Comments
 (0)