[PATCHv2 4/5] nvme-pci: iod nents fits in u8

Keith Busch kbusch at fb.com
Fri Jul 29 09:28:50 PDT 2022


From: Keith Busch <kbusch at kernel.org>

The maximum number of 'nents' is 127, set by the queue limit, and is
only >= 0, so it fits in an 'u8' type. Set to that type to save some
space in this highly allocated struct, and ensure we don't accidently
let nents exceed this type in the future.

Signed-off-by: Keith Busch <kbusch at kernel.org>
---
v1->v2:
  Added BUILD_BUG_ON (Christoph)

  Made this a u8 instead of s8

 drivers/nvme/host/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index e5b8e1c277b2..6d491a27ed73 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -229,7 +229,7 @@ struct nvme_iod {
 	bool use_sgl;
 	bool aborted;
 	s8 nr_allocations;	/* PRP list pool allocations. 0 means small pool in use */
-	int nents;		/* Used in scatterlist */
+	u8 nents;		/* Used in scatterlist */
 	dma_addr_t first_dma;
 	unsigned int dma_len;	/* length of single DMA segment mapping */
 	dma_addr_t meta_dma;
@@ -3562,6 +3562,7 @@ static int __init nvme_init(void)
 	BUILD_BUG_ON(sizeof(struct nvme_create_sq) != 64);
 	BUILD_BUG_ON(sizeof(struct nvme_delete_queue) != 64);
 	BUILD_BUG_ON(IRQ_AFFINITY_MAX_SETS < 2);
+	BUILD_BUG_ON(NVME_MAX_SEGS > U8_MAX);
 	BUILD_BUG_ON(DIV_ROUND_UP(nvme_pci_npages_prp(), NVME_CTRL_PAGE_SIZE) >
 		     S8_MAX);
 
-- 
2.30.2




More information about the Linux-nvme mailing list