Re: [PATCH] kvm: x86: mmu: Add cast to negated bitmasks in update_permission_bitmask()

From: Matthias Kaehlcke
Date: Tue Jun 19 2018 - 21:36:33 EST


On Tue, Jun 19, 2018 at 05:18:02PM -0700, Joe Perches wrote:
> On Tue, 2018-06-19 at 16:45 -0700, Matthias Kaehlcke wrote:
> > On Tue, Jun 19, 2018 at 02:55:05PM -0700, Joe Perches wrote:
> > > Well, you advocate to disable a possibly useful warning globally ...
> > > You're advocating for making the code more complex/ugly for a
> > > condition where the result is identical.
> > My goal is no to make the code (slightly) more complex/ugly but have
> > the rest of the kernel benefit from a possibly useful warning.
>
> For what case in the kernel is this warning useful?

It's less about finding errors that are currently in the kernel (I
don't know if there are any) and more about preventing new ones from
creeping in.

Code similar to the example from the link shared by Nick could easily
be part of some kernel driver:

https://wiki.sei.cmu.edu/confluence/display/c/EXP14-C.+Beware+of+integer+promotion+when+performing+bitwise+operations+on+integer+types+smaller+than+int