Commit d63a5ce3c0d25c96bdadc78792e5b48b846e899d

Authored by Mikulas Patocka
Committed by Alasdair G Kergon
1 parent 7acedc5b98

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>

Showing 4 changed files with 5 additions and 14 deletions Side-by-side Diff

drivers/md/dm-raid1.c
... ... @@ -1315,9 +1315,6 @@
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);
drivers/md/dm-stripe.c
... ... @@ -60,8 +60,8 @@
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);
... ... @@ -62,15 +62,6 @@
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 /*
include/linux/device-mapper.h
... ... @@ -354,6 +354,9 @@
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);