]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ocfs2: annotate more flexible array members with __counted_by_le()
authorDmitry Antipov <dmantipov@yandex.ru>
Tue, 21 Oct 2025 10:55:18 +0000 (13:55 +0300)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 21 Jan 2026 03:44:18 +0000 (19:44 -0800)
Annotate flexible array members of 'struct ocfs2_local_alloc' and 'struct
ocfs2_inline_data' with '__counted_by_le()' attribute to improve array
bounds checking when CONFIG_UBSAN_BOUNDS is enabled, and prefer the
convenient 'memset()' over an explicit loop to simplify
'ocfs2_clear_local_alloc()'.

Link: https://lkml.kernel.org/r/20251021105518.119953-1-dmantipov@yandex.ru
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Reviewed-by: Heming Zhao <heming.zhao@suse.com>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Joseph Qi <jiangqi903@gmail.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Jun Piao <piaojun@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/ocfs2/localalloc.c
fs/ocfs2/ocfs2_fs.h

index d1aa04a5af1b1c8f8d15da0f7ccd65ee2013a214..56be21c695d6e7431cad8f3cda57155c17b71d0a 100644 (file)
@@ -905,13 +905,11 @@ bail:
 static void ocfs2_clear_local_alloc(struct ocfs2_dinode *alloc)
 {
        struct ocfs2_local_alloc *la = OCFS2_LOCAL_ALLOC(alloc);
-       int i;
 
        alloc->id1.bitmap1.i_total = 0;
        alloc->id1.bitmap1.i_used = 0;
        la->la_bm_off = 0;
-       for(i = 0; i < le16_to_cpu(la->la_size); i++)
-               la->la_bitmap[i] = 0;
+       memset(la->la_bitmap, 0, le16_to_cpu(la->la_size));
 }
 
 #if 0
index f7763da5c4a2b690b5eb7cb6671d1bb876836849..c501eb3cdcdae5c1e275492262c5edd8d8508e5c 100644 (file)
@@ -641,7 +641,7 @@ struct ocfs2_local_alloc
        __le16 la_size;         /* Size of included bitmap, in bytes */
        __le16 la_reserved1;
        __le64 la_reserved2;
-/*10*/ __u8   la_bitmap[];
+/*10*/ __u8   la_bitmap[] __counted_by_le(la_size);
 };
 
 /*
@@ -654,7 +654,7 @@ struct ocfs2_inline_data
                                 * for data, starting at id_data */
        __le16  id_reserved0;
        __le32  id_reserved1;
-       __u8    id_data[];      /* Start of user data */
+       __u8    id_data[] __counted_by_le(id_count);    /* Start of user data */
 };
 
 /*