diff mbox series

null_blk: cleanup zoned mode initialization

Message ID 20210112034453.1220131-1-damien.lemoal@wdc.com (mailing list archive)
State New, archived
Headers show
Series null_blk: cleanup zoned mode initialization | expand

Commit Message

Damien Le Moal Jan. 12, 2021, 3:44 a.m. UTC
To avoid potential compilation problems, replaced the badly written
MB_TO_SECTS macro (missing parenthesis around the argument use) with
the inline function mb_to_sects(). And while at it, use DIV_ROUND_UP()
to calculate the total number of zones of a zoned device, simplifying
the code.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 drivers/block/null_blk/zoned.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

Comments

Chaitanya Kulkarni Jan. 12, 2021, 6:14 a.m. UTC | #1
On 1/11/21 19:47, Damien Le Moal wrote:
> To avoid potential compilation problems, replaced the badly written
> MB_TO_SECTS macro (missing parenthesis around the argument use) with
> the inline function mb_to_sects(). And while at it, use DIV_ROUND_UP()
> to calculate the total number of zones of a zoned device, simplifying
> the code.
>
> Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Looks good.

Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Damien Le Moal Jan. 27, 2021, 1:09 a.m. UTC | #2
On 2021/01/12 12:47, Damien Le Moal wrote:
> To avoid potential compilation problems, replaced the badly written
> MB_TO_SECTS macro (missing parenthesis around the argument use) with
> the inline function mb_to_sects(). And while at it, use DIV_ROUND_UP()
> to calculate the total number of zones of a zoned device, simplifying
> the code.
> 
> Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>

Jens,

Ping ?


> ---
>  drivers/block/null_blk/zoned.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c
> index 148b871f263b..535351570bb2 100644
> --- a/drivers/block/null_blk/zoned.c
> +++ b/drivers/block/null_blk/zoned.c
> @@ -6,7 +6,10 @@
>  #define CREATE_TRACE_POINTS
>  #include "trace.h"
>  
> -#define MB_TO_SECTS(mb) (((sector_t)mb * SZ_1M) >> SECTOR_SHIFT)
> +static inline sector_t mb_to_sects(unsigned long mb)
> +{
> +	return ((sector_t)mb * SZ_1M) >> SECTOR_SHIFT;
> +}
>  
>  static inline unsigned int null_zone_no(struct nullb_device *dev, sector_t sect)
>  {
> @@ -77,12 +80,10 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q)
>  		return -EINVAL;
>  	}
>  
> -	zone_capacity_sects = MB_TO_SECTS(dev->zone_capacity);
> -	dev_capacity_sects = MB_TO_SECTS(dev->size);
> -	dev->zone_size_sects = MB_TO_SECTS(dev->zone_size);
> -	dev->nr_zones = dev_capacity_sects >> ilog2(dev->zone_size_sects);
> -	if (dev_capacity_sects & (dev->zone_size_sects - 1))
> -		dev->nr_zones++;
> +	zone_capacity_sects = mb_to_sects(dev->zone_capacity);
> +	dev_capacity_sects = mb_to_sects(dev->size);
> +	dev->zone_size_sects = mb_to_sects(dev->zone_size);
> +	dev->nr_zones = DIV_ROUND_UP(dev_capacity_sects, dev->zone_size_sects);
>  
>  	dev->zones = kvmalloc_array(dev->nr_zones, sizeof(struct nullb_zone),
>  				    GFP_KERNEL | __GFP_ZERO);
>
Damien Le Moal Jan. 29, 2021, 12:06 a.m. UTC | #3
On 2021/01/12 12:47, Damien Le Moal wrote:
> To avoid potential compilation problems, replaced the badly written
> MB_TO_SECTS macro (missing parenthesis around the argument use) with
> the inline function mb_to_sects(). And while at it, use DIV_ROUND_UP()
> to calculate the total number of zones of a zoned device, simplifying
> the code.
> 
> Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
> ---
>  drivers/block/null_blk/zoned.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c
> index 148b871f263b..535351570bb2 100644
> --- a/drivers/block/null_blk/zoned.c
> +++ b/drivers/block/null_blk/zoned.c
> @@ -6,7 +6,10 @@
>  #define CREATE_TRACE_POINTS
>  #include "trace.h"
>  
> -#define MB_TO_SECTS(mb) (((sector_t)mb * SZ_1M) >> SECTOR_SHIFT)
> +static inline sector_t mb_to_sects(unsigned long mb)
> +{
> +	return ((sector_t)mb * SZ_1M) >> SECTOR_SHIFT;
> +}
>  
>  static inline unsigned int null_zone_no(struct nullb_device *dev, sector_t sect)
>  {
> @@ -77,12 +80,10 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q)
>  		return -EINVAL;
>  	}
>  
> -	zone_capacity_sects = MB_TO_SECTS(dev->zone_capacity);
> -	dev_capacity_sects = MB_TO_SECTS(dev->size);
> -	dev->zone_size_sects = MB_TO_SECTS(dev->zone_size);
> -	dev->nr_zones = dev_capacity_sects >> ilog2(dev->zone_size_sects);
> -	if (dev_capacity_sects & (dev->zone_size_sects - 1))
> -		dev->nr_zones++;
> +	zone_capacity_sects = mb_to_sects(dev->zone_capacity);
> +	dev_capacity_sects = mb_to_sects(dev->size);
> +	dev->zone_size_sects = mb_to_sects(dev->zone_size);
> +	dev->nr_zones = DIV_ROUND_UP(dev_capacity_sects, dev->zone_size_sects);
>  
>  	dev->zones = kvmalloc_array(dev->nr_zones, sizeof(struct nullb_zone),
>  				    GFP_KERNEL | __GFP_ZERO);
> 

