lkml.org 
[lkml]   [2018]   [Jun]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH v2] kvm: x86: mmu: Add cast to negated bitmasks in update_permission_bitmask()
On Mon, Jun 25, 2018 at 12:05 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 19/06/2018 21:25, Matthias Kaehlcke wrote:
> > update_permission_bitmask() negates u8 bitmask values and assigns them
> > to variables of type u8. Since the MSB is set in the bitmask values the
> > compiler expands the negated values to int, which then is assigned to
> > an u8 variable. Cast the negated value back to u8.
> >
> > This fixes several warnings like this when building with clang:
> >
> > arch/x86/kvm/mmu.c:4266:39: error: implicit conversion from 'int' to 'u8'
> > (aka 'unsigned char') changes value from -205 to 51 [-Werror,
> > -Wconstant-conversion]
> > u8 wf = (pfec & PFERR_WRITE_MASK) ? ~w : 0;
> > ~~ ^~
> >
> > (gcc also raises a warning (see https://godbolt.org/g/6JWfWk), however it
> > doesn't seem to be universally enabled)
> >
> > Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
> > Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> > ---
> > Changes in v2:
> > - negate the bitmask at initialization and rename variables to not_X
>
> The patch is not that bad, but I'd like to get confirmation that other
> maintainers are applying fixes like this. Honestly I'm not really
> impressed by most new clang warnings, these days.

Here's an actual bug this warning caught applied to drivers/input/:

dae1a432ab1f ("Input: mousedev - fix implicit conversion warning"):
https://patchwork.kernel.org/patch/9753771/

\
 
 \ /
  Last update: 2018-06-25 18:48    [W:0.078 / U:0.344 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site