Skip to content

Commit 2498363

Browse files
arndbvinodkoul
authored andcommitted
dmaengine: stm32-dma: avoid 64-bit division in stm32_dma_get_max_width
Using the % operator on a 64-bit variable is expensive and can cause a link failure: arm-linux-gnueabi-ld: drivers/dma/stm32-dma.o: in function `stm32_dma_get_max_width': stm32-dma.c:(.text+0x170): undefined reference to `__aeabi_uldivmod' arm-linux-gnueabi-ld: drivers/dma/stm32-dma.o: in function `stm32_dma_set_xfer_param': stm32-dma.c:(.text+0x1cd4): undefined reference to `__aeabi_uldivmod' As we know that we just want to check the alignment in stm32_dma_get_max_width(), there is no need for a full division, and using a simple mask is a faster replacement. Same in stm32_dma_set_xfer_param(), change this to only allow burst transfers if the address is a multiple of the length. stm32_dma_get_best_burst just after will take buf_len into account to fix burst in case of misalignment. Fixes: b20fd5f ("dmaengine: stm32-dma: fix stm32_dma_get_max_width") Reported-by: kernel test robot <[email protected]> Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: Amelie Delaunay <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent e067485 commit 2498363

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/dma/stm32-dma.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ static enum dma_slave_buswidth stm32_dma_get_max_width(u32 buf_len,
280280
max_width > DMA_SLAVE_BUSWIDTH_1_BYTE)
281281
max_width = max_width >> 1;
282282

283-
if (buf_addr % max_width)
283+
if (buf_addr & (max_width - 1))
284284
max_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
285285

286286
return max_width;
@@ -757,7 +757,7 @@ static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan,
757757
* Set memory burst size - burst not possible if address is not aligned on
758758
* the address boundary equal to the size of the transfer
759759
*/
760-
if (buf_addr % buf_len)
760+
if (buf_addr & (buf_len - 1))
761761
src_maxburst = 1;
762762
else
763763
src_maxburst = STM32_DMA_MAX_BURST;
@@ -813,7 +813,7 @@ static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan,
813813
* Set memory burst size - burst not possible if address is not aligned on
814814
* the address boundary equal to the size of the transfer
815815
*/
816-
if (buf_addr % buf_len)
816+
if (buf_addr & (buf_len - 1))
817817
dst_maxburst = 1;
818818
else
819819
dst_maxburst = STM32_DMA_MAX_BURST;

0 commit comments

Comments
 (0)