Skip to content

Commit 1a4e53d

Browse files
bijudasbroonie
authored andcommitted
spi: Fix invalid sgs value
max_seg_size is unsigned int and it can have a value up to 2^32 (for eg:-RZ_DMAC driver sets dma_set_max_seg_size as U32_MAX) When this value is used in min_t() as an integer type, it becomes -1 and the value of sgs becomes 0. Fix this issue by replacing the 'int' data type with 'unsigned int' in min_t(). Signed-off-by: Biju Das <[email protected]> Reviewed-by: Lad Prabhakar <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 8080876 commit 1a4e53d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/spi/spi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,10 +1019,10 @@ int spi_map_buf(struct spi_controller *ctlr, struct device *dev,
10191019
int i, ret;
10201020

10211021
if (vmalloced_buf || kmap_buf) {
1022-
desc_len = min_t(int, max_seg_size, PAGE_SIZE);
1022+
desc_len = min_t(unsigned int, max_seg_size, PAGE_SIZE);
10231023
sgs = DIV_ROUND_UP(len + offset_in_page(buf), desc_len);
10241024
} else if (virt_addr_valid(buf)) {
1025-
desc_len = min_t(int, max_seg_size, ctlr->max_dma_len);
1025+
desc_len = min_t(unsigned int, max_seg_size, ctlr->max_dma_len);
10261026
sgs = DIV_ROUND_UP(len, desc_len);
10271027
} else {
10281028
return -EINVAL;

0 commit comments

Comments
 (0)