Re: [PATCH] scsi: Remove negative constant left-shifts

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

 



On 2/21/19 4:20 PM, Iustin Pop wrote:
> Negative constant left-shift is undefined behaviour in the C standard,
> and as such newer versions of clang (at least) warn against it. GCC
> supports it for a long time, but it would be better to remove it and
> rely on defined behaviour.
> 
> My understanding is "~(-1 << N)" in 2's complement is intended to
> generate a bit pattern of zeroes ending with N '1' bits. The same can
> be achieved by "(1 << N) - 1" in a well-defined way, so switch to it
> to remove the warning.
> 
> Tested: building a kernel with generic SCSI tape, and checking basic
> operations (mt status, mt eject) on a real LTO unit. Cannot test
> the osst driver.
> 
> Signed-off-by: Iustin Pop <iustin@xxxxxxxxx>
> ---
>  (with apologies if I made mistakes in the CC list)
>  drivers/scsi/osst.c | 2 +-
>  drivers/scsi/st.c   | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c
> index 664c1238a87f..be3c73ebbfde 100644
> --- a/drivers/scsi/osst.c
> +++ b/drivers/scsi/osst.c
> @@ -139,7 +139,7 @@ static int debugging = 1;
>  #define OSST_TIMEOUT (200 * HZ)
>  #define OSST_LONG_TIMEOUT (1800 * HZ)
>  
> -#define TAPE_NR(x) (iminor(x) & ~(-1 << ST_MODE_SHIFT))
> +#define TAPE_NR(x) (iminor(x) & ((1 << ST_MODE_SHIFT)-1))
>  #define TAPE_MODE(x) ((iminor(x) & ST_MODE_MASK) >> ST_MODE_SHIFT)
>  #define TAPE_REWIND(x) ((iminor(x) & 0x80) == 0)
>  #define TAPE_IS_RAW(x) (TAPE_MODE(x) & (ST_NBR_MODES >> 1))
> diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
> index 7ff22d3f03e3..eca84caed6ff 100644
> --- a/drivers/scsi/st.c
> +++ b/drivers/scsi/st.c
> @@ -169,7 +169,7 @@ static int debugging = DEBUG;
>  
>  /* Remove mode bits and auto-rewind bit (7) */
>  #define TAPE_NR(x) ( ((iminor(x) & ~255) >> (ST_NBR_MODE_BITS + 1)) | \
> -    (iminor(x) & ~(-1 << ST_MODE_SHIFT)) )
> +	(iminor(x) & ((1 << ST_MODE_SHIFT)-1)))
>  #define TAPE_MODE(x) ((iminor(x) & ST_MODE_MASK) >> ST_MODE_SHIFT)
>  
>  /* Construct the minor number from the device (d), mode (m), and non-rewind (n) data */
> 

Reviewed-by: Lee Duncan <lduncan@xxxxxxxx>



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux