On 25/06/2018 19:35, Matthias Kaehlcke wrote:
> commit e2a5dca753d1cdc3212519023ed8a13e13f5495b
> Author: Borislav Petkov <[email protected]>
> Date:   Thu Nov 23 10:19:51 2017 +0100
> 
>     x86/umip: Fix insn_get_code_seg_params()'s return value

So this is the closest thing to a bug (it could have been a real bug
if the caller checked ret < 0 instead of ret == -EINVAL).  *However*
the warning there is a bit misleading too.

The compiler does absolutely nothing to tell you that the return value
is in the [-EINVAL,132] range and therefore it should have been int.
_That_ would have been a useful warning.  Instead, it says:

      arch/x86/lib/insn-eval.c:780:10: warning: implicit conversion from 'int' 
to 'char'
              changes value from 132 to -124 [-Wconstant-conversion]
                      return INSN_CODE_SEG_PARAMS(4, 8);
                      ~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~
      ./arch/x86/include/asm/insn-eval.h:16:57: note: expanded from macro 
'INSN_CODE_SEG_PARAMS'
      #define INSN_CODE_SEG_PARAMS(oper_sz, addr_sz) (oper_sz | (addr_sz << 4))
    
If you changed the return value from char to u8, you'd break the "return
-EINVAL;" case.  The compiler would probably complain in turn that this
is not the right fix, by signaling a warning on "return -EINVAL;", but the
warning could really be done better.

Thanks,

Paolo

Reply via email to