• Jason A. Donenfeld's avatar
    treewide: use get_random_u32_{above,below}() instead of manual loop · d247aabd
    Jason A. Donenfeld authored
    These cases were done with this Coccinelle:
    
    @@
    expression E;
    identifier I;
    @@
    -   do {
          ... when != I
    -     I = get_random_u32();
          ... when != I
    -   } while (I > E);
    +   I = get_random_u32_below(E + 1);
    
    @@
    expression E;
    identifier I;
    @@
    -   do {
          ... when != I
    -     I = get_random_u32();
          ... when != I
    -   } while (I >= E);
    +   I = get_random_u32_below(E);
    
    @@
    expression E;
    identifier I;
    @@
    -   do {
          ... when != I
    -     I = get_random_u32();
          ... when != I
    -   } while (I < E);
    +   I = get_random_u32_above(E - 1);
    
    @@
    expression E;
    identifier I;
    @@
    -   do {
          ... when != I
    -     I = get_random_u32();
          ... when != I
    -   } while (I <= E);
    +   I = get_random_u32_above(E);
    
    @@
    identifier I;
    @@
    -   do {
          ... when != I
    -     I = get_random_u32();
          ... when != I
    -   } while (!I);
    +   I = get_random_u32_above(0);
    
    @@
    identifier I;
    @@
    -   do {
          ... when != I
    -     I = get_random_u32();
          ... when != I
    -   } while (I == 0);
    +   I = get_random_u32_above(0);
    
    @@
    expression E;
    @@
    - E + 1 + get_random_u32_below(U32_MAX - E)
    + get_random_u32_above(E)
    Reviewed-by: default avatarKees Cook <keescook@chromium.org>
    Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
    d247aabd
af_vsock.c 58.9 KB