[lkml]   [2018]   [Oct]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRE: [PATCH] RDMA/cxgb3: Fix unintended sign extension
From: Colin King
> Sent: 25 October 2018 15:32
> From: Colin Ian King <>
> In the expression "utx_len << 28", utx_len starts as u8, but is promoted
> to a signed int, then sign-extended to u64. If utx_len is 0xf8 or greater
> then the sign extension will set all the upper bits of utx_cmd which is
> probably not what was intended. Cast to utx_len to u64 to avoid the sign
> extension.

utx_len is only ever 1, 2 or 3.
The 'problem' would arise if utx_len << 28 set the high bit.
This can only happen if utx_len is more than 7 (NFI where 0xf8 came from).

In any case the best fix is to use 'unsigned int' for wr_len and utx_len.
There is no point making local variable (or functions parameters/results)
smaller that 'int' unless you explicitly want the arithmetic to wrap.


Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
 \ /
  Last update: 2018-10-25 18:04    [W:0.039 / U:9.688 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site