summaryrefslogtreecommitdiff
path: root/fs/ntfs3/ntfs.h
diff options
context:
space:
mode:
authorKari Argillander <kari.argillander@gmail.com>2021-08-26 11:56:29 +0300
committerKonstantin Komarov <almaz.alexandrovich@paragon-software.com>2021-08-27 17:05:12 +0300
commitfa3cacf544636b2dc48cfb2f277a2071f14d66a2 (patch)
treeb8a8c9c934e36eb965f3dca0d299519fb748104a /fs/ntfs3/ntfs.h
parent24516d481dfc6c7728ffe36280ca8cf4640d119a (diff)
fs/ntfs3: Use kernel ALIGN macros over driver specific
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: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Kari Argillander <kari.argillander@gmail.com> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Diffstat (limited to 'fs/ntfs3/ntfs.h')
-rw-r--r--fs/ntfs3/ntfs.h16
1 files changed, 8 insertions, 8 deletions
diff --git a/fs/ntfs3/ntfs.h b/fs/ntfs3/ntfs.h
index 16da514af124..f6d6f1bd312e 100644
--- a/fs/ntfs3/ntfs.h
+++ b/fs/ntfs3/ntfs.h
@@ -392,8 +392,8 @@ static inline u64 attr_ondisk_size(const struct ATTRIB *attr)
return attr->non_res ? ((attr->flags &
(ATTR_FLAG_COMPRESSED | ATTR_FLAG_SPARSED)) ?
le64_to_cpu(attr->nres.total_size) :
- le64_to_cpu(attr->nres.alloc_size)) :
- QuadAlign(le32_to_cpu(attr->res.data_size));
+ le64_to_cpu(attr->nres.alloc_size))
+ : ALIGN(le32_to_cpu(attr->res.data_size), 8);
}
static inline u64 attr_size(const struct ATTRIB *attr)
@@ -529,8 +529,8 @@ static_assert(sizeof(struct ATTR_LIST_ENTRY) == 0x20);
static inline u32 le_size(u8 name_len)
{
- return QuadAlign(offsetof(struct ATTR_LIST_ENTRY, name) +
- name_len * sizeof(short));
+ return ALIGN(offsetof(struct ATTR_LIST_ENTRY, name) +
+ name_len * sizeof(short), 8);
}
/* returns 0 if 'attr' has the same type and name */
@@ -691,10 +691,10 @@ static inline bool de_has_vcn_ex(const struct NTFS_DE *e)
sizeof(__le64)));
}
-#define MAX_BYTES_PER_NAME_ENTRY \
- QuadAlign(sizeof(struct NTFS_DE) + \
- offsetof(struct ATTR_FILE_NAME, name) + \
- NTFS_NAME_LEN * sizeof(short))
+#define MAX_BYTES_PER_NAME_ENTRY \
+ ALIGN(sizeof(struct NTFS_DE) + \
+ offsetof(struct ATTR_FILE_NAME, name) + \
+ NTFS_NAME_LEN * sizeof(short), 8)
struct INDEX_HDR {
__le32 de_off; // 0x00: The offset from the start of this structure