Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dm: publish array_too_big

Move array_too_big to include/linux/device-mapper.h because it is
used by targets.

Remove the test from dm-raid1 as the number of mirror legs is limited
such that it can never fail. (Even for stripes it seems rather
unlikely.)

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>

authored by

Mikulas Patocka and committed by
Alasdair G Kergon
d63a5ce3 7acedc5b

+5 -14
-3
drivers/md/dm-raid1.c
··· 1315 1315 size_t len; 1316 1316 struct mirror_set *ms = NULL; 1317 1317 1318 - if (array_too_big(sizeof(*ms), sizeof(ms->mirror[0]), nr_mirrors)) 1319 - return NULL; 1320 - 1321 1318 len = sizeof(*ms) + (sizeof(ms->mirror[0]) * nr_mirrors); 1322 1319 1323 1320 ms = kzalloc(len, GFP_KERNEL);
+2 -2
drivers/md/dm-stripe.c
··· 60 60 { 61 61 size_t len; 62 62 63 - if (array_too_big(sizeof(struct stripe_c), sizeof(struct stripe), 64 - stripes)) 63 + if (dm_array_too_big(sizeof(struct stripe_c), sizeof(struct stripe), 64 + stripes)) 65 65 return NULL; 66 66 67 67 len = sizeof(struct stripe_c) + (sizeof(struct stripe) * stripes);
-9
drivers/md/dm.h
··· 62 62 int dm_target_iterate(void (*iter_func)(struct target_type *tt, 63 63 void *param), void *param); 64 64 65 - /*----------------------------------------------------------------- 66 - * Useful inlines. 67 - *---------------------------------------------------------------*/ 68 - static inline int array_too_big(unsigned long fixed, unsigned long obj, 69 - unsigned long num) 70 - { 71 - return (num > (ULONG_MAX - fixed) / obj); 72 - } 73 - 74 65 int dm_split_args(int *argc, char ***argvp, char *input); 75 66 76 67 /*
+3
include/linux/device-mapper.h
··· 354 354 */ 355 355 #define dm_round_up(n, sz) (dm_div_up((n), (sz)) * (sz)) 356 356 357 + #define dm_array_too_big(fixed, obj, num) \ 358 + ((num) > (UINT_MAX - (fixed)) / (obj)) 359 + 357 360 static inline sector_t to_sector(unsigned long n) 358 361 { 359 362 return (n >> SECTOR_SHIFT);