• Rasmus Villemoes's avatar
    soc: fsl: qe: change return type of cpm_muram_alloc() to s32 · 800cd6fb
    Rasmus Villemoes authored
    There are a number of problems with cpm_muram_alloc() and its
    callers. Most callers assign the return value to some variable and
    then use IS_ERR_VALUE to check for allocation failure. However, when
    that variable is not sizeof(long), this leads to warnings - and it is
    indeed broken to do e.g.
    
      u32 foo = cpm_muram_alloc();
      if (IS_ERR_VALUE(foo))
    
    on a 64-bit platform, since the condition
    
      foo >= (unsigned long)-ENOMEM
    
    is tautologically false. There are also callers that ignore the
    possibility of error, and then there are those that check for error by
    comparing the return value to 0...
    
    One could fix that by changing all callers to store the return value
    temporarily in an "unsigned long" and test that. However, use of
    IS_ERR_VALUE() is error-prone and should be restricted to things which
    are inherently long-sized (stuff in pt_regs etc.). Instead, let's aim
    for changing to the standard kernel style
    
      int foo = cpm_muram_alloc();
      if (foo < 0)
        deal_with_it()
      some->where = foo;
    
    Changing the return type from unsigned long to s32 (aka signed int)
    doesn't change the value that gets stored into any of the callers'
    variables except if the caller was storing the result in a u64 _and_
    the allocation failed, so in itself this patch should be a no-op.
    
    Another problem with cpm_muram_alloc() is that it can certainly
    validly return 0 - and except if some cpm_muram_alloc_fixed() call
    interferes, the very first cpm_muram_alloc() call will return just
    that. But that shows that both ucc_slow_free() and ucc_fast_free() are
    buggy, since they assume that a value of 0 means "that field was never
    allocated". We'll later change cpm_muram_free() to accept (and ignore)
    a negative offset, so callers can use a sentinel of -1 instead of 0
    and just unconditionally call cpm_muram_free().
    Reviewed-by: default avatarTimur Tabi <timur@kernel.org>
    Signed-off-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
    Signed-off-by: default avatarLi Yang <leoyang.li@nxp.com>
    800cd6fb
qe_common.c 6.06 KB