diff options
author | Matthew Wilcox <matthew.r.wilcox@intel.com> | 2013-03-27 21:28:22 -0400 |
---|---|---|
committer | Matthew Wilcox <matthew.r.wilcox@intel.com> | 2013-04-16 15:05:22 -0400 |
commit | 063cc6d5591ea9c0631b81ac5c7b829d99738b2f (patch) | |
tree | 5a61528a0a76394666fdc42d6b51bf576a7c1002 | |
parent | acb7aa0db09b8abd38abeb84334a8a27a52fbb1b (diff) |
NVMe: Abstract out sector to block number conversion
Introduce nvme_block_nr() to help convert sectors to block numbers.
This fixes an integer overflow in the SCSI conversion layer, and it's
slightly less typing than opencoding it.
Signed-off-by: Matthew Wilcox <matthew.r.wilcox@intel.com>
Acked-by: Keith Busch <keith.busch@intel.com>
-rw-r--r-- | drivers/block/nvme-core.c | 4 | ||||
-rw-r--r-- | drivers/block/nvme-scsi.c | 2 | ||||
-rw-r--r-- | include/linux/nvme.h | 5 |
3 files changed, 8 insertions, 3 deletions
diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c index 32fdfe9a5156..f3ea52aa3e5d 100644 --- a/drivers/block/nvme-core.c +++ b/drivers/block/nvme-core.c | |||
@@ -477,7 +477,7 @@ static int nvme_submit_discard(struct nvme_queue *nvmeq, struct nvme_ns *ns, | |||
477 | 477 | ||
478 | range->cattr = cpu_to_le32(0); | 478 | range->cattr = cpu_to_le32(0); |
479 | range->nlb = cpu_to_le32(bio->bi_size >> ns->lba_shift); | 479 | range->nlb = cpu_to_le32(bio->bi_size >> ns->lba_shift); |
480 | range->slba = cpu_to_le64(bio->bi_sector >> (ns->lba_shift - 9)); | 480 | range->slba = cpu_to_le64(nvme_block_nr(ns, bio->bi_sector)); |
481 | 481 | ||
482 | memset(cmnd, 0, sizeof(*cmnd)); | 482 | memset(cmnd, 0, sizeof(*cmnd)); |
483 | cmnd->dsm.opcode = nvme_cmd_dsm; | 483 | cmnd->dsm.opcode = nvme_cmd_dsm; |
@@ -590,7 +590,7 @@ static int nvme_submit_bio_queue(struct nvme_queue *nvmeq, struct nvme_ns *ns, | |||
590 | cmnd->rw.nsid = cpu_to_le32(ns->ns_id); | 590 | cmnd->rw.nsid = cpu_to_le32(ns->ns_id); |
591 | length = nvme_setup_prps(nvmeq->dev, &cmnd->common, iod, length, | 591 | length = nvme_setup_prps(nvmeq->dev, &cmnd->common, iod, length, |
592 | GFP_ATOMIC); | 592 | GFP_ATOMIC); |
593 | cmnd->rw.slba = cpu_to_le64(bio->bi_sector >> (ns->lba_shift - 9)); | 593 | cmnd->rw.slba = cpu_to_le64(nvme_block_nr(ns, bio->bi_sector)); |
594 | cmnd->rw.length = cpu_to_le16((length >> ns->lba_shift) - 1); | 594 | cmnd->rw.length = cpu_to_le16((length >> ns->lba_shift) - 1); |
595 | cmnd->rw.control = cpu_to_le16(control); | 595 | cmnd->rw.control = cpu_to_le16(control); |
596 | cmnd->rw.dsmgmt = cpu_to_le32(dsmgmt); | 596 | cmnd->rw.dsmgmt = cpu_to_le32(dsmgmt); |
diff --git a/drivers/block/nvme-scsi.c b/drivers/block/nvme-scsi.c index 483af3585c92..db7052ea8d0d 100644 --- a/drivers/block/nvme-scsi.c +++ b/drivers/block/nvme-scsi.c | |||
@@ -2040,7 +2040,7 @@ static int nvme_trans_do_nvme_io(struct nvme_ns *ns, struct sg_io_hdr *hdr, | |||
2040 | struct nvme_command c; | 2040 | struct nvme_command c; |
2041 | u8 opcode = (is_write ? nvme_cmd_write : nvme_cmd_read); | 2041 | u8 opcode = (is_write ? nvme_cmd_write : nvme_cmd_read); |
2042 | u16 control; | 2042 | u16 control; |
2043 | u32 max_blocks = (dev->max_hw_sectors << 9) >> ns->lba_shift; | 2043 | u32 max_blocks = nvme_block_nr(ns, dev->max_hw_sectors); |
2044 | 2044 | ||
2045 | num_cmds = nvme_trans_io_get_num_cmds(hdr, cdb_info, max_blocks); | 2045 | num_cmds = nvme_trans_io_get_num_cmds(hdr, cdb_info, max_blocks); |
2046 | 2046 | ||
diff --git a/include/linux/nvme.h b/include/linux/nvme.h index aa575033dbe7..09f419d4da4e 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h | |||
@@ -566,6 +566,11 @@ struct nvme_iod { | |||
566 | struct scatterlist sg[0]; | 566 | struct scatterlist sg[0]; |
567 | }; | 567 | }; |
568 | 568 | ||
569 | static inline u64 nvme_block_nr(struct nvme_ns *ns, sector_t sector) | ||
570 | { | ||
571 | return (sector >> (ns->lba_shift - 9)); | ||
572 | } | ||
573 | |||
569 | /** | 574 | /** |
570 | * nvme_free_iod - frees an nvme_iod | 575 | * nvme_free_iod - frees an nvme_iod |
571 | * @dev: The device that the I/O was submitted to | 576 | * @dev: The device that the I/O was submitted to |