* [PATCH] dmaengine: Simplify dma_async_device_register()
@ 2023-08-15 7:23 Yajun Deng
2023-08-15 16:04 ` Dave Jiang
2023-08-21 13:52 ` Vinod Koul
0 siblings, 2 replies; 3+ messages in thread
From: Yajun Deng @ 2023-08-15 7:23 UTC (permalink / raw)
To: vkoul; +Cc: dmaengine, linux-kernel, Yajun Deng
There are a lot of duplicate codes for checking if the dma has some
capability.
Define a temporary macro that is used to check if the dma claims some
capability and if the corresponding function is implemented.
Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
drivers/dma/dmaengine.c | 82 ++++++++++-------------------------------
1 file changed, 20 insertions(+), 62 deletions(-)
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 826b98284fa1..b7388ae62d7f 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -1147,69 +1147,27 @@ int dma_async_device_register(struct dma_device *device)
device->owner = device->dev->driver->owner;
- if (dma_has_cap(DMA_MEMCPY, device->cap_mask) && !device->device_prep_dma_memcpy) {
- dev_err(device->dev,
- "Device claims capability %s, but op is not defined\n",
- "DMA_MEMCPY");
- return -EIO;
- }
-
- if (dma_has_cap(DMA_XOR, device->cap_mask) && !device->device_prep_dma_xor) {
- dev_err(device->dev,
- "Device claims capability %s, but op is not defined\n",
- "DMA_XOR");
- return -EIO;
- }
-
- if (dma_has_cap(DMA_XOR_VAL, device->cap_mask) && !device->device_prep_dma_xor_val) {
- dev_err(device->dev,
- "Device claims capability %s, but op is not defined\n",
- "DMA_XOR_VAL");
- return -EIO;
- }
-
- if (dma_has_cap(DMA_PQ, device->cap_mask) && !device->device_prep_dma_pq) {
- dev_err(device->dev,
- "Device claims capability %s, but op is not defined\n",
- "DMA_PQ");
- return -EIO;
- }
-
- if (dma_has_cap(DMA_PQ_VAL, device->cap_mask) && !device->device_prep_dma_pq_val) {
- dev_err(device->dev,
- "Device claims capability %s, but op is not defined\n",
- "DMA_PQ_VAL");
- return -EIO;
- }
-
- if (dma_has_cap(DMA_MEMSET, device->cap_mask) && !device->device_prep_dma_memset) {
- dev_err(device->dev,
- "Device claims capability %s, but op is not defined\n",
- "DMA_MEMSET");
- return -EIO;
- }
-
- if (dma_has_cap(DMA_INTERRUPT, device->cap_mask) && !device->device_prep_dma_interrupt) {
- dev_err(device->dev,
- "Device claims capability %s, but op is not defined\n",
- "DMA_INTERRUPT");
- return -EIO;
- }
-
- if (dma_has_cap(DMA_CYCLIC, device->cap_mask) && !device->device_prep_dma_cyclic) {
- dev_err(device->dev,
- "Device claims capability %s, but op is not defined\n",
- "DMA_CYCLIC");
- return -EIO;
- }
-
- if (dma_has_cap(DMA_INTERLEAVE, device->cap_mask) && !device->device_prep_interleaved_dma) {
- dev_err(device->dev,
- "Device claims capability %s, but op is not defined\n",
- "DMA_INTERLEAVE");
- return -EIO;
- }
+#define CHECK_CAP(_name, _type) \
+{ \
+ if (dma_has_cap(_type, device->cap_mask) && !device->device_prep_##_name) { \
+ dev_err(device->dev, \
+ "Device claims capability %s, but op is not defined\n", \
+ __stringify(_type)); \
+ return -EIO; \
+ } \
+}
+ CHECK_CAP(dma_memcpy, DMA_MEMCPY);
+ CHECK_CAP(dma_xor, DMA_XOR);
+ CHECK_CAP(dma_xor_val, DMA_XOR_VAL);
+ CHECK_CAP(dma_pq, DMA_PQ);
+ CHECK_CAP(dma_pq_val, DMA_PQ_VAL);
+ CHECK_CAP(dma_memset, DMA_MEMSET);
+ CHECK_CAP(dma_interrupt, DMA_INTERRUPT);
+ CHECK_CAP(dma_cyclic, DMA_CYCLIC);
+ CHECK_CAP(interleaved_dma, DMA_INTERLEAVE);
+
+#undef CHECK_CAP
if (!device->device_tx_status) {
dev_err(device->dev, "Device tx_status is not defined\n");
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] dmaengine: Simplify dma_async_device_register()
2023-08-15 7:23 [PATCH] dmaengine: Simplify dma_async_device_register() Yajun Deng
@ 2023-08-15 16:04 ` Dave Jiang
2023-08-21 13:52 ` Vinod Koul
1 sibling, 0 replies; 3+ messages in thread
From: Dave Jiang @ 2023-08-15 16:04 UTC (permalink / raw)
To: Yajun Deng, vkoul; +Cc: dmaengine, linux-kernel
On 8/15/23 00:23, Yajun Deng wrote:
> There are a lot of duplicate codes for checking if the dma has some
> capability.
>
> Define a temporary macro that is used to check if the dma claims some
> capability and if the corresponding function is implemented.
>
> Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
> drivers/dma/dmaengine.c | 82 ++++++++++-------------------------------
> 1 file changed, 20 insertions(+), 62 deletions(-)
>
> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index 826b98284fa1..b7388ae62d7f 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -1147,69 +1147,27 @@ int dma_async_device_register(struct dma_device *device)
>
> device->owner = device->dev->driver->owner;
>
> - if (dma_has_cap(DMA_MEMCPY, device->cap_mask) && !device->device_prep_dma_memcpy) {
> - dev_err(device->dev,
> - "Device claims capability %s, but op is not defined\n",
> - "DMA_MEMCPY");
> - return -EIO;
> - }
> -
> - if (dma_has_cap(DMA_XOR, device->cap_mask) && !device->device_prep_dma_xor) {
> - dev_err(device->dev,
> - "Device claims capability %s, but op is not defined\n",
> - "DMA_XOR");
> - return -EIO;
> - }
> -
> - if (dma_has_cap(DMA_XOR_VAL, device->cap_mask) && !device->device_prep_dma_xor_val) {
> - dev_err(device->dev,
> - "Device claims capability %s, but op is not defined\n",
> - "DMA_XOR_VAL");
> - return -EIO;
> - }
> -
> - if (dma_has_cap(DMA_PQ, device->cap_mask) && !device->device_prep_dma_pq) {
> - dev_err(device->dev,
> - "Device claims capability %s, but op is not defined\n",
> - "DMA_PQ");
> - return -EIO;
> - }
> -
> - if (dma_has_cap(DMA_PQ_VAL, device->cap_mask) && !device->device_prep_dma_pq_val) {
> - dev_err(device->dev,
> - "Device claims capability %s, but op is not defined\n",
> - "DMA_PQ_VAL");
> - return -EIO;
> - }
> -
> - if (dma_has_cap(DMA_MEMSET, device->cap_mask) && !device->device_prep_dma_memset) {
> - dev_err(device->dev,
> - "Device claims capability %s, but op is not defined\n",
> - "DMA_MEMSET");
> - return -EIO;
> - }
> -
> - if (dma_has_cap(DMA_INTERRUPT, device->cap_mask) && !device->device_prep_dma_interrupt) {
> - dev_err(device->dev,
> - "Device claims capability %s, but op is not defined\n",
> - "DMA_INTERRUPT");
> - return -EIO;
> - }
> -
> - if (dma_has_cap(DMA_CYCLIC, device->cap_mask) && !device->device_prep_dma_cyclic) {
> - dev_err(device->dev,
> - "Device claims capability %s, but op is not defined\n",
> - "DMA_CYCLIC");
> - return -EIO;
> - }
> -
> - if (dma_has_cap(DMA_INTERLEAVE, device->cap_mask) && !device->device_prep_interleaved_dma) {
> - dev_err(device->dev,
> - "Device claims capability %s, but op is not defined\n",
> - "DMA_INTERLEAVE");
> - return -EIO;
> - }
> +#define CHECK_CAP(_name, _type) \
> +{ \
> + if (dma_has_cap(_type, device->cap_mask) && !device->device_prep_##_name) { \
> + dev_err(device->dev, \
> + "Device claims capability %s, but op is not defined\n", \
> + __stringify(_type)); \
> + return -EIO; \
> + } \
> +}
>
> + CHECK_CAP(dma_memcpy, DMA_MEMCPY);
> + CHECK_CAP(dma_xor, DMA_XOR);
> + CHECK_CAP(dma_xor_val, DMA_XOR_VAL);
> + CHECK_CAP(dma_pq, DMA_PQ);
> + CHECK_CAP(dma_pq_val, DMA_PQ_VAL);
> + CHECK_CAP(dma_memset, DMA_MEMSET);
> + CHECK_CAP(dma_interrupt, DMA_INTERRUPT);
> + CHECK_CAP(dma_cyclic, DMA_CYCLIC);
> + CHECK_CAP(interleaved_dma, DMA_INTERLEAVE);
> +
> +#undef CHECK_CAP
>
> if (!device->device_tx_status) {
> dev_err(device->dev, "Device tx_status is not defined\n");
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] dmaengine: Simplify dma_async_device_register()
2023-08-15 7:23 [PATCH] dmaengine: Simplify dma_async_device_register() Yajun Deng
2023-08-15 16:04 ` Dave Jiang
@ 2023-08-21 13:52 ` Vinod Koul
1 sibling, 0 replies; 3+ messages in thread
From: Vinod Koul @ 2023-08-21 13:52 UTC (permalink / raw)
To: Yajun Deng; +Cc: dmaengine, linux-kernel
On Tue, 15 Aug 2023 15:23:46 +0800, Yajun Deng wrote:
> There are a lot of duplicate codes for checking if the dma has some
> capability.
>
> Define a temporary macro that is used to check if the dma claims some
> capability and if the corresponding function is implemented.
>
>
> [...]
Applied, thanks!
[1/1] dmaengine: Simplify dma_async_device_register()
commit: 81ebed8aa2c213939a4670f508031a57d4ecbb70
Best regards,
--
~Vinod
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-21 13:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-15 7:23 [PATCH] dmaengine: Simplify dma_async_device_register() Yajun Deng
2023-08-15 16:04 ` Dave Jiang
2023-08-21 13:52 ` Vinod Koul
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox