Skip to content

Commit 65972a6

Browse files
keessnitm
authored andcommitted
dm mirror: remove VLA usage
On the quest to remove all VLAs from the kernel[1], this avoids VLAs in dm-raid1.c by just using the maximum size for the stack arrays. The nr_mirrors value was already capped at 9, so this makes it a trivial adjustment to the array sizes. [1] https://lkml.org/lkml/2018/3/7/621 Signed-off-by: Kees Cook <keescook@chromium.org> Acked-by: Heinz Mauelshagen <heinzm@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
1 parent 3d97c82 commit 65972a6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/md/dm-raid1.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#define MAX_RECOVERY 1 /* Maximum number of regions recovered in parallel. */
2525

26+
#define MAX_NR_MIRRORS (DM_KCOPYD_MAX_REGIONS + 1)
27+
2628
#define DM_RAID1_HANDLE_ERRORS 0x01
2729
#define DM_RAID1_KEEP_LOG 0x02
2830
#define errors_handled(p) ((p)->features & DM_RAID1_HANDLE_ERRORS)
@@ -255,7 +257,7 @@ static int mirror_flush(struct dm_target *ti)
255257
unsigned long error_bits;
256258

257259
unsigned int i;
258-
struct dm_io_region io[ms->nr_mirrors];
260+
struct dm_io_region io[MAX_NR_MIRRORS];
259261
struct mirror *m;
260262
struct dm_io_request io_req = {
261263
.bi_op = REQ_OP_WRITE,
@@ -651,7 +653,7 @@ static void write_callback(unsigned long error, void *context)
651653
static void do_write(struct mirror_set *ms, struct bio *bio)
652654
{
653655
unsigned int i;
654-
struct dm_io_region io[ms->nr_mirrors], *dest = io;
656+
struct dm_io_region io[MAX_NR_MIRRORS], *dest = io;
655657
struct mirror *m;
656658
struct dm_io_request io_req = {
657659
.bi_op = REQ_OP_WRITE,
@@ -1083,7 +1085,7 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)
10831085
argc -= args_used;
10841086

10851087
if (!argc || sscanf(argv[0], "%u%c", &nr_mirrors, &dummy) != 1 ||
1086-
nr_mirrors < 2 || nr_mirrors > DM_KCOPYD_MAX_REGIONS + 1) {
1088+
nr_mirrors < 2 || nr_mirrors > MAX_NR_MIRRORS) {
10871089
ti->error = "Invalid number of mirrors";
10881090
dm_dirty_log_destroy(dl);
10891091
return -EINVAL;
@@ -1404,7 +1406,7 @@ static void mirror_status(struct dm_target *ti, status_type_t type,
14041406
int num_feature_args = 0;
14051407
struct mirror_set *ms = (struct mirror_set *) ti->private;
14061408
struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
1407-
char buffer[ms->nr_mirrors + 1];
1409+
char buffer[MAX_NR_MIRRORS + 1];
14081410

14091411
switch (type) {
14101412
case STATUSTYPE_INFO:

0 commit comments

Comments
 (0)