Skip to content

Commit 2e531bc

Browse files
tititiou36Ulf Hansson
authored andcommitted
memstick/ms_block: Fix some incorrect memory allocation
Some functions of the bitmap API take advantage of the fact that a bitmap is an array of long. So, to make sure this assertion is correct, allocate bitmaps with bitmap_zalloc() instead of kzalloc()+hand-computed number of bytes. While at it, also use bitmap_free() instead of kfree() to keep the semantic. Fixes: 0ab3049 ("memstick: add support for legacy memorysticks") Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Link: https://lore.kernel.org/r/dbf633c48c24ae6d95f852557e8d8b3bbdef65fe.1656155715.git.christophe.jaillet@wanadoo.fr Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 0886040 commit 2e531bc

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

drivers/memstick/core/ms_block.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,17 +1341,17 @@ static int msb_ftl_initialize(struct msb_data *msb)
13411341
msb->zone_count = msb->block_count / MS_BLOCKS_IN_ZONE;
13421342
msb->logical_block_count = msb->zone_count * 496 - 2;
13431343

1344-
msb->used_blocks_bitmap = kzalloc(msb->block_count / 8, GFP_KERNEL);
1345-
msb->erased_blocks_bitmap = kzalloc(msb->block_count / 8, GFP_KERNEL);
1344+
msb->used_blocks_bitmap = bitmap_zalloc(msb->block_count, GFP_KERNEL);
1345+
msb->erased_blocks_bitmap = bitmap_zalloc(msb->block_count, GFP_KERNEL);
13461346
msb->lba_to_pba_table =
13471347
kmalloc_array(msb->logical_block_count, sizeof(u16),
13481348
GFP_KERNEL);
13491349

13501350
if (!msb->used_blocks_bitmap || !msb->lba_to_pba_table ||
13511351
!msb->erased_blocks_bitmap) {
1352-
kfree(msb->used_blocks_bitmap);
1352+
bitmap_free(msb->used_blocks_bitmap);
1353+
bitmap_free(msb->erased_blocks_bitmap);
13531354
kfree(msb->lba_to_pba_table);
1354-
kfree(msb->erased_blocks_bitmap);
13551355
return -ENOMEM;
13561356
}
13571357

@@ -1946,7 +1946,7 @@ static DEFINE_MUTEX(msb_disk_lock); /* protects against races in open/release */
19461946
static void msb_data_clear(struct msb_data *msb)
19471947
{
19481948
kfree(msb->boot_page);
1949-
kfree(msb->used_blocks_bitmap);
1949+
bitmap_free(msb->used_blocks_bitmap);
19501950
kfree(msb->lba_to_pba_table);
19511951
kfree(msb->cache);
19521952
msb->card = NULL;

0 commit comments

Comments
 (0)