lib: sbi_scratch: use bitwise ops in sbi_scratch_alloc_offset()
authorLi Jinpei <leekingp1994@163.com>
Tue, 11 Feb 2020 09:57:49 +0000 (15:27 +0530)
committerAnup Patel <anup@brainfault.org>
Thu, 13 Feb 2020 03:40:55 +0000 (09:10 +0530)
Instead of using loop to make "size" machine word aligned, we should
use bitwise ops.

Signed-off-by: Li Jinpei <leekingp1994@163.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
lib/sbi/sbi_scratch.c

index 95ee2f2..26716c5 100644 (file)
@@ -36,8 +36,8 @@ unsigned long sbi_scratch_alloc_offset(unsigned long size, const char *owner)
        if (!size)
                return 0;
 
-       while (size & (__SIZEOF_POINTER__ - 1))
-               size++;
+       if (size & (__SIZEOF_POINTER__ - 1))
+               size = (size & ~(__SIZEOF_POINTER__ - 1)) + __SIZEOF_POINTER__;
 
        spin_lock(&extra_lock);