diff options
author | Kees Cook <keescook@chromium.org> | 2018-04-11 00:43:15 -0400 |
---|---|---|
committer | Mike Snitzer <snitzer@redhat.com> | 2018-05-04 10:35:20 -0400 |
commit | 65972a6fa914b16cc15ffcffcb8bea8c64e78f49 (patch) | |
tree | d38714eaabf08f361c6a96467f31f6e94353a07c | |
parent | 3d97c829edd43262e7e9d720fa82c2241ba685a3 (diff) |
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>
-rw-r--r-- | drivers/md/dm-raid1.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c index 580c49cc8079..5903e492bb34 100644 --- a/drivers/md/dm-raid1.c +++ b/drivers/md/dm-raid1.c | |||
@@ -23,6 +23,8 @@ | |||
23 | 23 | ||
24 | #define MAX_RECOVERY 1 /* Maximum number of regions recovered in parallel. */ | 24 | #define MAX_RECOVERY 1 /* Maximum number of regions recovered in parallel. */ |
25 | 25 | ||
26 | #define MAX_NR_MIRRORS (DM_KCOPYD_MAX_REGIONS + 1) | ||
27 | |||
26 | #define DM_RAID1_HANDLE_ERRORS 0x01 | 28 | #define DM_RAID1_HANDLE_ERRORS 0x01 |
27 | #define DM_RAID1_KEEP_LOG 0x02 | 29 | #define DM_RAID1_KEEP_LOG 0x02 |
28 | #define errors_handled(p) ((p)->features & DM_RAID1_HANDLE_ERRORS) | 30 | #define errors_handled(p) ((p)->features & DM_RAID1_HANDLE_ERRORS) |
@@ -255,7 +257,7 @@ static int mirror_flush(struct dm_target *ti) | |||
255 | unsigned long error_bits; | 257 | unsigned long error_bits; |
256 | 258 | ||
257 | unsigned int i; | 259 | unsigned int i; |
258 | struct dm_io_region io[ms->nr_mirrors]; | 260 | struct dm_io_region io[MAX_NR_MIRRORS]; |
259 | struct mirror *m; | 261 | struct mirror *m; |
260 | struct dm_io_request io_req = { | 262 | struct dm_io_request io_req = { |
261 | .bi_op = REQ_OP_WRITE, | 263 | .bi_op = REQ_OP_WRITE, |
@@ -651,7 +653,7 @@ static void write_callback(unsigned long error, void *context) | |||
651 | static void do_write(struct mirror_set *ms, struct bio *bio) | 653 | static void do_write(struct mirror_set *ms, struct bio *bio) |
652 | { | 654 | { |
653 | unsigned int i; | 655 | 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; |
655 | struct mirror *m; | 657 | struct mirror *m; |
656 | struct dm_io_request io_req = { | 658 | struct dm_io_request io_req = { |
657 | .bi_op = REQ_OP_WRITE, | 659 | .bi_op = REQ_OP_WRITE, |
@@ -1083,7 +1085,7 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
1083 | argc -= args_used; | 1085 | argc -= args_used; |
1084 | 1086 | ||
1085 | if (!argc || sscanf(argv[0], "%u%c", &nr_mirrors, &dummy) != 1 || | 1087 | 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) { |
1087 | ti->error = "Invalid number of mirrors"; | 1089 | ti->error = "Invalid number of mirrors"; |
1088 | dm_dirty_log_destroy(dl); | 1090 | dm_dirty_log_destroy(dl); |
1089 | return -EINVAL; | 1091 | return -EINVAL; |
@@ -1404,7 +1406,7 @@ static void mirror_status(struct dm_target *ti, status_type_t type, | |||
1404 | int num_feature_args = 0; | 1406 | int num_feature_args = 0; |
1405 | struct mirror_set *ms = (struct mirror_set *) ti->private; | 1407 | struct mirror_set *ms = (struct mirror_set *) ti->private; |
1406 | struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); | 1408 | 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]; |
1408 | 1410 | ||
1409 | switch (type) { | 1411 | switch (type) { |
1410 | case STATUSTYPE_INFO: | 1412 | case STATUSTYPE_INFO: |