Jens,

Looks like this one has fallen through the cracks...
Could ypu pick it up please ?
Thanks !
Jens Axboe Jan. 29, 2021, 12:10 a.m. UTC | #4
On 1/11/21 8:44 PM, Damien Le Moal wrote:
> To avoid potential compilation problems, replaced the badly written
> MB_TO_SECTS macro (missing parenthesis around the argument use) with
> the inline function mb_to_sects(). And while at it, use DIV_ROUND_UP()
> to calculate the total number of zones of a zoned device, simplifying
> the code.

Sorry missed this, applide for 5.11.
Damien Le Moal Jan. 29, 2021, 12:11 a.m. UTC | #5
On 2021/01/29 9:11, Jens Axboe wrote:
> On 1/11/21 8:44 PM, Damien Le Moal wrote:
>> To avoid potential compilation problems, replaced the badly written
>> MB_TO_SECTS macro (missing parenthesis around the argument use) with
>> the inline function mb_to_sects(). And while at it, use DIV_ROUND_UP()
>> to calculate the total number of zones of a zoned device, simplifying
>> the code.
> 
> Sorry missed this, applide for 5.11.

Thanks !
diff mbox series

Patch

diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c
index 148b871f263b..535351570bb2 100644
--- a/drivers/block/null_blk/zoned.c
+++ b/drivers/block/null_blk/zoned.c
@@ -6,7 +6,10 @@ 
 #define CREATE_TRACE_POINTS
 #include "trace.h"
 
-#define MB_TO_SECTS(mb) (((sector_t)mb * SZ_1M) >> SECTOR_SHIFT)
+static inline sector_t mb_to_sects(unsigned long mb)
+{
+	return ((sector_t)mb * SZ_1M) >> SECTOR_SHIFT;
+}
 
 static inline unsigned int null_zone_no(struct nullb_device *dev, sector_t sect)
 {
@@ -77,12 +80,10 @@  int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q)
 		return -EINVAL;
 	}
 
-	zone_capacity_sects = MB_TO_SECTS(dev->zone_capacity);
-	dev_capacity_sects = MB_TO_SECTS(dev->size);
-	dev->zone_size_sects = MB_TO_SECTS(dev->zone_size);
-	dev->nr_zones = dev_capacity_sects >> ilog2(dev->zone_size_sects);
-	if (dev_capacity_sects & (dev->zone_size_sects - 1))
-		dev->nr_zones++;
+	zone_capacity_sects = mb_to_sects(dev->zone_capacity);
+	dev_capacity_sects = mb_to_sects(dev->size);
+	dev->zone_size_sects = mb_to_sects(dev->zone_size);
+	dev->nr_zones = DIV_ROUND_UP(dev_capacity_sects, dev->zone_size_sects);
 
 	dev->zones = kvmalloc_array(dev->nr_zones, sizeof(struct nullb_zone),
 				    GFP_KERNEL | __GFP_ZERO);