bitops: Move aligned_byte_mask() to wordpart.h
PATCH 1/1 bitops: Move aligned_byte_mask() to wordpart.h
The bitops.h is for bit related operations. The aligned_byte_mask() is about byte (or part of the machine word) operations, for which we have a separate header, move the mentioned macro to wordpart.h to consolidate similar operations.
--- include/linux/bitops.h | 7 ------- include/linux/wordpart.h | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-)
include/linux/bitops.h +0 -7
@@ -8,13 +8,6 @@#include <uapi/linux/kernel.h> -/* Set bits in the first 'n' bytes when loaded from memory */ -#ifdef __LITTLE_ENDIAN -# define aligned_byte_mask (n) ((1UL << 8*(n))-1) -#else -# define aligned_byte_mask (n) (~0xffUL << (BITS_PER_LONG - 8 - 8*(n))) -#endif -#define BITS_PER_TYPE (type) (sizeof(type) * BITS_PER_BYTE)#define BITS_TO_LONGS (nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(long))#define BITS_TO_U64 (nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(u64))
include/linux/wordpart.h +7 -0
@@ -39,4 +39,11 @@*/ #define REPEAT_BYTE (x) ((~0ul / 0xff) * (x)) +/* Set bits in the first 'n' bytes when loaded from memory */ +#ifdef __LITTLE_ENDIAN +# define aligned_byte_mask (n) ((1UL << 8*(n))-1) +#else +# define aligned_byte_mask (n) (~0xffUL << (BITS_PER_LONG - 8 - 8*(n))) +#endif +#endif // _LINUX_WORDPART_H
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Yury Norov
maintainerQuoted 6 lines · Andy Shevchenko
The
bitops.his for bit related operations. Thealigned_byte_mask()is about byte (or part of the machine word) operations, for which we have a separate header, move the mentioned macro towordpart.hto consolidate similar operations.Signed-off-by Andy Shevchenko <[email protected]>
Hi Andy,
I see the macro is used in lib/strnlen_user.c and in lib/usercopy.c. In case of strnlen_user, the wordpart.h is included via linux/kernel.h, which is OK to me. But In case of usercopy.c, I can't find how the header is included.
I'm sure there is some inclusion path, but it's always better to have the dependencies listed explicitly.
Can you please send a 2nd version with the lib/usercopy.c including wordpart.h?
Thanks,
Yury
Quoted 41 lines
--- include/linux/bitops.h | 7 ------- include/linux/wordpart.h | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-)include/linux/bitops.h +0
-7@@ -8,13 +8,6 @@#include <uapi/linux/kernel.h> -/* Set bits in the first 'n' bytes when loaded from memory */ -#ifdef __LITTLE_ENDIAN -# define aligned_byte_mask (n) ((1UL << 8*(n))-1) -#else -# define aligned_byte_mask (n) (~0xffUL << (BITS_PER_LONG - 8 - 8*(n))) -#endif -#define BITS_PER_TYPE (type) (sizeof(type) * BITS_PER_BYTE)#define BITS_TO_LONGS (nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(long))#define BITS_TO_U64 (nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(u64))include/linux/wordpart.h +7
-0@@ -39,4 +39,11 @@*/ #define REPEAT_BYTE (x) ((~0ul / 0xff) * (x)) +/* Set bits in the first 'n' bytes when loaded from memory */ +#ifdef __LITTLE_ENDIAN +# define aligned_byte_mask (n) ((1UL << 8*(n))-1) +#else +# define aligned_byte_mask (n) (~0xffUL << (BITS_PER_LONG - 8 - 8*(n))) +#endif +#endif // _LINUX_WORDPART_H Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Quoted 15 lines · Yury Norov
Quoted 6 lines · Andy Shevchenko
The
bitops.his for bit related operations. Thealigned_byte_mask()is about byte (or part of the machine word) operations, for which we have a separate header, move the mentioned macro towordpart.hto consolidate similar operations.Signed-off-by Andy Shevchenko <[email protected]>Hi Andy,
I see the macro is used in
lib/strnlen_user.cand inlib/usercopy.c. In case ofstrnlen_user, thewordpart.his included vialinux/kernel.h, which is OK to me. But In case ofusercopy.c, I can't find how the header is included.
Quoted 5 lines
I'm sure there is some inclusion path, but it's always better to have the dependencies listed explicitly.
Can you please send a 2nd version with the
lib/usercopy.cincludingwordpart.h?
I think it's unrelated right now. The inclusions in usercopy is a mess. It should be cleaned up in a separate patch for all inclusions.
But okay, making slightly more mess there won't harm :-)
Signature · 2 lines
With Best Regards, Andy Shevchenko