Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=3cb4f9fa0c5f3ded9f70f85b70ee6d429834f911
Commit:     3cb4f9fa0c5f3ded9f70f85b70ee6d429834f911
Parent:     aa0dff2d09bfa50b7d02714a45920c64568e699d
Author:     Peter Zijlstra <[EMAIL PROTECTED]>
AuthorDate: Tue Oct 16 23:25:42 2007 -0700
Committer:  Linus Torvalds <[EMAIL PROTECTED]>
CommitDate: Wed Oct 17 08:42:44 2007 -0700

    lib: percpu_counter_sub
    
    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 <[EMAIL PROTECTED]>
    Cc: Hugh Dickins <[EMAIL PROTECTED]>
    Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
    Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>
---
 fs/ext2/balloc.c               |    2 +-
 fs/ext3/balloc.c               |    2 +-
 fs/ext4/balloc.c               |    2 +-
 include/linux/percpu_counter.h |    5 +++++
 4 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
index 53be251..9157fcf 100644
--- a/fs/ext2/balloc.c
+++ b/fs/ext2/balloc.c
@@ -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;
 }
diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
index df57567..d3758ee 100644
--- a/fs/ext3/balloc.c
+++ b/fs/ext3/balloc.c
@@ -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);
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index a141456..8d59eec 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -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);
diff --git a/include/linux/percpu_counter.h b/include/linux/percpu_counter.h
index b84fc86..438a170 100644
--- a/include/linux/percpu_counter.h
+++ b/include/linux/percpu_counter.h
@@ -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 */
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to