public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] [SCSI] sd: consolidate sector size alignment check in sd_pref_fn
@ 2011-08-02  3:50 Namhyung Kim
  2011-08-02  3:50 ` [PATCH 2/3] [SCSI] sd: remove dead code Namhyung Kim
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Namhyung Kim @ 2011-08-02  3:50 UTC (permalink / raw)
  To: James E.J. Bottomley; +Cc: linux-scsi, linux-kernel

Generalize common code to reduce code duplication.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
 drivers/scsi/sd.c |   32 ++++++++------------------------
 1 files changed, 8 insertions(+), 24 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 953773cb26d9..463a324835f4 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -735,36 +735,20 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
 	 * and not force the scsi disk driver to use bounce buffers
 	 * for this.
 	 */
-	if (sdp->sector_size == 1024) {
-		if ((block & 1) || (blk_rq_sectors(rq) & 1)) {
-			scmd_printk(KERN_ERR, SCpnt,
-				    "Bad block number requested\n");
-			goto out;
-		} else {
-			block = block >> 1;
-			this_count = this_count >> 1;
-		}
-	}
-	if (sdp->sector_size == 2048) {
-		if ((block & 3) || (blk_rq_sectors(rq) & 3)) {
-			scmd_printk(KERN_ERR, SCpnt,
-				    "Bad block number requested\n");
-			goto out;
-		} else {
-			block = block >> 2;
-			this_count = this_count >> 2;
-		}
-	}
-	if (sdp->sector_size == 4096) {
-		if ((block & 7) || (blk_rq_sectors(rq) & 7)) {
+	if (sdp->sector_size > 512) {
+		int shift = ilog2(sdp->sector_size) - 9;
+
+		if (!IS_ALIGNED(block, 1 << shift) ||
+		    !IS_ALIGNED(blk_rq_sectors(rq), 1 << shift)) {
 			scmd_printk(KERN_ERR, SCpnt,
 				    "Bad block number requested\n");
 			goto out;
 		} else {
-			block = block >> 3;
-			this_count = this_count >> 3;
+			block = block >> shift;
+			this_count = this_count >> shift;
 		}
 	}
+
 	if (rq_data_dir(rq) == WRITE) {
 		if (!sdp->writeable) {
 			goto out;
-- 
1.7.6


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

end of thread, other threads:[~2011-08-03  1:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-02  3:50 [PATCH 1/3] [SCSI] sd: consolidate sector size alignment check in sd_pref_fn Namhyung Kim
2011-08-02  3:50 ` [PATCH 2/3] [SCSI] sd: remove dead code Namhyung Kim
2011-08-02 16:29   ` James Bottomley
2011-08-02  3:50 ` [PATCH 3/3] [SCSI] sd: update kernel doc comments Namhyung Kim
2011-08-02 16:29 ` [PATCH 1/3] [SCSI] sd: consolidate sector size alignment check in sd_pref_fn James Bottomley
2011-08-03  1:03   ` [PATCH v2] [SCSI] sd: consolidate sector size alignment check in sd_prep_fn Namhyung Kim

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