• Gustavo A. R. Silva's avatar
    audit: Use struct_size() helper in alloc_chunk · bbccc11b
    Gustavo A. R. Silva authored
    One of the more common cases of allocation size calculations is finding
    the size of a structure that has a zero-sized array at the end, along
    with memory for some number of elements for that array. For example:
    
    struct audit_chunk {
    	...
            struct node {
                    struct list_head list;
                    struct audit_tree *owner;
                    unsigned index;         /* index; upper bit indicates 'will prune' */
            } owners[];
    };
    
    Make use of the struct_size() helper instead of an open-coded version
    in order to avoid any potential type mistakes.
    
    So, replace the following form:
    
    offsetof(struct audit_chunk, owners) + count * sizeof(struct node);
    
    with:
    
    struct_size(chunk, owners, count)
    
    This code was detected with the help of Coccinelle.
    Signed-off-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
    Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
    bbccc11b
audit_tree.c 25.7 KB