diff options
Diffstat (limited to 'fs/ntfs/runlist.c')
-rw-r--r-- | fs/ntfs/runlist.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/fs/ntfs/runlist.c b/fs/ntfs/runlist.c index 061b5ff6b73c..eb52b801512b 100644 --- a/fs/ntfs/runlist.c +++ b/fs/ntfs/runlist.c | |||
@@ -381,6 +381,7 @@ static inline runlist_element *ntfs_rl_insert(runlist_element *dst, | |||
381 | static inline runlist_element *ntfs_rl_replace(runlist_element *dst, | 381 | static inline runlist_element *ntfs_rl_replace(runlist_element *dst, |
382 | int dsize, runlist_element *src, int ssize, int loc) | 382 | int dsize, runlist_element *src, int ssize, int loc) |
383 | { | 383 | { |
384 | signed delta; | ||
384 | BOOL left = FALSE; /* Left end of @src needs merging. */ | 385 | BOOL left = FALSE; /* Left end of @src needs merging. */ |
385 | BOOL right = FALSE; /* Right end of @src needs merging. */ | 386 | BOOL right = FALSE; /* Right end of @src needs merging. */ |
386 | int tail; /* Start of tail of @dst. */ | 387 | int tail; /* Start of tail of @dst. */ |
@@ -396,11 +397,14 @@ static inline runlist_element *ntfs_rl_replace(runlist_element *dst, | |||
396 | left = ntfs_are_rl_mergeable(dst + loc - 1, src); | 397 | left = ntfs_are_rl_mergeable(dst + loc - 1, src); |
397 | /* | 398 | /* |
398 | * Allocate some space. We will need less if the left, right, or both | 399 | * Allocate some space. We will need less if the left, right, or both |
399 | * ends get merged. | 400 | * ends get merged. The -1 accounts for the run being replaced. |
400 | */ | 401 | */ |
401 | dst = ntfs_rl_realloc(dst, dsize, dsize + ssize - left - right); | 402 | delta = ssize - 1 - left - right; |
402 | if (IS_ERR(dst)) | 403 | if (delta > 0) { |
403 | return dst; | 404 | dst = ntfs_rl_realloc(dst, dsize, dsize + delta); |
405 | if (IS_ERR(dst)) | ||
406 | return dst; | ||
407 | } | ||
404 | /* | 408 | /* |
405 | * We are guaranteed to succeed from here so can start modifying the | 409 | * We are guaranteed to succeed from here so can start modifying the |
406 | * original runlists. | 410 | * original runlists. |