Skip to content

Commit 3f04616

Browse files
gaochaointelChristoph Hellwig
authored andcommitted
swiotlb: avoid potential left shift overflow
The second operand passed to slot_addr() is declared as int or unsigned int in all call sites. The left-shift to get the offset of a slot can overflow if swiotlb size is larger than 4G. Convert the macro to an inline function and declare the second argument as phys_addr_t to avoid the potential overflow. Fixes: 26a7e09 ("swiotlb: refactor swiotlb_tbl_map_single") Signed-off-by: Chao Gao <chao.gao@intel.com> Reviewed-by: Dongli Zhang <dongli.zhang@oracle.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 2995b80 commit 3f04616

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

kernel/dma/swiotlb.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,10 @@ static void swiotlb_bounce(struct device *dev, phys_addr_t tlb_addr, size_t size
575575
}
576576
}
577577

578-
#define slot_addr(start, idx) ((start) + ((idx) << IO_TLB_SHIFT))
578+
static inline phys_addr_t slot_addr(phys_addr_t start, phys_addr_t idx)
579+
{
580+
return start + (idx << IO_TLB_SHIFT);
581+
}
579582

580583
/*
581584
* Carefully handle integer overflow which can occur when boundary_mask == ~0UL.

0 commit comments

Comments
 (0)