lib: sbi_scratch: Optimize the alignment code for alloc size
PATCH 1/1 lib: sbi_scratch: Optimize the alignment code for alloc size
Signed-off-by Xiang W <[email protected]>
--- lib/sbi/sbi_scratch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
lib/sbi/sbi_scratch.c +1 -2
@@ -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);
Signature · 1 line
2.39.2
PATCH 1/1 lib: sbi_scratch: Optimize the alignment code for alloc size
lib/sbi/sbi_scratch.c unsigned long sbi_scratch_alloc_offset(unsigned long size) · line 62
Quoted 1 line · Xiang W
lib/sbi/sbi_scratch.c +1
-0+ 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.
Signature · 3 lines
Andreas Schwab, SUSE Labs, schwab at suse.de GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different."