Merge "msm: ipa3: Fix to add check for dma_map_single return values"

This commit is contained in:
Linux Build Service Account 2017-06-05 04:34:34 -07:00 committed by Gerrit - the friendly Code Review server
commit c403d314f9
2 changed files with 37 additions and 38 deletions

View file

@ -356,7 +356,7 @@ int ipa3_send_one(struct ipa3_sys_context *sys, struct ipa3_desc *desc,
dma_address = desc->dma_address; dma_address = desc->dma_address;
tx_pkt->no_unmap_dma = true; tx_pkt->no_unmap_dma = true;
} }
if (!dma_address) { if (dma_mapping_error(ipa3_ctx->pdev, dma_address)) {
IPAERR("failed to DMA wrap\n"); IPAERR("failed to DMA wrap\n");
goto fail_dma_map; goto fail_dma_map;
} }
@ -471,7 +471,6 @@ int ipa3_send(struct ipa3_sys_context *sys,
int i = 0; int i = 0;
int j; int j;
int result; int result;
int fail_dma_wrap = 0;
uint size; uint size;
u32 mem_flag = GFP_ATOMIC; u32 mem_flag = GFP_ATOMIC;
int ipa_ep_idx; int ipa_ep_idx;
@ -527,7 +526,7 @@ int ipa3_send(struct ipa3_sys_context *sys,
} }
dma_addr = dma_map_single(ipa3_ctx->pdev, dma_addr = dma_map_single(ipa3_ctx->pdev,
transfer.iovec, size, DMA_TO_DEVICE); transfer.iovec, size, DMA_TO_DEVICE);
if (!dma_addr) { if (dma_mapping_error(ipa3_ctx->pdev, dma_addr)) {
IPAERR("dma_map_single failed\n"); IPAERR("dma_map_single failed\n");
kfree(transfer.iovec); kfree(transfer.iovec);
return -EFAULT; return -EFAULT;
@ -540,7 +539,6 @@ int ipa3_send(struct ipa3_sys_context *sys,
spin_lock_bh(&sys->spinlock); spin_lock_bh(&sys->spinlock);
for (i = 0; i < num_desc; i++) { for (i = 0; i < num_desc; i++) {
fail_dma_wrap = 0;
tx_pkt = kmem_cache_zalloc(ipa3_ctx->tx_pkt_wrapper_cache, tx_pkt = kmem_cache_zalloc(ipa3_ctx->tx_pkt_wrapper_cache,
mem_flag); mem_flag);
if (!tx_pkt) { if (!tx_pkt) {
@ -563,7 +561,7 @@ int ipa3_send(struct ipa3_sys_context *sys,
if (ipa_populate_tag_field(&desc[i], tx_pkt, if (ipa_populate_tag_field(&desc[i], tx_pkt,
&tag_pyld_ret)) { &tag_pyld_ret)) {
IPAERR("Failed to populate tag field\n"); IPAERR("Failed to populate tag field\n");
goto failure; goto failure_dma_map;
} }
} }
@ -579,11 +577,6 @@ int ipa3_send(struct ipa3_sys_context *sys,
tx_pkt->mem.base, tx_pkt->mem.base,
tx_pkt->mem.size, tx_pkt->mem.size,
DMA_TO_DEVICE); DMA_TO_DEVICE);
if (!tx_pkt->mem.phys_base) {
IPAERR("failed to do dma map.\n");
fail_dma_wrap = 1;
goto failure;
}
} else { } else {
tx_pkt->mem.phys_base = tx_pkt->mem.phys_base =
desc[i].dma_address; desc[i].dma_address;
@ -599,17 +592,17 @@ int ipa3_send(struct ipa3_sys_context *sys,
desc[i].frag, desc[i].frag,
0, tx_pkt->mem.size, 0, tx_pkt->mem.size,
DMA_TO_DEVICE); DMA_TO_DEVICE);
if (!tx_pkt->mem.phys_base) {
IPAERR("dma map failed\n");
fail_dma_wrap = 1;
goto failure;
}
} else { } else {
tx_pkt->mem.phys_base = tx_pkt->mem.phys_base =
desc[i].dma_address; desc[i].dma_address;
tx_pkt->no_unmap_dma = true; tx_pkt->no_unmap_dma = true;
} }
} }
if (dma_mapping_error(ipa3_ctx->pdev, tx_pkt->mem.phys_base)) {
IPAERR("failed to do dma map.\n");
goto failure_dma_map;
}
tx_pkt->sys = sys; tx_pkt->sys = sys;
tx_pkt->callback = desc[i].callback; tx_pkt->callback = desc[i].callback;
tx_pkt->user1 = desc[i].user1; tx_pkt->user1 = desc[i].user1;
@ -704,29 +697,31 @@ int ipa3_send(struct ipa3_sys_context *sys,
spin_unlock_bh(&sys->spinlock); spin_unlock_bh(&sys->spinlock);
return 0; return 0;
failure_dma_map:
kmem_cache_free(ipa3_ctx->tx_pkt_wrapper_cache, tx_pkt);
failure: failure:
ipahal_destroy_imm_cmd(tag_pyld_ret); ipahal_destroy_imm_cmd(tag_pyld_ret);
tx_pkt = tx_pkt_first; tx_pkt = tx_pkt_first;
for (j = 0; j < i; j++) { for (j = 0; j < i; j++) {
next_pkt = list_next_entry(tx_pkt, link); next_pkt = list_next_entry(tx_pkt, link);
list_del(&tx_pkt->link); list_del(&tx_pkt->link);
if (!tx_pkt->no_unmap_dma) {
if (desc[j].type != IPA_DATA_DESC_SKB_PAGED) { if (desc[j].type != IPA_DATA_DESC_SKB_PAGED) {
dma_unmap_single(ipa3_ctx->pdev, tx_pkt->mem.phys_base, dma_unmap_single(ipa3_ctx->pdev,
tx_pkt->mem.size, tx_pkt->mem.phys_base,
DMA_TO_DEVICE); tx_pkt->mem.size, DMA_TO_DEVICE);
} else { } else {
dma_unmap_page(ipa3_ctx->pdev, tx_pkt->mem.phys_base, dma_unmap_page(ipa3_ctx->pdev,
tx_pkt->mem.phys_base,
tx_pkt->mem.size, tx_pkt->mem.size,
DMA_TO_DEVICE); DMA_TO_DEVICE);
} }
}
kmem_cache_free(ipa3_ctx->tx_pkt_wrapper_cache, tx_pkt); kmem_cache_free(ipa3_ctx->tx_pkt_wrapper_cache, tx_pkt);
tx_pkt = next_pkt; tx_pkt = next_pkt;
} }
if (j < num_desc)
/* last desc failed */
if (fail_dma_wrap)
kmem_cache_free(ipa3_ctx->tx_pkt_wrapper_cache, tx_pkt);
if (ipa3_ctx->transport_prototype == IPA_TRANSPORT_TYPE_GSI) { if (ipa3_ctx->transport_prototype == IPA_TRANSPORT_TYPE_GSI) {
kfree(gsi_xfer_elem_array); kfree(gsi_xfer_elem_array);
} else { } else {
@ -1973,8 +1968,7 @@ begin:
rx_pkt->data.dma_addr = dma_map_single(ipa3_ctx->pdev, ptr, rx_pkt->data.dma_addr = dma_map_single(ipa3_ctx->pdev, ptr,
sys->rx_buff_sz, sys->rx_buff_sz,
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
if (rx_pkt->data.dma_addr == 0 || if (dma_mapping_error(ipa3_ctx->pdev, rx_pkt->data.dma_addr)) {
rx_pkt->data.dma_addr == ~0) {
pr_err_ratelimited("%s dma map fail %p for %p sys=%p\n", pr_err_ratelimited("%s dma map fail %p for %p sys=%p\n",
__func__, (void *)rx_pkt->data.dma_addr, __func__, (void *)rx_pkt->data.dma_addr,
ptr, sys); ptr, sys);
@ -2141,8 +2135,7 @@ static void ipa3_alloc_wlan_rx_common_cache(u32 size)
ptr = skb_put(rx_pkt->data.skb, IPA_WLAN_RX_BUFF_SZ); ptr = skb_put(rx_pkt->data.skb, IPA_WLAN_RX_BUFF_SZ);
rx_pkt->data.dma_addr = dma_map_single(ipa3_ctx->pdev, ptr, rx_pkt->data.dma_addr = dma_map_single(ipa3_ctx->pdev, ptr,
IPA_WLAN_RX_BUFF_SZ, DMA_FROM_DEVICE); IPA_WLAN_RX_BUFF_SZ, DMA_FROM_DEVICE);
if (rx_pkt->data.dma_addr == 0 || if (dma_mapping_error(ipa3_ctx->pdev, rx_pkt->data.dma_addr)) {
rx_pkt->data.dma_addr == ~0) {
IPAERR("dma_map_single failure %p for %p\n", IPAERR("dma_map_single failure %p for %p\n",
(void *)rx_pkt->data.dma_addr, ptr); (void *)rx_pkt->data.dma_addr, ptr);
goto fail_dma_mapping; goto fail_dma_mapping;
@ -2213,8 +2206,7 @@ static void ipa3_replenish_rx_cache(struct ipa3_sys_context *sys)
rx_pkt->data.dma_addr = dma_map_single(ipa3_ctx->pdev, ptr, rx_pkt->data.dma_addr = dma_map_single(ipa3_ctx->pdev, ptr,
sys->rx_buff_sz, sys->rx_buff_sz,
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
if (rx_pkt->data.dma_addr == 0 || if (dma_mapping_error(ipa3_ctx->pdev, rx_pkt->data.dma_addr)) {
rx_pkt->data.dma_addr == ~0) {
IPAERR("dma_map_single failure %p for %p\n", IPAERR("dma_map_single failure %p for %p\n",
(void *)rx_pkt->data.dma_addr, ptr); (void *)rx_pkt->data.dma_addr, ptr);
goto fail_dma_mapping; goto fail_dma_mapping;
@ -2304,8 +2296,8 @@ static void ipa3_replenish_rx_cache_recycle(struct ipa3_sys_context *sys)
ptr = skb_put(rx_pkt->data.skb, sys->rx_buff_sz); ptr = skb_put(rx_pkt->data.skb, sys->rx_buff_sz);
rx_pkt->data.dma_addr = dma_map_single(ipa3_ctx->pdev, rx_pkt->data.dma_addr = dma_map_single(ipa3_ctx->pdev,
ptr, sys->rx_buff_sz, DMA_FROM_DEVICE); ptr, sys->rx_buff_sz, DMA_FROM_DEVICE);
if (rx_pkt->data.dma_addr == 0 || if (dma_mapping_error(ipa3_ctx->pdev,
rx_pkt->data.dma_addr == ~0) { rx_pkt->data.dma_addr)) {
IPAERR("dma_map_single failure %p for %p\n", IPAERR("dma_map_single failure %p for %p\n",
(void *)rx_pkt->data.dma_addr, ptr); (void *)rx_pkt->data.dma_addr, ptr);
goto fail_dma_mapping; goto fail_dma_mapping;
@ -2320,8 +2312,8 @@ static void ipa3_replenish_rx_cache_recycle(struct ipa3_sys_context *sys)
ptr = skb_put(rx_pkt->data.skb, sys->rx_buff_sz); ptr = skb_put(rx_pkt->data.skb, sys->rx_buff_sz);
rx_pkt->data.dma_addr = dma_map_single(ipa3_ctx->pdev, rx_pkt->data.dma_addr = dma_map_single(ipa3_ctx->pdev,
ptr, sys->rx_buff_sz, DMA_FROM_DEVICE); ptr, sys->rx_buff_sz, DMA_FROM_DEVICE);
if (rx_pkt->data.dma_addr == 0 || if (dma_mapping_error(ipa3_ctx->pdev,
rx_pkt->data.dma_addr == ~0) { rx_pkt->data.dma_addr)) {
IPAERR("dma_map_single failure %p for %p\n", IPAERR("dma_map_single failure %p for %p\n",
(void *)rx_pkt->data.dma_addr, ptr); (void *)rx_pkt->data.dma_addr, ptr);
goto fail_dma_mapping; goto fail_dma_mapping;

View file

@ -494,6 +494,10 @@ static int __ipa_add_hdr(struct ipa_hdr_add *hdr)
entry->hdr, entry->hdr,
entry->hdr_len, entry->hdr_len,
DMA_TO_DEVICE); DMA_TO_DEVICE);
if (dma_mapping_error(ipa3_ctx->pdev, entry->phys_base)) {
IPAERR("dma_map_single failure for entry\n");
goto fail_dma_mapping;
}
} else { } else {
entry->is_hdr_proc_ctx = false; entry->is_hdr_proc_ctx = false;
if (list_empty(&htbl->head_free_offset_list[bin])) { if (list_empty(&htbl->head_free_offset_list[bin])) {
@ -569,6 +573,9 @@ fail_add_proc_ctx:
list_del(&entry->link); list_del(&entry->link);
dma_unmap_single(ipa3_ctx->pdev, entry->phys_base, dma_unmap_single(ipa3_ctx->pdev, entry->phys_base,
entry->hdr_len, DMA_TO_DEVICE); entry->hdr_len, DMA_TO_DEVICE);
fail_dma_mapping:
entry->is_hdr_proc_ctx = false;
bad_hdr_len: bad_hdr_len:
entry->cookie = 0; entry->cookie = 0;
kmem_cache_free(ipa3_ctx->hdr_cache, entry); kmem_cache_free(ipa3_ctx->hdr_cache, entry);