• Kari Argillander's avatar
    fs/ntfs3: Use kernel ALIGN macros over driver specific · fa3cacf5
    Kari Argillander authored
    The static checkers (Smatch) were complaining because QuadAlign() was
    buggy.  If you try to align something higher than UINT_MAX it got
    truncated to a u32.
    
    Smatch warning was:
    	fs/ntfs3/attrib.c:383 attr_set_size_res()
    	warn: was expecting a 64 bit value instead of '~7'
    
    So that this will not happen again we will change all these macros to
    kernel made ones. This can also help some other static analyzing tools
    to give us better warnings.
    
    Patch was generated with Coccinelle script and after that some style
    issue was hand fixed.
    
    Coccinelle script:
    
    virtual patch
    
    @alloc depends on patch@
    expression x;
    @@
    (
    -	#define QuadAlign(n)		(((n) + 7u) & (~7u))
    |
    -	QuadAlign(x)
    +	ALIGN(x, 8)
    |
    -	#define IsQuadAligned(n)	(!((size_t)(n)&7u))
    |
    -	IsQuadAligned(x)
    +	IS_ALIGNED(x, 8)
    |
    -	#define Quad2Align(n)		(((n) + 15u) & (~15u))
    |
    -	Quad2Align(x)
    +	ALIGN(x, 16)
    |
    -	#define IsQuad2Aligned(n)	(!((size_t)(n)&15u))
    |
    -	IsQuad2Aligned(x)
    +	IS_ALIGNED(x, 16)
    |
    -	#define Quad4Align(n)		(((n) + 31u) & (~31u))
    |
    -	Quad4Align(x)
    +	ALIGN(x, 32)
    |
    -	#define IsSizeTAligned(n)	(!((size_t)(n) & (sizeof(size_t) - 1)))
    |
    -	IsSizeTAligned(x)
    +	IS_ALIGNED(x, sizeof(size_t))
    |
    -	#define DwordAlign(n)		(((n) + 3u) & (~3u))
    |
    -	DwordAlign(x)
    +	ALIGN(x, 4)
    |
    -	#define IsDwordAligned(n)	(!((size_t)(n)&3u))
    |
    -	IsDwordAligned(x)
    +	IS_ALIGNED(x, 4)
    |
    -	#define WordAlign(n)		(((n) + 1u) & (~1u))
    |
    -	WordAlign(x)
    +	ALIGN(x, 2)
    |
    -	#define IsWordAligned(n)	(!((size_t)(n)&1u))
    |
    -	IsWordAligned(x)
    +	IS_ALIGNED(x, 2)
    |
    )
    Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
    Signed-off-by: default avatarKari Argillander <kari.argillander@gmail.com>
    Signed-off-by: default avatarKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
    fa3cacf5
attrib.c 44.4 KB