libnvdimm, badrange: replace div_u64_rem with DIV_ROUND_UP
PATCH v2 1/1 libnvdimm, badrange: replace div_u64_rem with DIV_ROUND_UP
__add_badblock_range use div_u64_rem to round up end_sector and it will introduces unnecessary rem define and costly '%' operation. So clean it with DIV_ROUND_UP.
Signed-off-by Kemeng Shi <[email protected]>
---V1->V2:
-- fix that end_sector is assigned twice, sorry for that.
drivers/nvdimm/badrange.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/nvdimm/badrange.c +1 -4
@@ -187,12 +187,9 @@ static void __add_badblock_range(struct badblocks *bb, u64 ns_offset, u64 len)const unsigned int sector_size =512 ;sector_t start_sector, end_sector;u64 num_sectors; -u32 rem; start_sector =div_u64 (ns_offset, sector_size); - end_sector =div_u64_rem (ns_offset + len, sector_size, &rem); -if (rem) - end_sector++; + end_sector =DIV_ROUND_UP (ns_offset + len, sector_size); num_sectors = end_sector - start_sector;if (unlikely (num_sectors > (u64 )INT_MAX )) {
Signature · 5 lines
2.23.0 -- Best wishes Kemeng Shi
A gentle ping
Quoted 31 lines · Kemeng Shi
__add_badblock_rangeusediv_u64_remto round upend_sectorand it will introduces unnecessary rem define and costly '%' operation. So clean it withDIV_ROUND_UP.Signed-off-by Kemeng Shi <[email protected]>---
V1->V2:
-- fix thatend_sectoris assigned twice, sorry for that.drivers/nvdimm/badrange.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/nvdimm/badrange.c +1
-4@@ -187,12 +187,9 @@ static void __add_badblock_range(struct badblocks *bb, u64 ns_offset, u64 len)const unsigned int sector_size =512 ;sector_t start_sector, end_sector;u64 num_sectors; -u32 rem; start_sector =div_u64 (ns_offset, sector_size); - end_sector =div_u64_rem (ns_offset + len, sector_size, &rem); -if (rem) - end_sector++; + end_sector =DIV_ROUND_UP (ns_offset + len, sector_size); num_sectors = end_sector - start_sector;if (unlikely (num_sectors > (u64 )INT_MAX )) {
Signature · 2 lines
Best wishes Kemeng Shi