From: Namhyung Kim <namhyung@gmail.com>
To: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] [SCSI] sd: consolidate sector size alignment check in sd_prep_fn
Date: Wed, 3 Aug 2011 10:03:24 +0900 [thread overview]
Message-ID: <1312333404-3088-1-git-send-email-namhyung@gmail.com> (raw)
In-Reply-To: <1312302550.11352.9.camel@mulgrave>
Generalize common code to reduce code duplication.
Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
drivers/scsi/sd.c | 36 ++++++++++++------------------------
1 files changed, 12 insertions(+), 24 deletions(-)
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 953773cb26d9..fb9d997ece9d 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -651,6 +651,7 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
unsigned int this_count = blk_rq_sectors(rq);
int ret, host_dif;
unsigned char protect;
+ int sector_shift;
/*
* Discard request come in as REQ_TYPE_FS but we turn them into
@@ -735,36 +736,23 @@ 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)) {
+ sector_shift = 0;
+ switch (sdp->sector_size) {
+ case 4096: sector_shift++; /* fall through */
+ case 2048: sector_shift++; /* fall through */
+ case 1024: sector_shift++;
+
+ if (!IS_ALIGNED(block, 1 << sector_shift) ||
+ !IS_ALIGNED(blk_rq_sectors(rq), 1 << sector_shift)) {
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)) {
- scmd_printk(KERN_ERR, SCpnt,
- "Bad block number requested\n");
- goto out;
- } else {
- block = block >> 3;
- this_count = this_count >> 3;
+ block = block >> sector_shift;
+ this_count = this_count >> sector_shift;
}
}
+
if (rq_data_dir(rq) == WRITE) {
if (!sdp->writeable) {
goto out;
--
1.7.6
prev parent reply other threads:[~2011-08-03 1:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Namhyung Kim [this message]
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=1312333404-3088-1-git-send-email-namhyung@gmail.com \
--to=namhyung@gmail.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
/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