diff mbox

[1/3] linux-gen: dpdk: fix buffer freeing in mbuf_to_pkt()

Message ID 1472653448-23947-1-git-send-email-matias.elo@nokia.com
State Accepted
Commit ffda91e73c9153d7a7b7d7948de2f902c261d36e
Headers show

Commit Message

Elo, Matias (Nokia - FI/Espoo) Aug. 31, 2016, 2:24 p.m. UTC
Free dpdk mbufs and odp packets correctly when packet_alloc_multi() isn't
able to allocate all requested packets.

Signed-off-by: Matias Elo <matias.elo@nokia.com>

---
 platform/linux-generic/pktio/dpdk.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

-- 
2.7.4

Comments

Bill Fischofer Aug. 31, 2016, 10:46 p.m. UTC | #1
For this series:

Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org>

On Wed, Aug 31, 2016 at 9:24 AM, Matias Elo <matias.elo@nokia.com> wrote:

> Free dpdk mbufs and odp packets correctly when packet_alloc_multi() isn't

> able to allocate all requested packets.

>

> Signed-off-by: Matias Elo <matias.elo@nokia.com>

> ---

>  platform/linux-generic/pktio/dpdk.c | 10 ++++++++--

>  1 file changed, 8 insertions(+), 2 deletions(-)

>

> diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/

> pktio/dpdk.c

> index b45c9a8..0a800b7 100644

> --- a/platform/linux-generic/pktio/dpdk.c

> +++ b/platform/linux-generic/pktio/dpdk.c

> @@ -755,6 +755,12 @@ static inline int mbuf_to_pkt(pktio_entry_t

> *pktio_entry,

>         alloc_len = pktio_entry->s.pkt_dpdk.data_room;

>

>         num = packet_alloc_multi(pool, alloc_len, pkt_table, mbuf_num);

> +       if (num != mbuf_num) {

> +               ODP_DBG("packet_alloc_multi() unable to allocate all

> packets: "

> +                       "%d/%" PRIu16 " allocated\n", num, mbuf_num);

> +               for (i = num; i < mbuf_num; i++)

> +                       rte_pktmbuf_free(mbuf_table[i]);

> +       }

>

>         for (i = 0; i < num; i++) {

>                 odp_packet_hdr_t parsed_hdr;

> @@ -807,9 +813,9 @@ static inline int mbuf_to_pkt(pktio_entry_t

> *pktio_entry,

>         return nb_pkts;

>

>  fail:

> -       odp_packet_free_multi(&pkt_table[i], mbuf_num - i);

> +       odp_packet_free_multi(&pkt_table[i], num - i);

>

> -       for (j = i; j < mbuf_num; j++)

> +       for (j = i; j < num; j++)

>                 rte_pktmbuf_free(mbuf_table[j]);

>

>         return (i > 0 ? i : -1);

> --

> 2.7.4

>

>
Maxim Uvarov Sept. 1, 2016, 12:35 p.m. UTC | #2
Merged,
Maxim.

On 09/01/16 01:46, Bill Fischofer wrote:
> For this series:

>

> Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org>

>

> On Wed, Aug 31, 2016 at 9:24 AM, Matias Elo <matias.elo@nokia.com> wrote:

>

>> Free dpdk mbufs and odp packets correctly when packet_alloc_multi() isn't

>> able to allocate all requested packets.

>>

>> Signed-off-by: Matias Elo <matias.elo@nokia.com>

>> ---

>>   platform/linux-generic/pktio/dpdk.c | 10 ++++++++--

>>   1 file changed, 8 insertions(+), 2 deletions(-)

>>

>> diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/

>> pktio/dpdk.c

>> index b45c9a8..0a800b7 100644

>> --- a/platform/linux-generic/pktio/dpdk.c

>> +++ b/platform/linux-generic/pktio/dpdk.c

>> @@ -755,6 +755,12 @@ static inline int mbuf_to_pkt(pktio_entry_t

>> *pktio_entry,

>>          alloc_len = pktio_entry->s.pkt_dpdk.data_room;

>>

>>          num = packet_alloc_multi(pool, alloc_len, pkt_table, mbuf_num);

>> +       if (num != mbuf_num) {

>> +               ODP_DBG("packet_alloc_multi() unable to allocate all

>> packets: "

>> +                       "%d/%" PRIu16 " allocated\n", num, mbuf_num);

>> +               for (i = num; i < mbuf_num; i++)

>> +                       rte_pktmbuf_free(mbuf_table[i]);

>> +       }

>>

>>          for (i = 0; i < num; i++) {

>>                  odp_packet_hdr_t parsed_hdr;

>> @@ -807,9 +813,9 @@ static inline int mbuf_to_pkt(pktio_entry_t

>> *pktio_entry,

>>          return nb_pkts;

>>

>>   fail:

>> -       odp_packet_free_multi(&pkt_table[i], mbuf_num - i);

>> +       odp_packet_free_multi(&pkt_table[i], num - i);

>>

>> -       for (j = i; j < mbuf_num; j++)

>> +       for (j = i; j < num; j++)

>>                  rte_pktmbuf_free(mbuf_table[j]);

>>

>>          return (i > 0 ? i : -1);

>> --

>> 2.7.4

>>

>>
diff mbox

Patch

diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c
index b45c9a8..0a800b7 100644
--- a/platform/linux-generic/pktio/dpdk.c
+++ b/platform/linux-generic/pktio/dpdk.c
@@ -755,6 +755,12 @@  static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry,
 	alloc_len = pktio_entry->s.pkt_dpdk.data_room;
 
 	num = packet_alloc_multi(pool, alloc_len, pkt_table, mbuf_num);
+	if (num != mbuf_num) {
+		ODP_DBG("packet_alloc_multi() unable to allocate all packets: "
+			"%d/%" PRIu16 " allocated\n", num, mbuf_num);
+		for (i = num; i < mbuf_num; i++)
+			rte_pktmbuf_free(mbuf_table[i]);
+	}
 
 	for (i = 0; i < num; i++) {
 		odp_packet_hdr_t parsed_hdr;
@@ -807,9 +813,9 @@  static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry,
 	return nb_pkts;
 
 fail:
-	odp_packet_free_multi(&pkt_table[i], mbuf_num - i);
+	odp_packet_free_multi(&pkt_table[i], num - i);
 
-	for (j = i; j < mbuf_num; j++)
+	for (j = i; j < num; j++)
 		rte_pktmbuf_free(mbuf_table[j]);
 
 	return (i > 0 ? i : -1);