Skip to content

Commit 2f088df

Browse files
committed
md/raid5: Convert stripe_head's "dev" to flexible array member
Replace old-style 1-element array of "dev" in struct stripe_head with modern C99 flexible array. In the future, we can additionally annotate it with the run-time size, found in the "disks" member. Cc: Song Liu <song@kernel.org> Cc: linux-raid@vger.kernel.org Reviewed-by: Christoph Hellwig <hch@lst.de> Acked-by: Song Liu <song@kernel.org> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/lkml/20230522212114.gonna.589-kees@kernel.org/ --- It looks like this memory calculation: memory = conf->min_nr_stripes * (sizeof(struct stripe_head) + max_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024; ... was already buggy (i.e. it included the single "dev" bytes in the result). However, I'm not entirely sure if that is the right analysis, since "dev" is not related to struct bio nor PAGE_SIZE?
1 parent d67790d commit 2f088df

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

drivers/md/raid5.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,7 +2433,7 @@ static int grow_stripes(struct r5conf *conf, int num)
24332433

24342434
conf->active_name = 0;
24352435
sc = kmem_cache_create(conf->cache_name[conf->active_name],
2436-
sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev),
2436+
struct_size_t(struct stripe_head, dev, devs),
24372437
0, 0, NULL);
24382438
if (!sc)
24392439
return 1;
@@ -2559,7 +2559,7 @@ static int resize_stripes(struct r5conf *conf, int newsize)
25592559

25602560
/* Step 1 */
25612561
sc = kmem_cache_create(conf->cache_name[1-conf->active_name],
2562-
sizeof(struct stripe_head)+(newsize-1)*sizeof(struct r5dev),
2562+
struct_size_t(struct stripe_head, dev, newsize),
25632563
0, 0, NULL);
25642564
if (!sc)
25652565
return -ENOMEM;

drivers/md/raid5.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ struct stripe_head {
268268
unsigned long flags;
269269
u32 log_checksum;
270270
unsigned short write_hint;
271-
} dev[1]; /* allocated with extra space depending of RAID geometry */
271+
} dev[]; /* allocated depending of RAID geometry ("disks" member) */
272272
};
273273

274274
/* stripe_head_state - collects and tracks the dynamic state of a stripe_head

0 commit comments

Comments
 (0)