dm: replace dm_vcalloc()

Use kvcalloc or kvmalloc_array instead (depending whether zeroing is
useful).

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
This commit is contained in:
Matthew Wilcox (Oracle) 2021-04-07 14:25:22 +01:00 committed by Mike Snitzer
parent 5208692e80
commit 7a35693adc
4 changed files with 12 additions and 34 deletions

View File

@ -596,7 +596,7 @@ static void persistent_dtr(struct dm_exception_store *store)
free_area(ps); free_area(ps);
/* Allocated in persistent_read_metadata */ /* Allocated in persistent_read_metadata */
vfree(ps->callbacks); kvfree(ps->callbacks);
kfree(ps); kfree(ps);
} }
@ -621,8 +621,8 @@ static int persistent_read_metadata(struct dm_exception_store *store,
*/ */
ps->exceptions_per_area = (ps->store->chunk_size << SECTOR_SHIFT) / ps->exceptions_per_area = (ps->store->chunk_size << SECTOR_SHIFT) /
sizeof(struct disk_exception); sizeof(struct disk_exception);
ps->callbacks = dm_vcalloc(ps->exceptions_per_area, ps->callbacks = kvcalloc(ps->exceptions_per_area,
sizeof(*ps->callbacks)); sizeof(*ps->callbacks), GFP_KERNEL);
if (!ps->callbacks) if (!ps->callbacks)
return -ENOMEM; return -ENOMEM;

View File

@ -663,7 +663,8 @@ static int dm_exception_table_init(struct dm_exception_table *et,
et->hash_shift = hash_shift; et->hash_shift = hash_shift;
et->hash_mask = size - 1; et->hash_mask = size - 1;
et->table = dm_vcalloc(size, sizeof(struct hlist_bl_head)); et->table = kvmalloc_array(size, sizeof(struct hlist_bl_head),
GFP_KERNEL);
if (!et->table) if (!et->table)
return -ENOMEM; return -ENOMEM;
@ -689,7 +690,7 @@ static void dm_exception_table_exit(struct dm_exception_table *et,
kmem_cache_free(mem, ex); kmem_cache_free(mem, ex);
} }
vfree(et->table); kvfree(et->table);
} }
static uint32_t exception_hash(struct dm_exception_table *et, chunk_t chunk) static uint32_t exception_hash(struct dm_exception_table *et, chunk_t chunk)

View File

@ -94,24 +94,6 @@ static int setup_btree_index(unsigned int l, struct dm_table *t)
return 0; return 0;
} }
void *dm_vcalloc(unsigned long nmemb, unsigned long elem_size)
{
unsigned long size;
void *addr;
/*
* Check that we're not going to overflow.
*/
if (nmemb > (ULONG_MAX / elem_size))
return NULL;
size = nmemb * elem_size;
addr = vzalloc(size);
return addr;
}
EXPORT_SYMBOL(dm_vcalloc);
/* /*
* highs, and targets are managed as dynamic arrays during a * highs, and targets are managed as dynamic arrays during a
* table load. * table load.
@ -124,15 +106,15 @@ static int alloc_targets(struct dm_table *t, unsigned int num)
/* /*
* Allocate both the target array and offset array at once. * Allocate both the target array and offset array at once.
*/ */
n_highs = (sector_t *) dm_vcalloc(num, sizeof(struct dm_target) + n_highs = kvcalloc(num, sizeof(struct dm_target) + sizeof(sector_t),
sizeof(sector_t)); GFP_KERNEL);
if (!n_highs) if (!n_highs)
return -ENOMEM; return -ENOMEM;
n_targets = (struct dm_target *) (n_highs + num); n_targets = (struct dm_target *) (n_highs + num);
memset(n_highs, -1, sizeof(*n_highs) * num); memset(n_highs, -1, sizeof(*n_highs) * num);
vfree(t->highs); kvfree(t->highs);
t->num_allocated = num; t->num_allocated = num;
t->highs = n_highs; t->highs = n_highs;
@ -198,7 +180,7 @@ void dm_table_destroy(struct dm_table *t)
/* free the indexes */ /* free the indexes */
if (t->depth >= 2) if (t->depth >= 2)
vfree(t->index[t->depth - 2]); kvfree(t->index[t->depth - 2]);
/* free the targets */ /* free the targets */
for (i = 0; i < t->num_targets; i++) { for (i = 0; i < t->num_targets; i++) {
@ -210,7 +192,7 @@ void dm_table_destroy(struct dm_table *t)
dm_put_target_type(tgt->type); dm_put_target_type(tgt->type);
} }
vfree(t->highs); kvfree(t->highs);
/* free the device list */ /* free the device list */
free_devices(&t->devices, t->md); free_devices(&t->devices, t->md);
@ -1077,7 +1059,7 @@ static int setup_indexes(struct dm_table *t)
total += t->counts[i]; total += t->counts[i];
} }
indexes = (sector_t *) dm_vcalloc(total, (unsigned long) NODE_SIZE); indexes = kvcalloc(total, NODE_SIZE, GFP_KERNEL);
if (!indexes) if (!indexes)
return -ENOMEM; return -ENOMEM;

View File

@ -574,11 +574,6 @@ struct dm_table *dm_swap_table(struct mapped_device *md,
*/ */
void dm_destroy_keyslot_manager(struct blk_keyslot_manager *ksm); void dm_destroy_keyslot_manager(struct blk_keyslot_manager *ksm);
/*
* A wrapper around vmalloc.
*/
void *dm_vcalloc(unsigned long nmemb, unsigned long elem_size);
/*----------------------------------------------------------------- /*-----------------------------------------------------------------
* Macros. * Macros.
*---------------------------------------------------------------*/ *---------------------------------------------------------------*/