Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: message: fusion: mptctl: Use dma_alloc_coherent()

In [1], Christoph Hellwig has proposed to remove the wrappers in
include/linux/pci-dma-compat.h.

Some reasons why this API should be removed have been given by Julia
Lawall in [2].

When memory is allocated in kbuf_alloc_2_sgl() GFP_KERNEL can be used
because this function already uses the GFP_USER flag for some memory
allocation and not spin_lock is taken in the between.

When memory is allocated in mptctl_do_mpt_command() GFP_KERNEL can be used
because this function already uses copy_from_user() and this function can
sleep.

When memory is allocated in mptctl_hp_hostinfo() GFP_KERNEL can be used
because this function already uses mpt_config() and this function has an
explicit might_sleep().

When memory is allocated in mptctl_hp_targetinfo() GFP_KERNEL can be used
because this function already uses mpt_config() and this function has an
explicit might_sleep().

[1]: https://lore.kernel.org/kernel-janitors/20200421081257.GA131897@infradead.org/
[2]: https://lore.kernel.org/kernel-janitors/alpine.DEB.2.22.394.2007120902170.2424@hadrien/

Link: https://lore.kernel.org/r/516375d6d06114484533baf03aae351306100246.1641500561.git.christophe.jaillet@wanadoo.fr
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Christophe JAILLET and committed by
Martin K. Petersen
706dc3b9 76a334d7

+19 -12
+19 -12
drivers/message/fusion/mptctl.c
··· 1041 1041 * copying the data in this array into the correct place in the 1042 1042 * request and chain buffers. 1043 1043 */ 1044 - sglbuf = pci_alloc_consistent(ioc->pcidev, MAX_SGL_BYTES, sglbuf_dma); 1044 + sglbuf = dma_alloc_coherent(&ioc->pcidev->dev, MAX_SGL_BYTES, 1045 + sglbuf_dma, GFP_KERNEL); 1045 1046 if (sglbuf == NULL) 1046 1047 goto free_and_fail; 1047 1048 ··· 1063 1062 while (bytes_allocd < bytes) { 1064 1063 this_alloc = min(alloc_sz, bytes-bytes_allocd); 1065 1064 buflist[buflist_ent].len = this_alloc; 1066 - buflist[buflist_ent].kptr = pci_alloc_consistent(ioc->pcidev, 1067 - this_alloc, 1068 - &pa); 1065 + buflist[buflist_ent].kptr = dma_alloc_coherent(&ioc->pcidev->dev, 1066 + this_alloc, 1067 + &pa, GFP_KERNEL); 1069 1068 if (buflist[buflist_ent].kptr == NULL) { 1070 1069 alloc_sz = alloc_sz / 2; 1071 1070 if (alloc_sz == 0) { ··· 2106 2105 } 2107 2106 flagsLength |= karg.dataOutSize; 2108 2107 bufOut.len = karg.dataOutSize; 2109 - bufOut.kptr = pci_alloc_consistent( 2110 - ioc->pcidev, bufOut.len, &dma_addr_out); 2108 + bufOut.kptr = dma_alloc_coherent(&ioc->pcidev->dev, 2109 + bufOut.len, 2110 + &dma_addr_out, GFP_KERNEL); 2111 2111 2112 2112 if (bufOut.kptr == NULL) { 2113 2113 rc = -ENOMEM; ··· 2141 2139 flagsLength |= karg.dataInSize; 2142 2140 2143 2141 bufIn.len = karg.dataInSize; 2144 - bufIn.kptr = pci_alloc_consistent(ioc->pcidev, 2145 - bufIn.len, &dma_addr_in); 2142 + bufIn.kptr = dma_alloc_coherent(&ioc->pcidev->dev, 2143 + bufIn.len, 2144 + &dma_addr_in, GFP_KERNEL); 2146 2145 2147 2146 if (bufIn.kptr == NULL) { 2148 2147 rc = -ENOMEM; ··· 2403 2400 /* Issue the second config page request */ 2404 2401 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 2405 2402 2406 - pbuf = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, &buf_dma); 2403 + pbuf = dma_alloc_coherent(&ioc->pcidev->dev, 2404 + hdr.PageLength * 4, 2405 + &buf_dma, GFP_KERNEL); 2407 2406 if (pbuf) { 2408 2407 cfg.physAddr = buf_dma; 2409 2408 if (mpt_config(ioc, &cfg) == 0) { ··· 2482 2477 else 2483 2478 IstwiRWRequest->DeviceAddr = 0xB0; 2484 2479 2485 - pbuf = pci_alloc_consistent(ioc->pcidev, 4, &buf_dma); 2480 + pbuf = dma_alloc_coherent(&ioc->pcidev->dev, 4, &buf_dma, GFP_KERNEL); 2486 2481 if (!pbuf) 2487 2482 goto out; 2488 2483 ioc->add_sge((char *)&IstwiRWRequest->SGL, ··· 2597 2592 /* Get the data transfer speeds 2598 2593 */ 2599 2594 data_sz = ioc->spi_data.sdp0length * 4; 2600 - pg0_alloc = pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma); 2595 + pg0_alloc = dma_alloc_coherent(&ioc->pcidev->dev, data_sz, &page_dma, 2596 + GFP_KERNEL); 2601 2597 if (pg0_alloc) { 2602 2598 hdr.PageVersion = ioc->spi_data.sdp0version; 2603 2599 hdr.PageLength = data_sz; ··· 2663 2657 /* Issue the second config page request */ 2664 2658 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 2665 2659 data_sz = (int) cfg.cfghdr.hdr->PageLength * 4; 2666 - pg3_alloc = pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma); 2660 + pg3_alloc = dma_alloc_coherent(&ioc->pcidev->dev, data_sz, 2661 + &page_dma, GFP_KERNEL); 2667 2662 if (pg3_alloc) { 2668 2663 cfg.physAddr = page_dma; 2669 2664 cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;