Skip to contentSkip to conversation

scsi: use sector_div instead of do_div

PATCH Applied Arnd Bergmann 5 participants 5 messages Nov 20, 2015 – Nov 26, 2015 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: use sector_div instead of do_div

do_div is the wrong way to divide a sector_t, as it is less efficient when sector_t is 32-bit wide. With the upcoming do_div optimizations, the kernel starts warning about this:

drivers/scsi/scsi_debug.c: In function 'dif_store':
include/asm-generic/div64.h:207:28: warning: comparison of distinct pointer types lacks a cast

This changes the code to use sector_div instead, which always produces optimal code.

---
Found on the ARM randconfig build today, after I merged Nico's patches for linux-next

drivers/scsi/scsi_debug.c +2 -2
index dfcc45bb03b1..ec622ba9864a 100644
@@ -678,7 +678,7 @@ static void *fake_store(unsigned long long lba)
 
 static struct sd_dif_tuple *dif_store(sector_t sector)
 {
-	sector = do_div(sector, sdebug_store_sectors);
+	sector = sector_div(sector, sdebug_store_sectors);
 
 	return dif_storep + sector;
 }
@@ -2780,7 +2780,7 @@ static unsigned long lba_to_map_index(sector_t lba)
 		lba += scsi_debug_unmap_granularity -
 			scsi_debug_unmap_alignment;
 	}
-	do_div(lba, scsi_debug_unmap_granularity);
+	sector_div(lba, scsi_debug_unmap_granularity);
 
 	return lba;
 }
Reviewed-by on v1 1/1
#1 lore raw
Quoted 41 lines · Arnd Bergmann

do_div is the wrong way to divide a sector_t, as it is less efficient when sector_t is 32-bit wide. With the upcoming do_div optimizations, the kernel starts warning about this:

drivers/scsi/scsi_debug.c: In function 'dif_store':
include/asm-generic/div64.h:207:28: warning: comparison of distinct pointer types lacks a cast

This changes the code to use sector_div instead, which always produces optimal code.

---
Found on the ARM randconfig build today, after I merged Nico's patches
for linux-next

drivers/scsi/scsi_debug.c +0 -0
index dfcc45bb03b1..ec622ba9864a 100644
@@ -678,7 +678,7 @@ static void *fake_store(unsigned long long lba)

?
?static struct sd_dif_tuple *dif_store(sector_t sector) ?{

drivers/scsi/scsi_debug.c +1 -1
-	sector = do_div(sector, sdebug_store_sectors);
+	sector = sector_div(sector, sdebug_store_sectors);

?
? return dif_storep + sector;
?}

drivers/scsi/scsi_debug.c +0 -0
@@ -2780,7 +2780,7 @@ static unsigned long lba_to_map_index(sector_t
 lba)

? lba += scsi_debug_unmap_granularity -
? scsi_debug_unmap_alignment;
? }

drivers/scsi/scsi_debug.c +1 -1
-	do_div(lba, scsi_debug_unmap_granularity);
+	sector_div(lba, scsi_debug_unmap_granularity);

?
? return lba;
?}

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at??http://vger.kernel.org/majordomo-info.html

Reviewed-by on v1 1/1
#2 lore raw
In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann

do_div is the wrong way to divide a sector_t, as it is less efficient when sector_t is 32-bit wide. With the upcoming do_div optimizations, the kernel starts warning about this:

drivers/scsi/scsi_debug.c: In function 'dif_store':
include/asm-generic/div64.h:207:28: warning: comparison of distinct pointer types lacks a cast

This changes the code to use sector_div instead, which always produces optimal code.

Reviewed-by on v1 1/1
#3 lore raw
In reply to Arnd Bergmann
Quoted 30 lines · Arnd Bergmann

do_div is the wrong way to divide a sector_t, as it is less efficient when sector_t is 32-bit wide. With the upcoming do_div optimizations, the kernel starts warning about this:

drivers/scsi/scsi_debug.c: In function 'dif_store':
include/asm-generic/div64.h:207:28: warning: comparison of distinct pointer types lacks a cast

This changes the code to use sector_div instead, which always produces optimal code.

---
Found on the ARM randconfig build today, after I merged Nico's patches for linux-next

drivers/scsi/scsi_debug.c +1 -1
index dfcc45bb03b1..ec622ba9864a 100644
@@ -678,7 +678,7 @@ static void *fake_store(unsigned long long lba)
 
 static struct sd_dif_tuple *dif_store(sector_t sector)
 {
-	sector = do_div(sector, sdebug_store_sectors);
+	sector = sector_div(sector, sdebug_store_sectors);
 
 	return dif_storep + sector;
 }

drivers/scsi/scsi_debug.c static unsigned long lba_to_map_index(sector_t lba) · line 2786

Quoted 8 lines
drivers/scsi/scsi_debug.c +1 -1
@@ -2780,7 +2780,7 @@ static unsigned long lba_to_map_index(sector_t lba)
 		lba += scsi_debug_unmap_granularity -
 			scsi_debug_unmap_alignment;
 	}
-	do_div(lba, scsi_debug_unmap_granularity);
+	sector_div(lba, scsi_debug_unmap_granularity);
 
 	return lba;
 }

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		               zSeries & Storage
hare at suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: F. Imend?rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG N?rnberg)
#4 lore raw
In reply to Arnd Bergmann
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Arnd" == Arnd Bergmann <[email protected]> writes:

Arnd> do_div is the wrong way to divide a sector_t, as it is less Arnd> efficient when sector_t is 32-bit wide. With the upcoming do_div Arnd> optimizations, the kernel starts warning about this:

Applied.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering