aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikulas Patocka <mpatocka@redhat.com>2008-10-21 12:44:57 -0400
committerAlasdair G Kergon <agk@redhat.com>2008-10-21 12:44:57 -0400
commitd63a5ce3c0d25c96bdadc78792e5b48b846e899d (patch)
treeac46375b47f784dff17d1e657d5115b45ad86844
parent7acedc5b98a2fcff64f00c21110aae7d3ac2f7df (diff)
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>
-rw-r--r--drivers/md/dm-raid1.c3
-rw-r--r--drivers/md/dm-stripe.c4
-rw-r--r--drivers/md/dm.h9
-rw-r--r--include/linux/device-mapper.h3
4 files changed, 5 insertions, 14 deletions
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index 29913e42c4ab..ecfd82169cb3 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -1315,9 +1315,6 @@ static struct mirror_set *alloc_context(unsigned int nr_mirrors,
1315 size_t len; 1315 size_t len;
1316 struct mirror_set *ms = NULL; 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 len = sizeof(*ms) + (sizeof(ms->mirror[0]) * nr_mirrors); 1318 len = sizeof(*ms) + (sizeof(ms->mirror[0]) * nr_mirrors);
1322 1319
1323 ms = kzalloc(len, GFP_KERNEL); 1320 ms = kzalloc(len, GFP_KERNEL);
diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
index b745d8ac625b..287e24584730 100644
--- a/drivers/md/dm-stripe.c
+++ b/drivers/md/dm-stripe.c
@@ -60,8 +60,8 @@ static inline struct stripe_c *alloc_context(unsigned int stripes)
60{ 60{
61 size_t len; 61 size_t len;
62 62
63 if (array_too_big(sizeof(struct stripe_c), sizeof(struct stripe), 63 if (dm_array_too_big(sizeof(struct stripe_c), sizeof(struct stripe),
64 stripes)) 64 stripes))
65 return NULL; 65 return NULL;
66 66
67 len = sizeof(struct stripe_c) + (sizeof(struct stripe) * stripes); 67 len = sizeof(struct stripe_c) + (sizeof(struct stripe) * stripes);
diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index cd189da2b2fa..0ade60cdef42 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -62,15 +62,6 @@ void dm_put_target_type(struct target_type *t);
62int dm_target_iterate(void (*iter_func)(struct target_type *tt, 62int dm_target_iterate(void (*iter_func)(struct target_type *tt,
63 void *param), void *param); 63 void *param), void *param);
64 64
65/*-----------------------------------------------------------------
66 * Useful inlines.
67 *---------------------------------------------------------------*/
68static 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
74int dm_split_args(int *argc, char ***argvp, char *input); 65int dm_split_args(int *argc, char ***argvp, char *input);
75 66
76/* 67/*
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index 08d783592b73..dfb30db475ed 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -354,6 +354,9 @@ void *dm_vcalloc(unsigned long nmemb, unsigned long elem_size);
354 */ 354 */
355#define dm_round_up(n, sz) (dm_div_up((n), (sz)) * (sz)) 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
357static inline sector_t to_sector(unsigned long n) 360static inline sector_t to_sector(unsigned long n)
358{ 361{
359 return (n >> SECTOR_SHIFT); 362 return (n >> SECTOR_SHIFT);