public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi disk: report size without overflow
@ 2005-10-21  3:55 Randy.Dunlap
  2005-10-21 17:20 ` James Bottomley
  0 siblings, 1 reply; 7+ messages in thread
From: Randy.Dunlap @ 2005-10-21  3:55 UTC (permalink / raw)
  To: scsi, jejb; +Cc: akpm, Dale Blount

From: Randy Dunlap <rdunlap@xenotime.net>

With CONFIG_LBD=n, 'sz' (32 bits) can overflow when capacity is
multiplied (even * 2), as seen in a report from Dale Blount
on lkml.  Also make sure that 'mb' will not overflow.

Signed-off-by: Randy Dunlap <rdunlap@xenotime.net>
---

 drivers/scsi/sd.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff -Naurp linux-2614-rc5/drivers/scsi/sd.c~scsi_disk_capacity linux-2614-rc5/drivers/scsi/sd.c
--- linux-2614-rc5/drivers/scsi/sd.c~scsi_disk_capacity	2005-10-20 18:55:35.000000000 -0700
+++ linux-2614-rc5/drivers/scsi/sd.c	2005-10-20 20:44:44.000000000 -0700
@@ -49,6 +49,7 @@
 #include <linux/blkpg.h>
 #include <linux/kref.h>
 #include <linux/delay.h>
+#include <asm/div64.h>
 #include <asm/uaccess.h>
 
 #include <scsi/scsi.h>
@@ -1253,16 +1254,16 @@ got_data:
 		 * Jacques Gelinas (Jacques@solucorp.qc.ca)
 		 */
 		int hard_sector = sector_size;
-		sector_t sz = sdkp->capacity * (hard_sector/256);
+		u64 sz = sdkp->capacity * (hard_sector/256);
 		request_queue_t *queue = sdp->request_queue;
-		sector_t mb;
+		u64 mb;
 
 		blk_queue_hardsect_size(queue, hard_sector);
 		/* avoid 64-bit division on 32-bit platforms */
 		mb = sz >> 1;
-		sector_div(sz, 1250);
+		do_div(sz, 1250);
 		mb -= sz - 974;
-		sector_div(mb, 1950);
+		do_div(mb, 1950);
 
 		printk(KERN_NOTICE "SCSI device %s: "
 		       "%llu %d-byte hdwr sectors (%llu MB)\n",


---

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2005-10-22 14:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-21  3:55 [PATCH] scsi disk: report size without overflow Randy.Dunlap
2005-10-21 17:20 ` James Bottomley
2005-10-21 20:46   ` Randy.Dunlap
2005-10-21 21:02     ` Dale Blount
2005-10-22 14:44       ` James Bottomley
2005-10-21 21:17     ` James Bottomley
2005-10-22  2:24       ` Randy.Dunlap

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox