Skip to content

Commit e118029

Browse files
tititiou36Mike Snitzer
authored andcommitted
dm zone: Use the bitmap API to allocate bitmaps
Use bitmap_zalloc()/bitmap_free() instead of hand-writing them. It is less verbose and it improves the semantic. Signed-off-by: Christophe JAILLET <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent d483001 commit e118029

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

drivers/md/dm-zone.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/mm.h>
88
#include <linux/sched/mm.h>
99
#include <linux/slab.h>
10+
#include <linux/bitmap.h>
1011

1112
#include "dm-core.h"
1213

@@ -140,9 +141,9 @@ bool dm_is_zone_write(struct mapped_device *md, struct bio *bio)
140141
void dm_cleanup_zoned_dev(struct mapped_device *md)
141142
{
142143
if (md->disk) {
143-
kfree(md->disk->conv_zones_bitmap);
144+
bitmap_free(md->disk->conv_zones_bitmap);
144145
md->disk->conv_zones_bitmap = NULL;
145-
kfree(md->disk->seq_zones_wlock);
146+
bitmap_free(md->disk->seq_zones_wlock);
146147
md->disk->seq_zones_wlock = NULL;
147148
}
148149

@@ -182,9 +183,8 @@ static int dm_zone_revalidate_cb(struct blk_zone *zone, unsigned int idx,
182183
switch (zone->type) {
183184
case BLK_ZONE_TYPE_CONVENTIONAL:
184185
if (!disk->conv_zones_bitmap) {
185-
disk->conv_zones_bitmap =
186-
kcalloc(BITS_TO_LONGS(disk->nr_zones),
187-
sizeof(unsigned long), GFP_NOIO);
186+
disk->conv_zones_bitmap = bitmap_zalloc(disk->nr_zones,
187+
GFP_NOIO);
188188
if (!disk->conv_zones_bitmap)
189189
return -ENOMEM;
190190
}
@@ -193,9 +193,8 @@ static int dm_zone_revalidate_cb(struct blk_zone *zone, unsigned int idx,
193193
case BLK_ZONE_TYPE_SEQWRITE_REQ:
194194
case BLK_ZONE_TYPE_SEQWRITE_PREF:
195195
if (!disk->seq_zones_wlock) {
196-
disk->seq_zones_wlock =
197-
kcalloc(BITS_TO_LONGS(disk->nr_zones),
198-
sizeof(unsigned long), GFP_NOIO);
196+
disk->seq_zones_wlock = bitmap_zalloc(disk->nr_zones,
197+
GFP_NOIO);
199198
if (!disk->seq_zones_wlock)
200199
return -ENOMEM;
201200
}

0 commit comments

Comments
 (0)