md: raid5: avoid sector values going negative when testing reshape progress.
authorNeilBrown <neilb@suse.de>
Tue, 26 May 2009 02:41:08 +0000 (12:41 +1000)
committerNeilBrown <neilb@suse.de>
Tue, 26 May 2009 02:41:08 +0000 (12:41 +1000)
As sector_t in unsigned, we cannot afford to let 'safepos' etc go
negative.
So replace
   a -= b;
by
   a -= min(b,a);

Signed-off-by: NeilBrown <neilb@suse.de>
drivers/md/raid5.c

index 4616bc3a6e713065e689943db4cdde421076d318..3c3626d2a1f9fe7a616bf84626a39593a56c2f84 100644 (file)
@@ -3811,13 +3811,13 @@ static sector_t reshape_request(mddev_t *mddev, sector_t sector_nr, int *skipped
        safepos = conf->reshape_safe;
        sector_div(safepos, data_disks);
        if (mddev->delta_disks < 0) {
-               writepos -= reshape_sectors;
+               writepos -= min(reshape_sectors, writepos);
                readpos += reshape_sectors;
                safepos += reshape_sectors;
        } else {
                writepos += reshape_sectors;
-               readpos -= reshape_sectors;
-               safepos -= reshape_sectors;
+               readpos -= min(reshape_sectors, readpos);
+               safepos -= min(reshape_sectors, safepos);
        }
 
        /* 'writepos' is the most advanced device address we might write.