From patchwork Wed Jan 16 00:49:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10765265 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E984913A4 for ; Wed, 16 Jan 2019 00:50:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D71722A1B9 for ; Wed, 16 Jan 2019 00:50:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB25A2E23C; Wed, 16 Jan 2019 00:50:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6EA32A1B9 for ; Wed, 16 Jan 2019 00:50:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727094AbfAPAul (ORCPT ); Tue, 15 Jan 2019 19:50:41 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:54573 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726646AbfAPAuk (ORCPT ); Tue, 15 Jan 2019 19:50:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=lFI8aUBFst2ey9moxp7gY7XZq+3f8rkhPGaM7q46OTQ=; b=b94ieb520ojB 3NC1yuLxkYsQgd0cisyBdIDNypD9y/MWrqoLmCmtwCQmaUQselva0f94auxE5LHJInlduYaHdCSUP b9y82/3dD3UhdL18NGTFsKXSS30SkL7czxRWUWPizw1gHAJG6TCiPp0p/nuPl1hhfXLhVfUbQQ9fo UbSTQkdK6fkqRNTdK7aCoUIc9SimFQaQGps2/xi3OrWqKJExeCpSygdr/R4irReEnIaEy+sLgD4Vr oyIbrM2uYd77HVzukelW7DnYhnWyDecwQ/O9BaVIGsuHZqqKp1xIDSniWEL5pjGhd27i+3cVDFFQB QLQn4GJJYwmlsvb3WlYzBQ==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gjZPb-0006Py-Hw; Wed, 16 Jan 2019 01:50:31 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 3023CC0838; Wed, 16 Jan 2019 01:50:16 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Hannes Reinecke Subject: [PATCH v2 2/7] sd: Be consistent about blocks vs. sectors Date: Tue, 15 Jan 2019 16:49:58 -0800 Message-Id: <20190116005003.230678-3-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog In-Reply-To: <20190116005003.230678-1-bvanassche@acm.org> References: <20190116005003.230678-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.00442456685346) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5ndSi2UOCM7PZV+ZQfraUNd602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTbBu5YFz4Jx0uq4149LpZwrkOR4/HajlzkVhakIw7Ig6RAJ lmpPd1BHwQ+kdrsiFH2cfUiCXtJytJdYVIlBCNoVg5+MMxHz1qQag3kpom3W/e94I33w2HmOCspO DckV+F+3wL2Y4F0412ezGCyTUPan0uklXEw37uMwN0/87jeHA1yAA48E18cja8iRHYDwyLIiwKLX T1N2MSH7GZ5RD1hGCbBzkh9OM/IQZX4UQ+0M5PcjPpm+mbxw9CcA3CQNDkFXB5UJrhTKjy92DTI6 8h3SnQmqYLjdEEIOK2vMtDcOIv6swqwgYQJviKY5/kNaTaa5Pkqio+WL8yLJH3B4G7qkcHsvFjae yZBKVj4s5LZEG/K9gXjVgrC1QcAgdzCQzBT9wRRkuvoiB4YsCfofouncNB4U2glErAJuIw/B9005 oAzEEJbreAQRsbSZZ9fXoUEifL76GD10kuo3nOZaoX+gsjENmEszkjZCjfYHwrdvNJlAR4VG1al3 V9+D6kte4sxnIKDFkcg0DoDn7tP2jpvLEQHXccWQ/x1965yjUk8rE9vpo2UgV9PP0GtOSQCD3Wp6 EipRzMVZ5LqwTx7Vvn9SWQRihqWRcCaa7yMGNcHiKmhXELglXPvXwY+m2hjhWXXhGUHq6zkhvAQI TbAoA+S9pj/j6xvaV3aquTDp0QDpLQeYUOp7A73HI6oJg7w/Vofg3oXo1l/v5aKY1zkbZm/DmoYV E/p9MbBpvhj6CNw5Cvqe0XEshFuK/GpNT7ar8xuaF/P4oRariZP4h22zsTekMDRcCgYQIezXimM8 MMGBqZ+MpTJWssqhJzGoox2dERA6xU+LYu8ZqEwbY4QIgPU/PUjlOCcnjE3PyvEckqyuEoD/UhoV 7BDkUqX6OOzSXSCrBF+Rr7gD/PbbEd/imcyVNwpU15Un0FfK735x4KpOFCcHL8+lTGBIVE9xbEkX 79s8o4XELc8yJ4QkhrPnLpRW2GNGz3siphBNPRLkjfE26R1/rxbQicf/5tMwo2bfwweqYtYE+WQ7 6HhyFntm2v6MQik4xcszxqBpk9lxB93ijjZAaWYpI6FpE9hPAWtgQ1UxL7hrJSk60SF3F6RYOYr2 X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "Martin K. Petersen" We have had several bugs due mixing sector and logical block size terminology. In the block layer, a sector is a 512-byte unit regardless of the logical block size of the underlying device. But the term "sector" is still widely used in sd.c when referring to logical block sized units. We previously introduced helper functions such as sectors_to_logical() and logical_to_sectors() to make the distinction clear. Use these to make the code in sd.c consistent wrt. logical blocks and block layer sectors. Use "lba" to describe a logical block address and "nr_blocks" when counting logical blocks. SBC uses "TRANSFER LENGTH" to describe the latter but this term was avoided to prevent confusion with the very similar DMA transfer size (->transfersize) which is counted in bytes. Reviewed-by: Hannes Reinecke Signed-off-by: Martin K. Petersen [ bvanassche: ported this patch from kernel v4.11 to kernel v5.0 ] Signed-off-by: Bart Van Assche --- drivers/scsi/sd.c | 169 +++++++++++++++++++++++----------------------- 1 file changed, 83 insertions(+), 86 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index a60b98681f15..4d14208fe6db 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -817,8 +817,8 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd) { struct scsi_device *sdp = cmd->device; struct request *rq = cmd->request; - u64 sector = blk_rq_pos(rq) >> (ilog2(sdp->sector_size) - 9); - u32 nr_sectors = blk_rq_sectors(rq) >> (ilog2(sdp->sector_size) - 9); + u64 lba = sectors_to_logical(sdp, blk_rq_pos(rq)); + u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); unsigned int data_len = 24; char *buf; @@ -837,8 +837,8 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd) buf = page_address(rq->special_vec.bv_page); put_unaligned_be16(6 + 16, &buf[0]); put_unaligned_be16(16, &buf[2]); - put_unaligned_be64(sector, &buf[8]); - put_unaligned_be32(nr_sectors, &buf[16]); + put_unaligned_be64(lba, &buf[8]); + put_unaligned_be32(nr_blocks, &buf[16]); cmd->allowed = SD_MAX_RETRIES; cmd->transfersize = data_len; @@ -853,8 +853,8 @@ static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd, { struct scsi_device *sdp = cmd->device; struct request *rq = cmd->request; - u64 sector = blk_rq_pos(rq) >> (ilog2(sdp->sector_size) - 9); - u32 nr_sectors = blk_rq_sectors(rq) >> (ilog2(sdp->sector_size) - 9); + u64 lba = sectors_to_logical(sdp, blk_rq_pos(rq)); + u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); u32 data_len = sdp->sector_size; rq->special_vec.bv_page = mempool_alloc(sd_page_pool, GFP_ATOMIC); @@ -869,8 +869,8 @@ static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd, cmd->cmnd[0] = WRITE_SAME_16; if (unmap) cmd->cmnd[1] = 0x8; /* UNMAP */ - put_unaligned_be64(sector, &cmd->cmnd[2]); - put_unaligned_be32(nr_sectors, &cmd->cmnd[10]); + put_unaligned_be64(lba, &cmd->cmnd[2]); + put_unaligned_be32(nr_blocks, &cmd->cmnd[10]); cmd->allowed = SD_MAX_RETRIES; cmd->transfersize = data_len; @@ -885,8 +885,8 @@ static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd, { struct scsi_device *sdp = cmd->device; struct request *rq = cmd->request; - u64 sector = blk_rq_pos(rq) >> (ilog2(sdp->sector_size) - 9); - u32 nr_sectors = blk_rq_sectors(rq) >> (ilog2(sdp->sector_size) - 9); + u64 lba = sectors_to_logical(sdp, blk_rq_pos(rq)); + u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); u32 data_len = sdp->sector_size; rq->special_vec.bv_page = mempool_alloc(sd_page_pool, GFP_ATOMIC); @@ -901,8 +901,8 @@ static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd, cmd->cmnd[0] = WRITE_SAME; if (unmap) cmd->cmnd[1] = 0x8; /* UNMAP */ - put_unaligned_be32(sector, &cmd->cmnd[2]); - put_unaligned_be16(nr_sectors, &cmd->cmnd[7]); + put_unaligned_be32(lba, &cmd->cmnd[2]); + put_unaligned_be16(nr_blocks, &cmd->cmnd[7]); cmd->allowed = SD_MAX_RETRIES; cmd->transfersize = data_len; @@ -917,8 +917,8 @@ static blk_status_t sd_setup_write_zeroes_cmnd(struct scsi_cmnd *cmd) struct request *rq = cmd->request; struct scsi_device *sdp = cmd->device; struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); - u64 sector = blk_rq_pos(rq) >> (ilog2(sdp->sector_size) - 9); - u32 nr_sectors = blk_rq_sectors(rq) >> (ilog2(sdp->sector_size) - 9); + u64 lba = sectors_to_logical(sdp, blk_rq_pos(rq)); + u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); if (!(rq->cmd_flags & REQ_NOUNMAP)) { switch (sdkp->zeroing_mode) { @@ -932,7 +932,7 @@ static blk_status_t sd_setup_write_zeroes_cmnd(struct scsi_cmnd *cmd) if (sdp->no_write_same) return BLK_STS_TARGET; - if (sdkp->ws16 || sector > 0xffffffff || nr_sectors > 0xffff) + if (sdkp->ws16 || lba > 0xffffffff || nr_blocks > 0xffff) return sd_setup_write_same16_cmnd(cmd, false); return sd_setup_write_same10_cmnd(cmd, false); @@ -1013,8 +1013,8 @@ static blk_status_t sd_setup_write_same_cmnd(struct scsi_cmnd *cmd) struct scsi_device *sdp = cmd->device; struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); struct bio *bio = rq->bio; - sector_t sector = blk_rq_pos(rq); - unsigned int nr_sectors = blk_rq_sectors(rq); + u64 lba = sectors_to_logical(sdp, blk_rq_pos(rq)); + u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); blk_status_t ret; if (sdkp->device->no_write_same) @@ -1022,21 +1022,18 @@ static blk_status_t sd_setup_write_same_cmnd(struct scsi_cmnd *cmd) BUG_ON(bio_offset(bio) || bio_iovec(bio).bv_len != sdp->sector_size); - sector >>= ilog2(sdp->sector_size) - 9; - nr_sectors >>= ilog2(sdp->sector_size) - 9; - rq->timeout = SD_WRITE_SAME_TIMEOUT; - if (sdkp->ws16 || sector > 0xffffffff || nr_sectors > 0xffff) { + if (sdkp->ws16 || lba > 0xffffffff || nr_blocks > 0xffff) { cmd->cmd_len = 16; cmd->cmnd[0] = WRITE_SAME_16; - put_unaligned_be64(sector, &cmd->cmnd[2]); - put_unaligned_be32(nr_sectors, &cmd->cmnd[10]); + put_unaligned_be64(lba, &cmd->cmnd[2]); + put_unaligned_be32(nr_blocks, &cmd->cmnd[10]); } else { cmd->cmd_len = 10; cmd->cmnd[0] = WRITE_SAME; - put_unaligned_be32(sector, &cmd->cmnd[2]); - put_unaligned_be16(nr_sectors, &cmd->cmnd[7]); + put_unaligned_be32(lba, &cmd->cmnd[2]); + put_unaligned_be16(nr_blocks, &cmd->cmnd[7]); } cmd->transfersize = sdp->sector_size; @@ -1081,9 +1078,9 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) struct scsi_device *sdp = SCpnt->device; struct gendisk *disk = rq->rq_disk; struct scsi_disk *sdkp = scsi_disk(disk); - sector_t block = blk_rq_pos(rq); + sector_t lba = blk_rq_pos(rq); sector_t threshold; - unsigned int this_count = blk_rq_sectors(rq); + unsigned int nr_blocks = blk_rq_sectors(rq); unsigned int dif, dix; unsigned char protect; blk_status_t ret; @@ -1096,10 +1093,10 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) SCSI_LOG_HLQUEUE(1, scmd_printk(KERN_INFO, SCpnt, "%s: block=%llu, count=%d\n", - __func__, (unsigned long long)block, this_count)); + __func__, (unsigned long long)lba, nr_blocks)); if (!sdp || !scsi_device_online(sdp) || - block + blk_rq_sectors(rq) > get_capacity(disk)) { + lba + blk_rq_sectors(rq) > get_capacity(disk)) { SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt, "Finishing %u sectors\n", blk_rq_sectors(rq))); @@ -1124,18 +1121,18 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) threshold = get_capacity(disk) - SD_LAST_BUGGY_SECTORS * (sdp->sector_size / 512); - if (unlikely(sdp->last_sector_bug && block + this_count > threshold)) { - if (block < threshold) { + if (unlikely(sdp->last_sector_bug && lba + nr_blocks > threshold)) { + if (lba < threshold) { /* Access up to the threshold but not beyond */ - this_count = threshold - block; + nr_blocks = threshold - lba; } else { /* Access only a single hardware sector */ - this_count = sdp->sector_size / 512; + nr_blocks = sdp->sector_size / 512; } } SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt, "block=%llu\n", - (unsigned long long)block)); + (unsigned long long)lba)); /* * If we have a 1K hardware sectorsize, prevent access to single @@ -1149,31 +1146,31 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) * for this. */ if (sdp->sector_size == 1024) { - if ((block & 1) || (blk_rq_sectors(rq) & 1)) { + if ((lba & 1) || (blk_rq_sectors(rq) & 1)) { scmd_printk(KERN_ERR, SCpnt, "Bad block number requested\n"); return BLK_STS_IOERR; } - block = block >> 1; - this_count = this_count >> 1; + lba = lba >> 1; + nr_blocks = nr_blocks >> 1; } if (sdp->sector_size == 2048) { - if ((block & 3) || (blk_rq_sectors(rq) & 3)) { + if ((lba & 3) || (blk_rq_sectors(rq) & 3)) { scmd_printk(KERN_ERR, SCpnt, "Bad block number requested\n"); return BLK_STS_IOERR; } - block = block >> 2; - this_count = this_count >> 2; + lba = lba >> 2; + nr_blocks = nr_blocks >> 2; } if (sdp->sector_size == 4096) { - if ((block & 7) || (blk_rq_sectors(rq) & 7)) { + if ((lba & 7) || (blk_rq_sectors(rq) & 7)) { scmd_printk(KERN_ERR, SCpnt, "Bad block number requested\n"); return BLK_STS_IOERR; } - block = block >> 3; - this_count = this_count >> 3; + lba = lba >> 3; + nr_blocks = nr_blocks >> 3; } if (rq_data_dir(rq) == WRITE) { SCpnt->cmnd[0] = WRITE_6; @@ -1191,7 +1188,7 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt, "%s %d/%u 512 byte blocks.\n", (rq_data_dir(rq) == WRITE) ? - "writing" : "reading", this_count, + "writing" : "reading", nr_blocks, blk_rq_sectors(rq))); dix = scsi_prot_sg_count(SCpnt); @@ -1216,54 +1213,54 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) SCpnt->cmnd[10] = protect | ((rq->cmd_flags & REQ_FUA) ? 0x8 : 0); /* LBA */ - SCpnt->cmnd[12] = sizeof(block) > 4 ? (unsigned char) (block >> 56) & 0xff : 0; - SCpnt->cmnd[13] = sizeof(block) > 4 ? (unsigned char) (block >> 48) & 0xff : 0; - SCpnt->cmnd[14] = sizeof(block) > 4 ? (unsigned char) (block >> 40) & 0xff : 0; - SCpnt->cmnd[15] = sizeof(block) > 4 ? (unsigned char) (block >> 32) & 0xff : 0; - SCpnt->cmnd[16] = (unsigned char) (block >> 24) & 0xff; - SCpnt->cmnd[17] = (unsigned char) (block >> 16) & 0xff; - SCpnt->cmnd[18] = (unsigned char) (block >> 8) & 0xff; - SCpnt->cmnd[19] = (unsigned char) block & 0xff; + SCpnt->cmnd[12] = sizeof(lba) > 4 ? (unsigned char) (lba >> 56) & 0xff : 0; + SCpnt->cmnd[13] = sizeof(lba) > 4 ? (unsigned char) (lba >> 48) & 0xff : 0; + SCpnt->cmnd[14] = sizeof(lba) > 4 ? (unsigned char) (lba >> 40) & 0xff : 0; + SCpnt->cmnd[15] = sizeof(lba) > 4 ? (unsigned char) (lba >> 32) & 0xff : 0; + SCpnt->cmnd[16] = (unsigned char) (lba >> 24) & 0xff; + SCpnt->cmnd[17] = (unsigned char) (lba >> 16) & 0xff; + SCpnt->cmnd[18] = (unsigned char) (lba >> 8) & 0xff; + SCpnt->cmnd[19] = (unsigned char) lba & 0xff; /* Expected Indirect LBA */ - SCpnt->cmnd[20] = (unsigned char) (block >> 24) & 0xff; - SCpnt->cmnd[21] = (unsigned char) (block >> 16) & 0xff; - SCpnt->cmnd[22] = (unsigned char) (block >> 8) & 0xff; - SCpnt->cmnd[23] = (unsigned char) block & 0xff; + SCpnt->cmnd[20] = (unsigned char) (lba >> 24) & 0xff; + SCpnt->cmnd[21] = (unsigned char) (lba >> 16) & 0xff; + SCpnt->cmnd[22] = (unsigned char) (lba >> 8) & 0xff; + SCpnt->cmnd[23] = (unsigned char) lba & 0xff; /* Transfer length */ - SCpnt->cmnd[28] = (unsigned char) (this_count >> 24) & 0xff; - SCpnt->cmnd[29] = (unsigned char) (this_count >> 16) & 0xff; - SCpnt->cmnd[30] = (unsigned char) (this_count >> 8) & 0xff; - SCpnt->cmnd[31] = (unsigned char) this_count & 0xff; - } else if (sdp->use_16_for_rw || (this_count > 0xffff)) { + SCpnt->cmnd[28] = (unsigned char) (nr_blocks >> 24) & 0xff; + SCpnt->cmnd[29] = (unsigned char) (nr_blocks >> 16) & 0xff; + SCpnt->cmnd[30] = (unsigned char) (nr_blocks >> 8) & 0xff; + SCpnt->cmnd[31] = (unsigned char) nr_blocks & 0xff; + } else if (sdp->use_16_for_rw || (nr_blocks > 0xffff)) { SCpnt->cmnd[0] += READ_16 - READ_6; SCpnt->cmnd[1] = protect | ((rq->cmd_flags & REQ_FUA) ? 0x8 : 0); - SCpnt->cmnd[2] = sizeof(block) > 4 ? (unsigned char) (block >> 56) & 0xff : 0; - SCpnt->cmnd[3] = sizeof(block) > 4 ? (unsigned char) (block >> 48) & 0xff : 0; - SCpnt->cmnd[4] = sizeof(block) > 4 ? (unsigned char) (block >> 40) & 0xff : 0; - SCpnt->cmnd[5] = sizeof(block) > 4 ? (unsigned char) (block >> 32) & 0xff : 0; - SCpnt->cmnd[6] = (unsigned char) (block >> 24) & 0xff; - SCpnt->cmnd[7] = (unsigned char) (block >> 16) & 0xff; - SCpnt->cmnd[8] = (unsigned char) (block >> 8) & 0xff; - SCpnt->cmnd[9] = (unsigned char) block & 0xff; - SCpnt->cmnd[10] = (unsigned char) (this_count >> 24) & 0xff; - SCpnt->cmnd[11] = (unsigned char) (this_count >> 16) & 0xff; - SCpnt->cmnd[12] = (unsigned char) (this_count >> 8) & 0xff; - SCpnt->cmnd[13] = (unsigned char) this_count & 0xff; + SCpnt->cmnd[2] = sizeof(lba) > 4 ? (unsigned char) (lba >> 56) & 0xff : 0; + SCpnt->cmnd[3] = sizeof(lba) > 4 ? (unsigned char) (lba >> 48) & 0xff : 0; + SCpnt->cmnd[4] = sizeof(lba) > 4 ? (unsigned char) (lba >> 40) & 0xff : 0; + SCpnt->cmnd[5] = sizeof(lba) > 4 ? (unsigned char) (lba >> 32) & 0xff : 0; + SCpnt->cmnd[6] = (unsigned char) (lba >> 24) & 0xff; + SCpnt->cmnd[7] = (unsigned char) (lba >> 16) & 0xff; + SCpnt->cmnd[8] = (unsigned char) (lba >> 8) & 0xff; + SCpnt->cmnd[9] = (unsigned char) lba & 0xff; + SCpnt->cmnd[10] = (unsigned char) (nr_blocks >> 24) & 0xff; + SCpnt->cmnd[11] = (unsigned char) (nr_blocks >> 16) & 0xff; + SCpnt->cmnd[12] = (unsigned char) (nr_blocks >> 8) & 0xff; + SCpnt->cmnd[13] = (unsigned char) nr_blocks & 0xff; SCpnt->cmnd[14] = SCpnt->cmnd[15] = 0; - } else if ((this_count > 0xff) || (block > 0x1fffff) || + } else if ((nr_blocks > 0xff) || (lba > 0x1fffff) || scsi_device_protection(SCpnt->device) || SCpnt->device->use_10_for_rw) { SCpnt->cmnd[0] += READ_10 - READ_6; SCpnt->cmnd[1] = protect | ((rq->cmd_flags & REQ_FUA) ? 0x8 : 0); - SCpnt->cmnd[2] = (unsigned char) (block >> 24) & 0xff; - SCpnt->cmnd[3] = (unsigned char) (block >> 16) & 0xff; - SCpnt->cmnd[4] = (unsigned char) (block >> 8) & 0xff; - SCpnt->cmnd[5] = (unsigned char) block & 0xff; + SCpnt->cmnd[2] = (unsigned char) (lba >> 24) & 0xff; + SCpnt->cmnd[3] = (unsigned char) (lba >> 16) & 0xff; + SCpnt->cmnd[4] = (unsigned char) (lba >> 8) & 0xff; + SCpnt->cmnd[5] = (unsigned char) lba & 0xff; SCpnt->cmnd[6] = SCpnt->cmnd[9] = 0; - SCpnt->cmnd[7] = (unsigned char) (this_count >> 8) & 0xff; - SCpnt->cmnd[8] = (unsigned char) this_count & 0xff; + SCpnt->cmnd[7] = (unsigned char) (nr_blocks >> 8) & 0xff; + SCpnt->cmnd[8] = (unsigned char) nr_blocks & 0xff; } else { if (unlikely(rq->cmd_flags & REQ_FUA)) { /* @@ -1277,13 +1274,13 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) return BLK_STS_IOERR; } - SCpnt->cmnd[1] |= (unsigned char) ((block >> 16) & 0x1f); - SCpnt->cmnd[2] = (unsigned char) ((block >> 8) & 0xff); - SCpnt->cmnd[3] = (unsigned char) block & 0xff; - SCpnt->cmnd[4] = (unsigned char) this_count; + SCpnt->cmnd[1] |= (unsigned char) ((lba >> 16) & 0x1f); + SCpnt->cmnd[2] = (unsigned char) ((lba >> 8) & 0xff); + SCpnt->cmnd[3] = (unsigned char) lba & 0xff; + SCpnt->cmnd[4] = (unsigned char) nr_blocks; SCpnt->cmnd[5] = 0; } - SCpnt->sdb.length = this_count * sdp->sector_size; + SCpnt->sdb.length = nr_blocks * sdp->sector_size; /* * We shouldn't disconnect in the middle of a sector, so with a dumb @@ -1291,7 +1288,7 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) * this many bytes between each connect / disconnect. */ SCpnt->transfersize = sdp->sector_size; - SCpnt->underflow = this_count << 9; + SCpnt->underflow = nr_blocks << 9; SCpnt->allowed = SD_MAX_RETRIES; /*