Re: [PATCH 4.14 015/159] bitops: Add clear/set_bit32() to linux/bitops.h

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2017-12-22 at 09:45 +0100, Greg Kroah-Hartman wrote:
> 4.14-stable review patch.  If anyone has any objections, please let me know.
> 
> ------------------
> 
> From: Andi Kleen <ak@xxxxxxxxxxxxxxx>
> 
> commit cbe96375025e14fc76f9ed42ee5225120d7210f8 upstream.
> 
> Add two simple wrappers around set_bit/clear_bit() that accept
> the common case of an u32 array. This avoids writing
> casts in all callers.

These won't work correctly on big-endian 64-bit systems.  They are also
unsafe to use on u32 arrays with an odd length, on 64-bit systems.
This is why lib/bitmap.c has conversion functions for u32 arrays.

Ben.

> Signed-off-by: Andi Kleen <ak@xxxxxxxxxxxxxxx>
> Reviewed-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Link: http://lkml.kernel.org/r/20171013215645.23166-2-andi@xxxxxxxxxxxxxx
> Signed-off-by: Ingo Molnar <mingo@xxxxxxxxxx>
> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> 
> ---
>  include/linux/bitops.h |   26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 
> --- a/include/linux/bitops.h
> +++ b/include/linux/bitops.h
> @@ -228,6 +228,32 @@ static inline unsigned long __ffs64(u64
>  	return __ffs((unsigned long)word);
>  }
>  
> +/*
> + * clear_bit32 - Clear a bit in memory for u32 array
> + * @nr: Bit to clear
> + * @addr: u32 * address of bitmap
> + *
> + * Same as clear_bit, but avoids needing casts for u32 arrays.
> + */
> +
> +static __always_inline void clear_bit32(long nr, volatile u32 *addr)
> +{
> +	clear_bit(nr, (volatile unsigned long *)addr);
> +}
> +
> +/*
> + * set_bit32 - Set a bit in memory for u32 array
> + * @nr: Bit to clear
> + * @addr: u32 * address of bitmap
> + *
> + * Same as set_bit, but avoids needing casts for u32 arrays.
> + */
> +
> +static __always_inline void set_bit32(long nr, volatile u32 *addr)
> +{
> +	set_bit(nr, (volatile unsigned long *)addr);
> +}
> +
>  #ifdef __KERNEL__
>  
>  #ifndef set_mask_bits
> 
> 
-- 
Ben Hutchings
The world is coming to an end.	Please log off.

Attachment: signature.asc
Description: This is a digitally signed message part


[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]