]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
ucounts: Use atomic_long_sub_return for clarity
authorEric W. Biederman <ebiederm@xmission.com>
Mon, 18 Oct 2021 16:22:20 +0000 (11:22 -0500)
committerEric W. Biederman <ebiederm@xmission.com>
Wed, 20 Oct 2021 15:45:34 +0000 (10:45 -0500)
Decrement ucounts using atomic_long_sub_return to make it
clear the point is for the ucount to decrease.

Not a big deal but it should make it easier to catch bugs.

Suggested-by: Yu Zhao <yuzhao@google.com>
Link: https://lkml.kernel.org/r/87k0iaqkqj.fsf_-_@disp2133
Tested-by: Yu Zhao <yuzhao@google.com>
Reviewed-by: Alexey Gladkov <legion@kernel.org>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
kernel/ucount.c

index 133b6044fda4e212609f32167d0efb5b88cd0359..4f5613dac2273a1b96feb809e2a5f1449932769b 100644 (file)
@@ -282,7 +282,7 @@ bool dec_rlimit_ucounts(struct ucounts *ucounts, enum ucount_type type, long v)
        struct ucounts *iter;
        long new = -1; /* Silence compiler warning */
        for (iter = ucounts; iter; iter = iter->ns->ucounts) {
-               long dec = atomic_long_add_return(-v, &iter->ucount[type]);
+               long dec = atomic_long_sub_return(v, &iter->ucount[type]);
                WARN_ON_ONCE(dec < 0);
                if (iter == ucounts)
                        new = dec;
@@ -295,7 +295,7 @@ static void do_dec_rlimit_put_ucounts(struct ucounts *ucounts,
 {
        struct ucounts *iter, *next;
        for (iter = ucounts; iter != last; iter = next) {
-               long dec = atomic_long_add_return(-1, &iter->ucount[type]);
+               long dec = atomic_long_sub_return(1, &iter->ucount[type]);
                WARN_ON_ONCE(dec < 0);
                next = iter->ns->ucounts;
                if (dec == 0)
@@ -332,7 +332,7 @@ long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum ucount_type type)
        }
        return ret;
 dec_unwind:
-       dec = atomic_long_add_return(-1, &iter->ucount[type]);
+       dec = atomic_long_sub_return(1, &iter->ucount[type]);
        WARN_ON_ONCE(dec < 0);
 unwind:
        do_dec_rlimit_put_ucounts(ucounts, iter, type);