kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: comedi: s626: Remove pci-dma-compat wrapper APIs.
@ 2020-07-11 12:47 Suraj Upadhyay
  2020-07-11 13:38 ` Christophe JAILLET
  0 siblings, 1 reply; 3+ messages in thread
From: Suraj Upadhyay @ 2020-07-11 12:47 UTC (permalink / raw)
  To: gregkh, abbotti, hsweeten; +Cc: devel, kernel-janitors, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 4554 bytes --]

The legacy API wrappers in include/linux/pci-dma-compat.h
should go away as it creates unnecessary midlayering
for include/linux/dma-mapping.h APIs, instead use dma-mapping.h
APIs directly.

The patch has been generated with the coccinelle script below
and compile-tested.

@@@@
- PCI_DMA_BIDIRECTIONAL
+ DMA_BIDIRECTIONAL

@@@@
- PCI_DMA_TODEVICE
+ DMA_TO_DEVICE

@@@@
- PCI_DMA_FROMDEVICE
+ DMA_FROM_DEVICE

@@@@
- PCI_DMA_NONE
+ DMA_NONE

@@ expression E1, E2, E3; @@
- pci_alloc_consistent(E1, E2, E3)
+ dma_alloc_coherent(&E1->dev, E2, E3, GFP_ATOMIC)

@@ expression E1, E2, E3; @@
- pci_zalloc_consistent(E1, E2, E3)
+ dma_alloc_coherent(&E1->dev, E2, E3, GFP_ATOMIC)

@@ expression E1, E2, E3, E4; @@
- pci_free_consistent(E1, E2, E3, E4)
+ dma_free_coherent(&E1->dev, E2, E3, E4)

@@ expression E1, E2, E3, E4; @@
- pci_map_single(E1, E2, E3, E4)
+ dma_map_single(&E1->dev, E2, E3, (enum dma_data_direction)E4)

@@ expression E1, E2, E3, E4; @@
- pci_unmap_single(E1, E2, E3, E4)
+ dma_unmap_single(&E1->dev, E2, E3, (enum dma_data_direction)E4)

@@ expression E1, E2, E3, E4, E5; @@
- pci_map_page(E1, E2, E3, E4, E5)
+ dma_map_page(&E1->dev, E2, E3, E4, (enum dma_data_direction)E5)

@@ expression E1, E2, E3, E4; @@
- pci_unmap_page(E1, E2, E3, E4)
+ dma_unmap_page(&E1->dev, E2, E3, (enum dma_data_direction)E4)

@@ expression E1, E2, E3, E4; @@
- pci_map_sg(E1, E2, E3, E4)
+ dma_map_sg(&E1->dev, E2, E3, (enum dma_data_direction)E4)

@@ expression E1, E2, E3, E4; @@
- pci_unmap_sg(E1, E2, E3, E4)
+ dma_unmap_sg(&E1->dev, E2, E3, (enum dma_data_direction)E4)

@@ expression E1, E2, E3, E4; @@
- pci_dma_sync_single_for_cpu(E1, E2, E3, E4)
+ dma_sync_single_for_cpu(&E1->dev, E2, E3, (enum dma_data_direction)E4)

@@ expression E1, E2, E3, E4; @@
- pci_dma_sync_single_for_device(E1, E2, E3, E4)
+ dma_sync_single_for_device(&E1->dev, E2, E3, (enum dma_data_direction)E4)

@@ expression E1, E2, E3, E4; @@
- pci_dma_sync_sg_for_cpu(E1, E2, E3, E4)
+ dma_sync_sg_for_cpu(&E1->dev, E2, E3, (enum dma_data_direction)E4)

@@ expression E1, E2, E3, E4; @@
- pci_dma_sync_sg_for_device(E1, E2, E3, E4)
+ dma_sync_sg_for_device(&E1->dev, E2, E3, (enum dma_data_direction)E4)

@@ expression E1, E2; @@
- pci_dma_mapping_error(E1, E2)
+ dma_mapping_error(&E1->dev, E2)

@@ expression E1, E2; @@
- pci_set_consistent_dma_mask(E1, E2)
+ dma_set_coherent_mask(&E1->dev, E2)

@@ expression E1, E2; @@
- pci_set_dma_mask(E1, E2)
+ dma_set_mask(&E1->dev, E2)

Signed-off-by: Suraj Upadhyay <usuraj35@gmail.com>
---
	This change is proposed by Christoph Hellwig <hch@infradead.org>
	in the post https://marc.info/?l=kernel-janitors&m=158745678307186&w=4
	on kernel-janitors Mailing List.

 drivers/staging/comedi/drivers/s626.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c
index 084a8e7b9fc2..c159416662fd 100644
--- a/drivers/staging/comedi/drivers/s626.c
+++ b/drivers/staging/comedi/drivers/s626.c
@@ -2130,13 +2130,15 @@ static int s626_allocate_dma_buffers(struct comedi_device *dev)
 	void *addr;
 	dma_addr_t appdma;
 
-	addr = pci_alloc_consistent(pcidev, S626_DMABUF_SIZE, &appdma);
+	addr = dma_alloc_coherent(&pcidev->dev, S626_DMABUF_SIZE, &appdma,
+				  GFP_ATOMIC);
 	if (!addr)
 		return -ENOMEM;
 	devpriv->ana_buf.logical_base = addr;
 	devpriv->ana_buf.physical_base = appdma;
 
-	addr = pci_alloc_consistent(pcidev, S626_DMABUF_SIZE, &appdma);
+	addr = dma_alloc_coherent(&pcidev->dev, S626_DMABUF_SIZE, &appdma,
+				  GFP_ATOMIC);
 	if (!addr)
 		return -ENOMEM;
 	devpriv->rps_buf.logical_base = addr;
@@ -2154,13 +2156,13 @@ static void s626_free_dma_buffers(struct comedi_device *dev)
 		return;
 
 	if (devpriv->rps_buf.logical_base)
-		pci_free_consistent(pcidev, S626_DMABUF_SIZE,
-				    devpriv->rps_buf.logical_base,
-				    devpriv->rps_buf.physical_base);
+		dma_free_coherent(&pcidev->dev, S626_DMABUF_SIZE,
+				  devpriv->rps_buf.logical_base,
+				  devpriv->rps_buf.physical_base);
 	if (devpriv->ana_buf.logical_base)
-		pci_free_consistent(pcidev, S626_DMABUF_SIZE,
-				    devpriv->ana_buf.logical_base,
-				    devpriv->ana_buf.physical_base);
+		dma_free_coherent(&pcidev->dev, S626_DMABUF_SIZE,
+				  devpriv->ana_buf.logical_base,
+				  devpriv->ana_buf.physical_base);
 }
 
 static int s626_initialize(struct comedi_device *dev)
-- 
2.17.1


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: comedi: s626: Remove pci-dma-compat wrapper APIs.
  2020-07-11 12:47 [PATCH] staging: comedi: s626: Remove pci-dma-compat wrapper APIs Suraj Upadhyay
@ 2020-07-11 13:38 ` Christophe JAILLET
  2020-07-13 13:48   ` Ian Abbott
  0 siblings, 1 reply; 3+ messages in thread
From: Christophe JAILLET @ 2020-07-11 13:38 UTC (permalink / raw)
  To: Suraj Upadhyay, gregkh, abbotti, hsweeten
  Cc: devel, kernel-janitors, linux-kernel

Le 11/07/2020 à 14:35, Suraj Upadhyay a écrit :
> The legacy API wrappers in include/linux/pci-dma-compat.h
> should go away as it creates unnecessary midlayering
> for include/linux/dma-mapping.h APIs, instead use dma-mapping.h
> APIs directly.
>
> The patch has been generated with the coccinelle script below
> and compile-tested.
>
> [...]
> @@ expression E1, E2, E3; @@
> - pci_alloc_consistent(E1, E2, E3)
> + dma_alloc_coherent(&E1->dev, E2, E3, GFP_ATOMIC)
>
> @@ expression E1, E2, E3; @@
> - pci_zalloc_consistent(E1, E2, E3)
> + dma_alloc_coherent(&E1->dev, E2, E3, GFP_ATOMIC)

This is the tricky part of this kind of cleanup, see below.

GFP_ATOMIC can't be wrong because it is was exactly what was done with 
the pci_ function.
However, most of the time, it can safely be replaced by GFP_KERNEL which 
gives more opportunities to the memory allocator.

> [...]
> diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c
> index 084a8e7b9fc2..c159416662fd 100644
> --- a/drivers/staging/comedi/drivers/s626.c
> +++ b/drivers/staging/comedi/drivers/s626.c
> @@ -2130,13 +2130,15 @@ static int s626_allocate_dma_buffers(struct comedi_device *dev)
>   	void *addr;
>   	dma_addr_t appdma;
>   
> -	addr = pci_alloc_consistent(pcidev, S626_DMABUF_SIZE, &appdma);
> +	addr = dma_alloc_coherent(&pcidev->dev, S626_DMABUF_SIZE, &appdma,
> +				  GFP_ATOMIC);
>   	if (!addr)
>   		return -ENOMEM;
>   	devpriv->ana_buf.logical_base = addr;
>   	devpriv->ana_buf.physical_base = appdma;
>   
> -	addr = pci_alloc_consistent(pcidev, S626_DMABUF_SIZE, &appdma);
> +	addr = dma_alloc_coherent(&pcidev->dev, S626_DMABUF_SIZE, &appdma,
> +				  GFP_ATOMIC);
>   	if (!addr)
>   		return -ENOMEM;
>   	devpriv->rps_buf.logical_base = addr;
's626_allocate_dma_buffers()' is only called from 's626_auto_attach()'.
In this function, around the call to 's626_allocate_dma_buffers()', you 
can see:
   - a few lines before, a call to 'comedi_alloc_devpriv()'

   - a few lines after, a call to 'comedi_alloc_subdevices()'

These 2 functions make some memory allocation using GFP_KERNEL.

So it is likely that using GFP_KERNEL in your proposal is also valid.


Just my 2c.

CJ

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: comedi: s626: Remove pci-dma-compat wrapper APIs.
  2020-07-11 13:38 ` Christophe JAILLET
