Skip to content

Commit

Permalink
bitops: Move aligned_byte_mask() to wordpart.h
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Yury Norov <yury.norov@gmail.com>
  • Loading branch information
Andy Shevchenko authored and Yury Norov committed May 19, 2024
1 parent fe708f9 commit 9f2c2d6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 0 additions & 7 deletions include/linux/bitops.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions include/linux/wordpart.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions lib/usercopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <linux/fault-inject-usercopy.h>
#include <linux/instrumented.h>
#include <linux/uaccess.h>
#include <linux/wordpart.h>
#include <linux/nospec.h>

/* out-of-line parts */
Expand Down

0 comments on commit 9f2c2d6

Please sign in to comment.