Skip to contentSkip to conversation

scsi: tcmu: Switch to bitmap_zalloc()

PATCH Applied Andy Shevchenko 4 participants 5 messages Mar 4, 2019 – Mar 7, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: tcmu: Switch to bitmap_zalloc()

Switch to bitmap_zalloc() to show clearly what we are allocating. Besides that it returns pointer of bitmap type instead of opaque void *.

---
 drivers/target/target_core_user.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/target/target_core_user.c +3 -5
index 5831e0eecea1..c726c029affe 100644
@@ -1663,7 +1663,7 @@ static void tcmu_dev_kref_release(struct kref *kref)
 	WARN_ON(!all_expired);
 
 	tcmu_blocks_release(&udev->data_blocks, 0, udev->dbi_max + 1);
-	kfree(udev->data_bitmap);
+	bitmap_free(udev->data_bitmap);
 	mutex_unlock(&udev->cmdr_lock);
 
 	call_rcu(&dev->rcu_head, tcmu_dev_call_rcu);
@@ -1870,9 +1870,7 @@ static int tcmu_configure_device(struct se_device *dev)
 	info = &udev->uio_info;
 
 	mutex_lock(&udev->cmdr_lock);
-	udev->data_bitmap = kcalloc(BITS_TO_LONGS(udev->max_blocks),
-				    sizeof(unsigned long),
-				    GFP_KERNEL);
+	udev->data_bitmap = bitmap_zalloc(udev->max_blocks, GFP_KERNEL);
 	mutex_unlock(&udev->cmdr_lock);
 	if (!udev->data_bitmap) {
 		ret = -ENOMEM;
@@ -1959,7 +1957,7 @@ static int tcmu_configure_device(struct se_device *dev)
 	vfree(udev->mb_addr);
 	udev->mb_addr = NULL;
 err_vzalloc:
-	kfree(udev->data_bitmap);
+	bitmap_free(udev->data_bitmap);
 	udev->data_bitmap = NULL;
 err_bitmap_alloc:
 	kfree(info->name);
Signature · 1 line
2.20.1
Reviewed-by Bart Van Assche +ADw-bvanassche+AEA-acm.org+AD4 on v1 1/1
#1 lore raw

On Mon, 2019-03-04 at 11:44 +-0200, Andy Shevchenko wrote:
+AD4 Switch to bitmap+AF8-zalloc() to show clearly what we are allocating. +AD4 Besides that it returns pointer of bitmap type instead of opaque void +ACo.

Reviewed-by Bart Van Assche +ADw-bvanassche+AEA-acm.org+AD4
#2 lore raw
In reply to Andy Shevchenko

Mike,

Please review!

Quoted 41 lines

Switch to bitmap_zalloc() to show clearly what we are allocating. Besides that it returns pointer of bitmap type instead of opaque void *.

---
 drivers/target/target_core_user.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/target/target_core_user.c +3 -5
index 5831e0eecea1..c726c029affe 100644
@@ -1663,7 +1663,7 @@ static void tcmu_dev_kref_release(struct kref *kref)
 	WARN_ON(!all_expired);
 
 	tcmu_blocks_release(&udev->data_blocks, 0, udev->dbi_max + 1);
-	kfree(udev->data_bitmap);
+	bitmap_free(udev->data_bitmap);
 	mutex_unlock(&udev->cmdr_lock);
 
 	call_rcu(&dev->rcu_head, tcmu_dev_call_rcu);
@@ -1870,9 +1870,7 @@ static int tcmu_configure_device(struct se_device *dev)
 	info = &udev->uio_info;
 
 	mutex_lock(&udev->cmdr_lock);
-	udev->data_bitmap = kcalloc(BITS_TO_LONGS(udev->max_blocks),
-				    sizeof(unsigned long),
-				    GFP_KERNEL);
+	udev->data_bitmap = bitmap_zalloc(udev->max_blocks, GFP_KERNEL);
 	mutex_unlock(&udev->cmdr_lock);
 	if (!udev->data_bitmap) {
 		ret = -ENOMEM;
@@ -1959,7 +1957,7 @@ static int tcmu_configure_device(struct se_device *dev)
 	vfree(udev->mb_addr);
 	udev->mb_addr = NULL;
 err_vzalloc:
-	kfree(udev->data_bitmap);
+	bitmap_free(udev->data_bitmap);
 	udev->data_bitmap = NULL;
 err_bitmap_alloc:
 	kfree(info->name);
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
Acked-by on v1 1/1
#3 lore raw
In reply to Andy Shevchenko
Quoted 34 lines · Andy Shevchenko

Switch to bitmap_zalloc() to show clearly what we are allocating. Besides that it returns pointer of bitmap type instead of opaque void *.

---
 drivers/target/target_core_user.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/target/target_core_user.c +2 -4
index 5831e0eecea1..c726c029affe 100644
@@ -1663,7 +1663,7 @@ static void tcmu_dev_kref_release(struct kref *kref)
 	WARN_ON(!all_expired);
 
 	tcmu_blocks_release(&udev->data_blocks, 0, udev->dbi_max + 1);
-	kfree(udev->data_bitmap);
+	bitmap_free(udev->data_bitmap);
 	mutex_unlock(&udev->cmdr_lock);
 
 	call_rcu(&dev->rcu_head, tcmu_dev_call_rcu);
@@ -1870,9 +1870,7 @@ static int tcmu_configure_device(struct se_device *dev)
 	info = &udev->uio_info;
 
 	mutex_lock(&udev->cmdr_lock);
-	udev->data_bitmap = kcalloc(BITS_TO_LONGS(udev->max_blocks),
-				    sizeof(unsigned long),
-				    GFP_KERNEL);
+	udev->data_bitmap = bitmap_zalloc(udev->max_blocks, GFP_KERNEL);
 	mutex_unlock(&udev->cmdr_lock);
 	if (!udev->data_bitmap) {
 		ret = -ENOMEM;

drivers/target/target_core_user.c static int tcmu_configure_device(struct se_device *dev) · line 1963

Quoted 8 lines
drivers/target/target_core_user.c +1 -1
@@ -1959,7 +1957,7 @@ static int tcmu_configure_device(struct se_device *dev)
 	vfree(udev->mb_addr);
 	udev->mb_addr = NULL;
 err_vzalloc:
-	kfree(udev->data_bitmap);
+	bitmap_free(udev->data_bitmap);
 	udev->data_bitmap = NULL;
 err_bitmap_alloc:
 	kfree(info->name);

Looks nice to me. Thanks.

#4 lore raw
In reply to Andy Shevchenko

Andy,

Quoted 3 lines

Switch to bitmap_zalloc() to show clearly what we are allocating. Besides that it returns pointer of bitmap type instead of opaque void *.

Applied to 5.1/scsi-queue. Thank you!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering