]> git.neil.brown.name Git - LaFS.git/commitdiff
lafs_space_alloc - avoid underflow of unsigned numbers
authorNeilBrown <neilb@suse.de>
Wed, 23 Jun 2010 01:52:00 +0000 (11:52 +1000)
committerNeilBrown <neilb@suse.de>
Wed, 23 Jun 2010 02:49:04 +0000 (12:49 +1000)
As the numbers in the calc are unsigned, use only additions
to avoid anything going negative.

Signed-off-by: NeilBrown <neilb@suse.de>
segments.c

index 4e2ae3a3c9cb1f069251f60bd3058d2528b82f2c..ffed5c426864aa9ea779ea278ae6aaff3d33f422 100644 (file)
@@ -615,8 +615,8 @@ int lafs_space_alloc(struct fs *fs, int credits, int why)
                                   * EAGAIN, so never return it
                                   */
                if (fs->rolled) {
-                       if (fs->free_blocks - fs->allocated_blocks
-                           - credits < watermark)
+                       if (fs->free_blocks < fs->allocated_blocks
+                           + credits + watermark)
                                credits = 0; /* Sorry, no room */
                }
        }