public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@SteelEye.com>
To: "Randy.Dunlap" <rdunlap@xenotime.net>
Cc: scsi <linux-scsi@vger.kernel.org>, akpm <akpm@osdl.org>,
	Dale Blount <linux-kernel@dale.us>
Subject: Re: [PATCH] scsi disk: report size without overflow
Date: Fri, 21 Oct 2005 12:20:49 -0500	[thread overview]
Message-ID: <1129915249.3440.42.camel@mulgrave> (raw)
In-Reply-To: <20051020205532.16b65fa7.rdunlap@xenotime.net>

On Thu, 2005-10-20 at 20:55 -0700, Randy.Dunlap wrote:
> 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>

Mathematically, it doesn't look like we need to use 64 bits at all;
what's wrong with the attached?  It looks like the code once allowed 256
byte sectors, but the if statement above now forbids them.

I'm really not terribly sympathetic to anyone trying Terrabyte discs on
a non-LBD 32 bit kernel.  The potential for overflow (and consequent
data loss) is pretty huge. 

James

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1253,14 +1253,13 @@ got_data:
 		 * Jacques Gelinas (Jacques@solucorp.qc.ca)
 		 */
 		int hard_sector = sector_size;
-		sector_t sz = sdkp->capacity * (hard_sector/256);
+		sector_t sz = sdkp->capacity * (hard_sector/512);
 		request_queue_t *queue = sdp->request_queue;
-		sector_t mb;
+		sector_t mb = sz;
 
 		blk_queue_hardsect_size(queue, hard_sector);
 		/* avoid 64-bit division on 32-bit platforms */
-		mb = sz >> 1;
-		sector_div(sz, 1250);
+		sector_div(sz, 625);
 		mb -= sz - 974;
 		sector_div(mb, 1950);
 



  reply	other threads:[~2005-10-21 17:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-21  3:55 [PATCH] scsi disk: report size without overflow Randy.Dunlap
2005-10-21 17:20 ` James Bottomley [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1129915249.3440.42.camel@mulgrave \
    --to=james.bottomley@steeleye.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@dale.us \
    --cc=linux-scsi@vger.kernel.org \
    --cc=rdunlap@xenotime.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox