Re: [PATCH] net: sxgbe: fix unintended sign extension

From: David Miller
Date: Wed Feb 06 2019 - 14:52:46 EST


From: Colin King <colin.king@xxxxxxxxxxxxx>
Date: Wed, 6 Feb 2019 10:25:03 +0000

> From: Colin Ian King <colin.king@xxxxxxxxxxxxx>
>
> Shifting a u8 by 24 will cause the value to be promoted to an integer. If
> the top bit of the u8 is set then the following conversion to an unsigned
> long will sign extend the value causing the upper 32 bits to be set in
> the result.

We feed this into a writel() which truncates to a 32-bit value, so nothing
bad can happen here.

This is a very canonical way to code up something like this, it works
properly in all situations, and therefore I'd rather not add all of
these fat ugly looking casts.

Thank you.