[PATCH 3/3] md/raid0: round member size in raid0_size() with sector_div()

From: Zizhi Wo

Date: Fri Oct 16 2026 - 21:05:29 EST


From: Zizhi Wo <wozizhi@xxxxxxxxxx>

raid0_size() rounds each member device down to the chunk boundary by
masking with 'chunk_sectors - 1':

rdev->sectors & ~(sector_t)(mddev->chunk_sectors - 1)

This bit-masking only yields a correct round-down when chunk_sectors is a
power of 2. However, raid0 also supports non-power-of-2 chunk sizes, as
handled in raid0_make_request() and map_sector(), so the rounding is wrong
in that case.

Use raid0_member_sectors() instead, so that each member is rounded down
with sector_div() for any chunk size, consistent with how
create_strip_zones() already rounds the members when building the zones.

Signed-off-by: Zizhi Wo <wozizhi@xxxxxxxxxx>
---
drivers/md/raid0.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index c96ee54f9acc..623b0701ce70 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -367,12 +367,12 @@ static sector_t raid0_size(struct mddev *mddev, sector_t sectors, int raid_disks

WARN_ONCE(sectors || raid_disks,
"%s does not support generic reshape\n", __func__);

rdev_for_each(rdev, mddev)
- array_sectors += (rdev->sectors &
- ~(sector_t)(mddev->chunk_sectors-1));
+ array_sectors += raid0_member_sectors(rdev->sectors,
+ mddev->chunk_sectors);

return array_sectors;
}

static void raid0_free(struct mddev *mddev, void *priv)
--
2.52.0