Skip to content
  • Kees Cook's avatar
    treewide: Use array_size() in sock_kmalloc() · 76e43e37
    Kees Cook authored
    The sock_kmalloc() function has no 2-factor argument form, so
    multiplication factors need to be wrapped in array_size(). This patch
    replaces cases of:
    
            sock_kmalloc(handle, a * b, gfp)
    
    with:
            sock_kmalloc(handle, array_size(a, b), gfp)
    
    as well as handling cases of:
    
            sock_kmalloc(handle, a * b * c, gfp)
    
    with:
    
            sock_kmalloc(handle, array3_size(a, b, c), gfp)
    
    This does, however, attempt to ignore constant size factors like:
    
            sock_kmalloc(handle, 4 * 1024, gfp)
    
    though any constants defined via macros get caught up in the conversion.
    
    Any factors with a sizeof() of "unsigned char", "char", and "u8" were
    dropped, since they're redundant.
    
    The Coccinelle script used for this was:
    
    // Fix redundant parens around sizeof().
    @@
    expression HANDLE;
    type TYPE;
    expression THING, E;
    @@
    
    (
      sock_kmalloc(HANDLE,
    -	(sizeof(TYPE)) * E
    +	sizeof(TYPE) * E
      , ...)
    |
      sock_kmalloc(HANDLE,
    -	(sizeof(THING)) * E
    +	sizeof(THING) * E
      , ...)...
    76e43e37