]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
lib: percpu_counter_sub
authorPeter Zijlstra <a.p.zijlstra@chello.nl>
Wed, 17 Oct 2007 06:25:42 +0000 (23:25 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Wed, 17 Oct 2007 15:42:44 +0000 (08:42 -0700)
Hugh spotted that some code does:
  percpu_counter_add(&counter, -unsignedlong)

which, when the amount argument is of type s32, sort-of works thanks to
two's-complement. However when we'd change the type to s64 this breaks on 32bit
machines, because the promotion rules zero extend the unsigned number.

Provide percpu_counter_sub() to hide the s64 cast. That is:
  percpu_counter_sub(&counter, foo)
is equal to:
  percpu_counter_add(&counter, -(s64)foo);

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/ext2/balloc.c
fs/ext3/balloc.c
fs/ext4/balloc.c
include/linux/percpu_counter.h

index 53be251585603067c515f14bef2109b4ca34b64a..9157fcf887bc0c2b782a97396f824f8055caf8e7 100644 (file)
@@ -124,7 +124,7 @@ static int reserve_blocks(struct super_block *sb, int count)
                        return 0;
        }
 
-       percpu_counter_add(&sbi->s_freeblocks_counter, -count);
+       percpu_counter_sub(&sbi->s_freeblocks_counter, count);
        sb->s_dirt = 1;
        return count;
 }
index df575673e02d9718d13aa49e74040b3c0affc17e..d3758ee9cb5bde3e8c6ee8c1b154efa48e3e9443 100644 (file)
@@ -1633,7 +1633,7 @@ allocated:
        gdp->bg_free_blocks_count =
                        cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count)-num);
        spin_unlock(sb_bgl_lock(sbi, group_no));
-       percpu_counter_add(&sbi->s_freeblocks_counter, -num);
+       percpu_counter_sub(&sbi->s_freeblocks_counter, num);
 
        BUFFER_TRACE(gdp_bh, "journal_dirty_metadata for group descriptor");
        err = ext3_journal_dirty_metadata(handle, gdp_bh);
index a141456cd4919ec17cb81ff625b452f28ea10357..8d59eec2e82b55e98cd3e82845378fb34bd5ddba 100644 (file)
@@ -1647,7 +1647,7 @@ allocated:
        gdp->bg_free_blocks_count =
                        cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count)-num);
        spin_unlock(sb_bgl_lock(sbi, group_no));
-       percpu_counter_add(&sbi->s_freeblocks_counter, -num);
+       percpu_counter_sub(&sbi->s_freeblocks_counter, num);
 
        BUFFER_TRACE(gdp_bh, "journal_dirty_metadata for group descriptor");
        err = ext4_journal_dirty_metadata(handle, gdp_bh);
index b84fc8667de86cb5299d4f1466ee30aaf7ed9a6c..438a170187ec6026342f8d67173d22018b6f3f03 100644 (file)
@@ -105,4 +105,9 @@ static inline void percpu_counter_dec(struct percpu_counter *fbc)
        percpu_counter_add(fbc, -1);
 }
 
+static inline void percpu_counter_sub(struct percpu_counter *fbc, s64 amount)
+{
+       percpu_counter_add(fbc, -amount);
+}
+
 #endif /* _LINUX_PERCPU_COUNTER_H */