memstick/ms_block:
Subsystems (3)
cover memstick/ms_block:
This serie is related to bitmap usage in memstick/ms_block.
Patch 1 use the dedicated bitmap API to make sure that a number of long is allocated, instead of a number of bytes.
Patch 2 fix a memory leak. This is speculative.
Pacth 3 is just a clean up to make more use of the bitmap API mostly for consistancy reason.
Christophe JAILLET (3):
memstick/ms_block: Fix some incorrect memory allocation memstick/ms_block: Fix a memory leak memstick/ms_block: Use the bitmap API when applicable
drivers/memstick/core/ms_block.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/3 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.
---
I guess that it is not an issue in RL because memory allocation is certainly "rounding" to keep memory alignment.
--- drivers/memstick/core/ms_block.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/memstick/core/ms_block.c +5 -5
@@ -1341,17 +1341,17 @@ static int msb_ftl_initialize(struct msb_data *msb) msb->zone_count = msb->block_count /MS_BLOCKS_IN_ZONE ; msb->logical_block_count = msb->zone_count *496 -2 ; - msb->used_blocks_bitmap =kzalloc (msb->block_count /8 ,GFP_KERNEL ); - msb->erased_blocks_bitmap =kzalloc (msb->block_count /8 ,GFP_KERNEL ); + msb->used_blocks_bitmap =bitmap_zalloc (msb->block_count,GFP_KERNEL ); + msb->erased_blocks_bitmap =bitmap_zalloc (msb->block_count,GFP_KERNEL ); msb->lba_to_pba_table =kmalloc_array (msb->logical_block_count,sizeof (u16),GFP_KERNEL );if (!msb->used_blocks_bitmap || !msb->lba_to_pba_table || !msb->erased_blocks_bitmap) { -kfree (msb->used_blocks_bitmap); +bitmap_free (msb->used_blocks_bitmap); +bitmap_free (msb->erased_blocks_bitmap);kfree (msb->lba_to_pba_table); -kfree (msb->erased_blocks_bitmap);return -ENOMEM ; }
@@ -1946,7 +1946,7 @@ static DEFINE_MUTEX(msb_disk_lock); /* protects against races in open/release */static void msb_data_clear (struct msb_data *msb) {kfree (msb->boot_page); -kfree (msb->used_blocks_bitmap); +bitmap_free (msb->used_blocks_bitmap);kfree (msb->lba_to_pba_table);kfree (msb->cache); msb->card =NULL ;
Signature · 1 line
2.34.1
Re: [PATCH 1/3] memstick/ms_block: Fix some incorrect memory allocation
Quoted 4 lines · Christophe JAILLET
Some functions of the bitmap API take advantage of the fact that a bitmap is an array of long.
Quoted 8 lines
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 ofkfree()to keep the semantic.Fixes 0ab30494bc4f ("memstick: add support for legacy memorysticks")Signed-off-by Christophe JAILLET <[email protected]>
Applied for next, thanks!
Kind regards
Uffe
Quoted 45 lines
---
I guess that it is not an issue in RL because memory allocation is certainly "rounding" to keep memory alignment.--- drivers/memstick/core/ms_block.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/memstick/core/ms_block.c +5
-6@@ -1341,17 +1341,17 @@ static int msb_ftl_initialize(struct msb_data *msb) msb->zone_count = msb->block_count /MS_BLOCKS_IN_ZONE ; msb->logical_block_count = msb->zone_count *496 -2 ; - msb->used_blocks_bitmap =kzalloc (msb->block_count /8 ,GFP_KERNEL ); - msb->erased_blocks_bitmap =kzalloc (msb->block_count /8 ,GFP_KERNEL ); + msb->used_blocks_bitmap =bitmap_zalloc (msb->block_count,GFP_KERNEL ); + msb->erased_blocks_bitmap =bitmap_zalloc (msb->block_count,GFP_KERNEL ); msb->lba_to_pba_table =kmalloc_array (msb->logical_block_count,sizeof (u16),GFP_KERNEL );if (!msb->used_blocks_bitmap || !msb->lba_to_pba_table || !msb->erased_blocks_bitmap) { -kfree (msb->used_blocks_bitmap); +bitmap_free (msb->used_blocks_bitmap); +bitmap_free (msb->erased_blocks_bitmap);kfree (msb->lba_to_pba_table); -kfree (msb->erased_blocks_bitmap);return -ENOMEM ; }@@ -1946,7 +1946,7 @@ static DEFINE_MUTEX(msb_disk_lock); /* protects against races in open/release */static void msb_data_clear (struct msb_data *msb) {kfree (msb->boot_page); -kfree (msb->used_blocks_bitmap); +bitmap_free (msb->used_blocks_bitmap);kfree (msb->lba_to_pba_table);kfree (msb->cache); msb->card =NULL ; --2.34.1
PATCH 2/3 memstick/ms_block: Fix a memory leak
In reply to Christophe JAILLET'erased_blocks_bitmap' is never freed. As it is allocated at the same time as 'used_blocks_bitmap', it is likely that it should be freed also at the same time.
Add the corresponding bitmap_free() in msb_data_clear().
---
This patch is speculative.
--- drivers/memstick/core/ms_block.c | 1 + 1 file changed, 1 insertion(+)
drivers/memstick/core/ms_block.c +1 -0
@@ -1947,6 +1947,7 @@ static void msb_data_clear(struct msb_data *msb) {kfree (msb->boot_page);bitmap_free (msb->used_blocks_bitmap); +bitmap_free (msb->erased_blocks_bitmap);kfree (msb->lba_to_pba_table);kfree (msb->cache); msb->card =NULL ;
Signature · 1 line
2.34.1
Re: [PATCH 2/3] memstick/ms_block: Fix a memory leak
Quoted 9 lines · Christophe JAILLET
'
erased_blocks_bitmap' is never freed. As it is allocated at the same time as 'used_blocks_bitmap', it is likely that it should be freed also at the same time.Add the corresponding
bitmap_free()inmsb_data_clear().Fixes 0ab30494bc4f ("memstick: add support for legacy memorysticks")Signed-off-by Christophe JAILLET <[email protected]>
Applied for next, thanks!
Kind regards
Uffe
Quoted 21 lines
---
This patch is speculative.--- drivers/memstick/core/ms_block.c | 1 + 1 file changed, 1 insertion(+)drivers/memstick/core/ms_block.c +1
-1@@ -1947,6 +1947,7 @@ static void msb_data_clear(struct msb_data *msb) {kfree (msb->boot_page);bitmap_free (msb->used_blocks_bitmap); +bitmap_free (msb->erased_blocks_bitmap);kfree (msb->lba_to_pba_table);kfree (msb->cache); msb->card =NULL ; --2.34.1
PATCH 3/3 memstick/ms_block: Use the bitmap API when applicable
In reply to Christophe JAILLETUse bitmap_equal() instead of hand writing it. It improves semantic and avoids some explicit computation to convert a number of bits to a number of bytes.
--- drivers/memstick/core/ms_block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/memstick/core/ms_block.c +2 -2
@@ -2245,8 +2245,8 @@ static int msb_resume(struct memstick_dev *card) goto out;if (msb->block_count != new_msb->block_count || -memcmp (msb->used_blocks_bitmap, new_msb->used_blocks_bitmap, - msb->block_count /8 )) + !bitmap_equal (msb->used_blocks_bitmap, new_msb->used_blocks_bitmap, + msb->block_count)) goto out; card_dead = false;
Signature · 1 line
2.34.1
Re: [PATCH 3/3] memstick/ms_block: Use the bitmap API when applicable
Quoted 6 lines · Christophe JAILLET
Use
bitmap_equal()instead of hand writing it. It improves semantic and avoids some explicit computation to convert a number of bits to a number of bytes.Signed-off-by Christophe JAILLET <[email protected]>
Applied for next, thanks!
Kind regards
Uffe
Quoted 22 lines
--- drivers/memstick/core/ms_block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/memstick/core/ms_block.c +2
-3@@ -2245,8 +2245,8 @@ static int msb_resume(struct memstick_dev *card) goto out;if (msb->block_count != new_msb->block_count || -memcmp (msb->used_blocks_bitmap, new_msb->used_blocks_bitmap, - msb->block_count /8 )) + !bitmap_equal (msb->used_blocks_bitmap, new_msb->used_blocks_bitmap, + msb->block_count)) goto out; card_dead = false; --2.34.1