Message ID | 20230309094607.72318-1-wxjstz@126.com |
---|---|
State | Superseded |
Headers | show |
Series | lib: sbi_scratch: Optimize the alignment code for alloc size | expand |
On Mär 09 2023, Xiang W wrote:
> + size = (size + __SIZEOF_POINTER__ - 1) & ~(__SIZEOF_POINTER__ - 1);
It is probably more robust to convert (__SIZEOF_POINTER__ - 1) to
unsigned long before inverting. This currently depends on the fact that
~(__SIZEOF_POINTER__ - 1) is a signed int, and thus sign extended, to
work correctly.
diff --git a/lib/sbi/sbi_scratch.c b/lib/sbi/sbi_scratch.c index 87b34c6..ea62105 100644 --- a/lib/sbi/sbi_scratch.c +++ b/lib/sbi/sbi_scratch.c @@ -59,8 +59,7 @@ unsigned long sbi_scratch_alloc_offset(unsigned long size) if (!size) return 0; - if (size & (__SIZEOF_POINTER__ - 1)) - size = (size & ~(__SIZEOF_POINTER__ - 1)) + __SIZEOF_POINTER__; + size = (size + __SIZEOF_POINTER__ - 1) & ~(__SIZEOF_POINTER__ - 1); spin_lock(&extra_lock);
Signed-off-by: Xiang W <wxjstz@126.com> --- lib/sbi/sbi_scratch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)