Skip to content

Commit 706dc3b

Browse files
tititiou36martinkpetersen
authored andcommitted
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>
1 parent 76a334d commit 706dc3b

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

drivers/message/fusion/mptctl.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,8 @@ kbuf_alloc_2_sgl(int bytes, u32 sgdir, int sge_offset, int *frags,
10411041
* copying the data in this array into the correct place in the
10421042
* request and chain buffers.
10431043
*/
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);
10451046
if (sglbuf == NULL)
10461047
goto free_and_fail;
10471048

@@ -1062,9 +1063,9 @@ kbuf_alloc_2_sgl(int bytes, u32 sgdir, int sge_offset, int *frags,
10621063
while (bytes_allocd < bytes) {
10631064
this_alloc = min(alloc_sz, bytes-bytes_allocd);
10641065
buflist[buflist_ent].len = this_alloc;
1065-
buflist[buflist_ent].kptr = pci_alloc_consistent(ioc->pcidev,
1066-
this_alloc,
1067-
&pa);
1066+
buflist[buflist_ent].kptr = dma_alloc_coherent(&ioc->pcidev->dev,
1067+
this_alloc,
1068+
&pa, GFP_KERNEL);
10681069
if (buflist[buflist_ent].kptr == NULL) {
10691070
alloc_sz = alloc_sz / 2;
10701071
if (alloc_sz == 0) {
@@ -2105,8 +2106,9 @@ mptctl_do_mpt_command (MPT_ADAPTER *ioc, struct mpt_ioctl_command karg, void __u
21052106
}
21062107
flagsLength |= karg.dataOutSize;
21072108
bufOut.len = karg.dataOutSize;
2108-
bufOut.kptr = pci_alloc_consistent(
2109-
ioc->pcidev, bufOut.len, &dma_addr_out);
2109+
bufOut.kptr = dma_alloc_coherent(&ioc->pcidev->dev,
2110+
bufOut.len,
2111+
&dma_addr_out, GFP_KERNEL);
21102112

21112113
if (bufOut.kptr == NULL) {
21122114
rc = -ENOMEM;
@@ -2139,8 +2141,9 @@ mptctl_do_mpt_command (MPT_ADAPTER *ioc, struct mpt_ioctl_command karg, void __u
21392141
flagsLength |= karg.dataInSize;
21402142

21412143
bufIn.len = karg.dataInSize;
2142-
bufIn.kptr = pci_alloc_consistent(ioc->pcidev,
2143-
bufIn.len, &dma_addr_in);
2144+
bufIn.kptr = dma_alloc_coherent(&ioc->pcidev->dev,
2145+
bufIn.len,
2146+
&dma_addr_in, GFP_KERNEL);
21442147

21452148
if (bufIn.kptr == NULL) {
21462149
rc = -ENOMEM;
@@ -2400,7 +2403,9 @@ mptctl_hp_hostinfo(MPT_ADAPTER *ioc, unsigned long arg, unsigned int data_size)
24002403
/* Issue the second config page request */
24012404
cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
24022405

2403-
pbuf = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, &buf_dma);
2406+
pbuf = dma_alloc_coherent(&ioc->pcidev->dev,
2407+
hdr.PageLength * 4,
2408+
&buf_dma, GFP_KERNEL);
24042409
if (pbuf) {
24052410
cfg.physAddr = buf_dma;
24062411
if (mpt_config(ioc, &cfg) == 0) {
@@ -2477,7 +2482,7 @@ mptctl_hp_hostinfo(MPT_ADAPTER *ioc, unsigned long arg, unsigned int data_size)
24772482
else
24782483
IstwiRWRequest->DeviceAddr = 0xB0;
24792484

2480-
pbuf = pci_alloc_consistent(ioc->pcidev, 4, &buf_dma);
2485+
pbuf = dma_alloc_coherent(&ioc->pcidev->dev, 4, &buf_dma, GFP_KERNEL);
24812486
if (!pbuf)
24822487
goto out;
24832488
ioc->add_sge((char *)&IstwiRWRequest->SGL,
@@ -2592,7 +2597,8 @@ mptctl_hp_targetinfo(MPT_ADAPTER *ioc, unsigned long arg)
25922597
/* Get the data transfer speeds
25932598
*/
25942599
data_sz = ioc->spi_data.sdp0length * 4;
2595-
pg0_alloc = pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
2600+
pg0_alloc = dma_alloc_coherent(&ioc->pcidev->dev, data_sz, &page_dma,
2601+
GFP_KERNEL);
25962602
if (pg0_alloc) {
25972603
hdr.PageVersion = ioc->spi_data.sdp0version;
25982604
hdr.PageLength = data_sz;
@@ -2657,7 +2663,8 @@ mptctl_hp_targetinfo(MPT_ADAPTER *ioc, unsigned long arg)
26572663
/* Issue the second config page request */
26582664
cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
26592665
data_sz = (int) cfg.cfghdr.hdr->PageLength * 4;
2660-
pg3_alloc = pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
2666+
pg3_alloc = dma_alloc_coherent(&ioc->pcidev->dev, data_sz,
2667+
&page_dma, GFP_KERNEL);
26612668
if (pg3_alloc) {
26622669
cfg.physAddr = page_dma;
26632670
cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;

0 commit comments

Comments
 (0)