lkml.org 
[lkml]   [2018]   [Feb]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH][V2] rtc: tx4939: avoid unintended sign extension on a 24 bit shift
On 15/02/2018 at 21:44:53 +0100, Alexandre Belloni wrote:
> On 15/02/2018 at 19:36:14 +0000, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> >
> > The shifting of buf[5] by 24 bits to the left will be promoted to
> > a 32 bit signed int and then sign-extended to an unsigned long. If
> > the top bit of buf[5] is set then all then all the upper bits sec
> > end up as also being set because of the sign-extension. Fix this by
> > casting buf[5] to an unsigned long before the shift.
> >
>
> The timing of the discovery of this issue is suspicious. I believe it is
> because I just enabled COMPILE_TEST on that driver and now this gets
> compiled on a 64bit architecture.
>
> Can I ask on which architecture this is an issue? I don't think (and a
> small test program confirms) x86 does the sign extension because both
> sec and buf are unsigned.
>

Actually, my test program was wrong and you are right.

--
Alexandre Belloni, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
http://bootlin.com

\
 
 \ /
  Last update: 2018-02-16 16:25    [W:0.114 / U:1.192 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site