@ 2020-07-13 13:48   ` Ian Abbott
  0 siblings, 0 replies; 3+ messages in thread
From: Ian Abbott @ 2020-07-13 13:48 UTC (permalink / raw)
  To: Christophe JAILLET, Suraj Upadhyay, gregkh, hsweeten
  Cc: devel, kernel-janitors, linux-kernel

On 11/07/2020 14:38, Christophe JAILLET wrote:
> Le 11/07/2020 à 14:35, Suraj Upadhyay a écrit :
>> The legacy API wrappers in include/linux/pci-dma-compat.h
>> should go away as it creates unnecessary midlayering
>> for include/linux/dma-mapping.h APIs, instead use dma-mapping.h
>> APIs directly.
>>
>> The patch has been generated with the coccinelle script below
>> and compile-tested.
>>
>> [...]
>> @@ expression E1, E2, E3; @@
>> - pci_alloc_consistent(E1, E2, E3)
>> + dma_alloc_coherent(&E1->dev, E2, E3, GFP_ATOMIC)
>>
>> @@ expression E1, E2, E3; @@
>> - pci_zalloc_consistent(E1, E2, E3)
>> + dma_alloc_coherent(&E1->dev, E2, E3, GFP_ATOMIC)
> 
> This is the tricky part of this kind of cleanup, see below.
> 
> GFP_ATOMIC can't be wrong because it is was exactly what was done with 
> the pci_ function.
> However, most of the time, it can safely be replaced by GFP_KERNEL which 
> gives more opportunities to the memory allocator.
> 
>> [...]
>> diff --git a/drivers/staging/comedi/drivers/s626.c 
>> b/drivers/staging/comedi/drivers/s626.c
>> index 084a8e7b9fc2..c159416662fd 100644
>> --- a/drivers/staging/comedi/drivers/s626.c
>> +++ b/drivers/staging/comedi/drivers/s626.c
>> @@ -2130,13 +2130,15 @@ static int s626_allocate_dma_buffers(struct 
>> comedi_device *dev)
>>       void *addr;
>>       dma_addr_t appdma;
>> -    addr = pci_alloc_consistent(pcidev, S626_DMABUF_SIZE, &appdma);
>> +    addr = dma_alloc_coherent(&pcidev->dev, S626_DMABUF_SIZE, &appdma,
>> +                  GFP_ATOMIC);
>>       if (!addr)
>>           return -ENOMEM;
>>       devpriv->ana_buf.logical_base = addr;
>>       devpriv->ana_buf.physical_base = appdma;
>> -    addr = pci_alloc_consistent(pcidev, S626_DMABUF_SIZE, &appdma);
>> +    addr = dma_alloc_coherent(&pcidev->dev, S626_DMABUF_SIZE, &appdma,
>> +                  GFP_ATOMIC);
>>       if (!addr)
>>           return -ENOMEM;
>>       devpriv->rps_buf.logical_base = addr;
> 's626_allocate_dma_buffers()' is only called from 's626_auto_attach()'.
> In this function, around the call to 's626_allocate_dma_buffers()', you 
> can see:
>    - a few lines before, a call to 'comedi_alloc_devpriv()'
> 
>    - a few lines after, a call to 'comedi_alloc_subdevices()'
> 
> These 2 functions make some memory allocation using GFP_KERNEL.
> 
> So it is likely that using GFP_KERNEL in your proposal is also valid.

Indeed, GFP_KERNEL is perfectly fine here.  It could be done as a 
follow-up patch, or done in a v2 of this patch with a mention in the 
patch description.

-- 
-=( Ian Abbott <abbotti@mev.co.uk> || Web: www.mev.co.uk )=-
-=( MEV Ltd. is a company registered in England & Wales. )=-
-=( Registered number: 02862268.  Registered address:    )=-
-=( 15 West Park Road, Bramhall, STOCKPORT, SK7 3JZ, UK. )=-

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-13 13:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-11 12:47 [PATCH] staging: comedi: s626: Remove pci-dma-compat wrapper APIs Suraj Upadhyay
2020-07-11 13:38 ` Christophe JAILLET
2020-07-13 13:48   ` Ian Abbott

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).