NVMe: Abstract out sector to block number conversion
authorMatthew Wilcox <matthew.r.wilcox@intel.com>
Thu, 28 Mar 2013 01:28:22 +0000 (21:28 -0400)
committerMatthew Wilcox <matthew.r.wilcox@intel.com>
Tue, 16 Apr 2013 19:05:22 +0000 (15:05 -0400)
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>
drivers/block/nvme-core.c
drivers/block/nvme-scsi.c
include/linux/nvme.h

index 32fdfe9a5156a01fab6b451df1e89d85b9901d27..f3ea52aa3e5df174fe456a796c79ac736b563295 100644 (file)
@@ -477,7 +477,7 @@ static int nvme_submit_discard(struct nvme_queue *nvmeq, struct nvme_ns *ns,
 
        range->cattr = cpu_to_le32(0);
        range->nlb = cpu_to_le32(bio->bi_size >> ns->lba_shift);
-       range->slba = cpu_to_le64(bio->bi_sector >> (ns->lba_shift - 9));
+       range->slba = cpu_to_le64(nvme_block_nr(ns, bio->bi_sector));
 
        memset(cmnd, 0, sizeof(*cmnd));
        cmnd->dsm.opcode = nvme_cmd_dsm;
@@ -590,7 +590,7 @@ static int nvme_submit_bio_queue(struct nvme_queue *nvmeq, struct nvme_ns *ns,
        cmnd->rw.nsid = cpu_to_le32(ns->ns_id);
        length = nvme_setup_prps(nvmeq->dev, &cmnd->common, iod, length,
                                                                GFP_ATOMIC);
-       cmnd->rw.slba = cpu_to_le64(bio->bi_sector >> (ns->lba_shift - 9));
+       cmnd->rw.slba = cpu_to_le64(nvme_block_nr(ns, bio->bi_sector));
        cmnd->rw.length = cpu_to_le16((length >> ns->lba_shift) - 1);
        cmnd->rw.control = cpu_to_le16(control);
        cmnd->rw.dsmgmt = cpu_to_le32(dsmgmt);
index 483af3585c9260369909a98070fe97909ffceb87..db7052ea8d0d48e5488605363e0467a35cd4c036 100644 (file)
@@ -2040,7 +2040,7 @@ static int nvme_trans_do_nvme_io(struct nvme_ns *ns, struct sg_io_hdr *hdr,
        struct nvme_command c;
        u8 opcode = (is_write ? nvme_cmd_write : nvme_cmd_read);
        u16 control;
-       u32 max_blocks = (dev->max_hw_sectors << 9) >> ns->lba_shift;
+       u32 max_blocks = nvme_block_nr(ns, dev->max_hw_sectors);
 
        num_cmds = nvme_trans_io_get_num_cmds(hdr, cdb_info, max_blocks);
 
index aa575033dbe7d9ac66a4cc5d4d5a94afa48a8b46..09f419d4da4e29ded943743f7f702a86e7887086 100644 (file)
@@ -566,6 +566,11 @@ struct nvme_iod {
        struct scatterlist sg[0];
 };
 
+static inline u64 nvme_block_nr(struct nvme_ns *ns, sector_t sector)
+{
+       return (sector >> (ns->lba_shift - 9));
+}
+
 /**
  * nvme_free_iod - frees an nvme_iod
  * @dev: The device that the I/O was submitted to