From: Yu Watanabe Date: Sun, 4 Sep 2022 09:54:52 +0000 (+0900) Subject: repart: do not assign new size larger than acquired or the specified maximum X-Git-Tag: v252-rc1~222^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d7c46b5e1e6c606f765198cf6a21f6dd997c6f2a;p=thirdparty%2Fsystemd.git repart: do not assign new size larger than acquired or the specified maximum The acquired size may be larger than the requested maximum. So, let's cap the value. Note, at the final phase, the acquired size should be larger than the requested minimum. Hence, the assertion about that is added. --- diff --git a/src/partition/repart.c b/src/partition/repart.c index 368c2cd2892..48575799775 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -796,7 +796,8 @@ static bool context_grow_partitions_phase( * assigning this shouldn't impact the shares of the other * partitions. */ - p->new_size = MAX(round_down_size(share, context->grain_size), rsz); + assert(share >= rsz); + p->new_size = CLAMP(round_down_size(share, context->grain_size), rsz, xsz); charge = true; } @@ -822,7 +823,8 @@ static bool context_grow_partitions_phase( p->new_padding = xsz; charge = try_again = true; } else if (phase == PHASE_DISTRIBUTE) { - p->new_padding = MAX(round_down_size(share, context->grain_size), rsz); + assert(share >= rsz); + p->new_padding = CLAMP(round_down_size(share, context->grain_size), rsz, xsz); charge = true; }