Skip to content

Commit 81ebed8

Browse files
Yajun Dengvinodkoul
authored andcommitted
dmaengine: Simplify dma_async_device_register()
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 <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 33a0b73 commit 81ebed8

File tree

1 file changed

+20
-62
lines changed

1 file changed

+20
-62
lines changed

drivers/dma/dmaengine.c

Lines changed: 20 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,69 +1147,27 @@ int dma_async_device_register(struct dma_device *device)
11471147

11481148
device->owner = device->dev->driver->owner;
11491149

1150-
if (dma_has_cap(DMA_MEMCPY, device->cap_mask) && !device->device_prep_dma_memcpy) {
1151-
dev_err(device->dev,
1152-
"Device claims capability %s, but op is not defined\n",
1153-
"DMA_MEMCPY");
1154-
return -EIO;
1155-
}
1156-
1157-
if (dma_has_cap(DMA_XOR, device->cap_mask) && !device->device_prep_dma_xor) {
1158-
dev_err(device->dev,
1159-
"Device claims capability %s, but op is not defined\n",
1160-
"DMA_XOR");
1161-
return -EIO;
1162-
}
1163-
1164-
if (dma_has_cap(DMA_XOR_VAL, device->cap_mask) && !device->device_prep_dma_xor_val) {
1165-
dev_err(device->dev,
1166-
"Device claims capability %s, but op is not defined\n",
1167-
"DMA_XOR_VAL");
1168-
return -EIO;
1169-
}
1170-
1171-
if (dma_has_cap(DMA_PQ, device->cap_mask) && !device->device_prep_dma_pq) {
1172-
dev_err(device->dev,
1173-
"Device claims capability %s, but op is not defined\n",
1174-
"DMA_PQ");
1175-
return -EIO;
1176-
}
1177-
1178-
if (dma_has_cap(DMA_PQ_VAL, device->cap_mask) && !device->device_prep_dma_pq_val) {
1179-
dev_err(device->dev,
1180-
"Device claims capability %s, but op is not defined\n",
1181-
"DMA_PQ_VAL");
1182-
return -EIO;
1183-
}
1184-
1185-
if (dma_has_cap(DMA_MEMSET, device->cap_mask) && !device->device_prep_dma_memset) {
1186-
dev_err(device->dev,
1187-
"Device claims capability %s, but op is not defined\n",
1188-
"DMA_MEMSET");
1189-
return -EIO;
1190-
}
1191-
1192-
if (dma_has_cap(DMA_INTERRUPT, device->cap_mask) && !device->device_prep_dma_interrupt) {
1193-
dev_err(device->dev,
1194-
"Device claims capability %s, but op is not defined\n",
1195-
"DMA_INTERRUPT");
1196-
return -EIO;
1197-
}
1198-
1199-
if (dma_has_cap(DMA_CYCLIC, device->cap_mask) && !device->device_prep_dma_cyclic) {
1200-
dev_err(device->dev,
1201-
"Device claims capability %s, but op is not defined\n",
1202-
"DMA_CYCLIC");
1203-
return -EIO;
1204-
}
1205-
1206-
if (dma_has_cap(DMA_INTERLEAVE, device->cap_mask) && !device->device_prep_interleaved_dma) {
1207-
dev_err(device->dev,
1208-
"Device claims capability %s, but op is not defined\n",
1209-
"DMA_INTERLEAVE");
1210-
return -EIO;
1211-
}
1150+
#define CHECK_CAP(_name, _type) \
1151+
{ \
1152+
if (dma_has_cap(_type, device->cap_mask) && !device->device_prep_##_name) { \
1153+
dev_err(device->dev, \
1154+
"Device claims capability %s, but op is not defined\n", \
1155+
__stringify(_type)); \
1156+
return -EIO; \
1157+
} \
1158+
}
12121159

1160+
CHECK_CAP(dma_memcpy, DMA_MEMCPY);
1161+
CHECK_CAP(dma_xor, DMA_XOR);
1162+
CHECK_CAP(dma_xor_val, DMA_XOR_VAL);
1163+
CHECK_CAP(dma_pq, DMA_PQ);
1164+
CHECK_CAP(dma_pq_val, DMA_PQ_VAL);
1165+
CHECK_CAP(dma_memset, DMA_MEMSET);
1166+
CHECK_CAP(dma_interrupt, DMA_INTERRUPT);
1167+
CHECK_CAP(dma_cyclic, DMA_CYCLIC);
1168+
CHECK_CAP(interleaved_dma, DMA_INTERLEAVE);
1169+
1170+
#undef CHECK_CAP
12131171

12141172
if (!device->device_tx_status) {
12151173
dev_err(device->dev, "Device tx_status is not defined\n");

0 commit comments

Comments
 (0)