diff mbox

[1/1,v1] examples: odp_ipsec: handle alloc_pkt_ctx failure

Message ID 1428474470-30400-1-git-send-email-alexandru.badicioiu@linaro.org
State Accepted
Commit 38dfc2770a0a8218d05c805faabd011d17a907fa
Headers show

Commit Message

Alexandru Badicioiu April 8, 2015, 6:27 a.m. UTC
From: Alexandru Badicioiu <alexandru.badicioiu@linaro.org>

Application should continue in case a packet context cannot be
allocated.

Signed-off-by: Alexandru Badicioiu <alexandru.badicioiu@linaro.org>
---
 example/ipsec/odp_ipsec.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Maxim Uvarov April 10, 2015, 4:14 p.m. UTC | #1
Merged,
Maxim.

On 04/08/15 09:27, alexandru.badicioiu@linaro.org wrote:
> From: Alexandru Badicioiu <alexandru.badicioiu@linaro.org>
>
> Application should continue in case a packet context cannot be
> allocated.
>
> Signed-off-by: Alexandru Badicioiu <alexandru.badicioiu@linaro.org>
> ---
>   example/ipsec/odp_ipsec.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
> index 56e9aa8..0cbf5b4 100644
> --- a/example/ipsec/odp_ipsec.c
> +++ b/example/ipsec/odp_ipsec.c
> @@ -187,9 +187,8 @@ pkt_ctx_t *alloc_pkt_ctx(odp_packet_t pkt)
>   	odp_buffer_t ctx_buf = odp_buffer_alloc(ctx_pool);
>   	pkt_ctx_t *ctx;
>   
> -	/* There should always be enough contexts */
>   	if (odp_unlikely(ODP_BUFFER_INVALID == ctx_buf))
> -		abort();
> +		return NULL;
>   
>   	ctx = odp_buffer_addr(ctx_buf);
>   	memset(ctx, 0, sizeof(*ctx));
> @@ -1017,6 +1016,10 @@ void *pktio_thread(void *arg EXAMPLE_UNUSED)
>   				ctx = get_pkt_ctx_from_pkt(pkt);
>   			} else {
>   				ctx = alloc_pkt_ctx(pkt);
> +				if (!ctx) {
> +					odp_packet_free(pkt);
> +					continue;
> +				}
>   				ctx->state = PKT_STATE_INPUT_VERIFY;
>   			}
>   		} else if (ODP_EVENT_CRYPTO_COMPL == odp_event_type(ev)) {
diff mbox

Patch

diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
index 56e9aa8..0cbf5b4 100644
--- a/example/ipsec/odp_ipsec.c
+++ b/example/ipsec/odp_ipsec.c
@@ -187,9 +187,8 @@  pkt_ctx_t *alloc_pkt_ctx(odp_packet_t pkt)
 	odp_buffer_t ctx_buf = odp_buffer_alloc(ctx_pool);
 	pkt_ctx_t *ctx;
 
-	/* There should always be enough contexts */
 	if (odp_unlikely(ODP_BUFFER_INVALID == ctx_buf))
-		abort();
+		return NULL;
 
 	ctx = odp_buffer_addr(ctx_buf);
 	memset(ctx, 0, sizeof(*ctx));
@@ -1017,6 +1016,10 @@  void *pktio_thread(void *arg EXAMPLE_UNUSED)
 				ctx = get_pkt_ctx_from_pkt(pkt);
 			} else {
 				ctx = alloc_pkt_ctx(pkt);
+				if (!ctx) {
+					odp_packet_free(pkt);
+					continue;
+				}
 				ctx->state = PKT_STATE_INPUT_VERIFY;
 			}
 		} else if (ODP_EVENT_CRYPTO_COMPL == odp_event_type(ev)) {