0065-bitops-Add-clear-set_bit32-to-linux-bitops.h.patch 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. From 2f76ec868c18486b60f1b76428339a2fa0c2e5d8 Mon Sep 17 00:00:00 2001
  2. From: Andi Kleen <[email protected]>
  3. Date: Fri, 13 Oct 2017 14:56:41 -0700
  4. Subject: [PATCH 065/232] bitops: Add clear/set_bit32() to linux/bitops.h
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. Add two simple wrappers around set_bit/clear_bit() that accept
  10. the common case of an u32 array. This avoids writing
  11. casts in all callers.
  12. Signed-off-by: Andi Kleen <[email protected]>
  13. Reviewed-by: Thomas Gleixner <[email protected]>
  14. Cc: Linus Torvalds <[email protected]>
  15. Cc: Peter Zijlstra <[email protected]>
  16. Link: http://lkml.kernel.org/r/[email protected]
  17. Signed-off-by: Ingo Molnar <[email protected]>
  18. (cherry picked from commit cbe96375025e14fc76f9ed42ee5225120d7210f8)
  19. Signed-off-by: Andy Whitcroft <[email protected]>
  20. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  21. (cherry picked from commit 06d31c11519ca0e8f9b7cab857f442ef44dfc1b2)
  22. Signed-off-by: Fabian Grünbichler <[email protected]>
  23. ---
  24. include/linux/bitops.h | 26 ++++++++++++++++++++++++++
  25. 1 file changed, 26 insertions(+)
  26. diff --git a/include/linux/bitops.h b/include/linux/bitops.h
  27. index a83c822c35c2..eb257a96db6d 100644
  28. --- a/include/linux/bitops.h
  29. +++ b/include/linux/bitops.h
  30. @@ -226,6 +226,32 @@ static inline unsigned long __ffs64(u64 word)
  31. return __ffs((unsigned long)word);
  32. }
  33. +/*
  34. + * clear_bit32 - Clear a bit in memory for u32 array
  35. + * @nr: Bit to clear
  36. + * @addr: u32 * address of bitmap
  37. + *
  38. + * Same as clear_bit, but avoids needing casts for u32 arrays.
  39. + */
  40. +
  41. +static __always_inline void clear_bit32(long nr, volatile u32 *addr)
  42. +{
  43. + clear_bit(nr, (volatile unsigned long *)addr);
  44. +}
  45. +
  46. +/*
  47. + * set_bit32 - Set a bit in memory for u32 array
  48. + * @nr: Bit to clear
  49. + * @addr: u32 * address of bitmap
  50. + *
  51. + * Same as set_bit, but avoids needing casts for u32 arrays.
  52. + */
  53. +
  54. +static __always_inline void set_bit32(long nr, volatile u32 *addr)
  55. +{
  56. + set_bit(nr, (volatile unsigned long *)addr);
  57. +}
  58. +
  59. #ifdef __KERNEL__
  60. #ifndef set_mask_bits
  61. --
  62. 2.14.2