patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH] event: fix check in ring_init() in event ring code
@ 2018-08-02  8:36 Harry van Haaren
  2018-08-02 12:43 ` Jerin Jacob
  2018-08-02 14:43 ` [dpdk-stable] [PATCH v2] event: fix check in ring init() " Harry van Haaren
  0 siblings, 2 replies; 4+ messages in thread
From: Harry van Haaren @ 2018-08-02  8:36 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, bruce.richardson, stable, thomas, jerin.jacob

This commit fixes a bug in a 32-bit environment where the
generic ring_init() would fail, but given the interaction
with memzones the next iteration of the event_ring_autotest
would actually *pass* because the ring in question would
exist already an be looked-up.

This commit rightly error checks the result of ring_init(),
and calls rte_free() on the memory as required.

Fixes: dc39e2f359b5 ("eventdev: add ring structure for events")
Cc: bruce.richardson@intel.com
Cc: stable@dpdk.org

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>

---

Cc: thomas@monjalon.net
Cc: jerin.jacob@caviumnetworks.com

Please consider this for RC3, as it fixes the unit tests
on 32-bit systems.
---
 lib/librte_eventdev/rte_event_ring.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/librte_eventdev/rte_event_ring.c b/lib/librte_eventdev/rte_event_ring.c
index eb67751..5791928 100644
--- a/lib/librte_eventdev/rte_event_ring.c
+++ b/lib/librte_eventdev/rte_event_ring.c
@@ -82,11 +82,14 @@ rte_event_ring_create(const char *name, unsigned int count, int socket_id,
 	mz = rte_memzone_reserve(mz_name, ring_size, socket_id, mz_flags);
 	if (mz != NULL) {
 		r = mz->addr;
-		/*
-		 * no need to check return value here, we already checked the
-		 * arguments above
-		 */
-		rte_event_ring_init(r, name, requested_count, flags);
+		/* Check return value in case rte_ring_init() fails on size */
+		int err = rte_event_ring_init(r, name, requested_count, flags);
+		if (err) {
+			RTE_LOG(ERR, RING, "Ring init failed\n");
+			rte_free(te);
+			rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
+			return 0;
+		}
 
 		te->data = (void *) r;
 		r->r.memzone = mz;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-stable] [PATCH] event: fix check in ring_init() in event ring code
  2018-08-02  8:36 [dpdk-stable] [PATCH] event: fix check in ring_init() in event ring code Harry van Haaren
@ 2018-08-02 12:43 ` Jerin Jacob
  2018-08-02 14:43 ` [dpdk-stable] [PATCH v2] event: fix check in ring init() " Harry van Haaren
  1 sibling, 0 replies; 4+ messages in thread
From: Jerin Jacob @ 2018-08-02 12:43 UTC (permalink / raw)
  To: Harry van Haaren; +Cc: dev, bruce.richardson, stable, thomas

-----Original Message-----
> Date: Thu, 2 Aug 2018 09:36:04 +0100
> From: Harry van Haaren <harry.van.haaren@intel.com>
> To: dev@dpdk.org
> CC: Harry van Haaren <harry.van.haaren@intel.com>,
>  bruce.richardson@intel.com, stable@dpdk.org, thomas@monjalon.net,
>  jerin.jacob@caviumnetworks.com
> Subject: [PATCH] event: fix check in ring_init() in event ring code
> X-Mailer: git-send-email 2.7.4
> 
> External Email
> 
> This commit fixes a bug in a 32-bit environment where the
> generic ring_init() would fail, but given the interaction
> with memzones the next iteration of the event_ring_autotest
> would actually *pass* because the ring in question would
> exist already an be looked-up.
> 
> This commit rightly error checks the result of ring_init(),
> and calls rte_free() on the memory as required.
> 
> Fixes: dc39e2f359b5 ("eventdev: add ring structure for events")
> Cc: bruce.richardson@intel.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>


There is one check-git-log.sh issue

Wrong headline format:
	event: fix check in ring_init() in event ring code

> 
> ---
> 
> Cc: thomas@monjalon.net
> Cc: jerin.jacob@caviumnetworks.com
> 
> Please consider this for RC3, as it fixes the unit tests
> on 32-bit systems.
> ---
>  lib/librte_eventdev/rte_event_ring.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/librte_eventdev/rte_event_ring.c b/lib/librte_eventdev/rte_event_ring.c
> index eb67751..5791928 100644
> --- a/lib/librte_eventdev/rte_event_ring.c
> +++ b/lib/librte_eventdev/rte_event_ring.c
> @@ -82,11 +82,14 @@ rte_event_ring_create(const char *name, unsigned int count, int socket_id,
>         mz = rte_memzone_reserve(mz_name, ring_size, socket_id, mz_flags);
>         if (mz != NULL) {
>                 r = mz->addr;
> -               /*
> -                * no need to check return value here, we already checked the
> -                * arguments above
> -                */
> -               rte_event_ring_init(r, name, requested_count, flags);
> +               /* Check return value in case rte_ring_init() fails on size */
> +               int err = rte_event_ring_init(r, name, requested_count, flags);
> +               if (err) {
> +                       RTE_LOG(ERR, RING, "Ring init failed\n");

shouldn't we do rte_memzone_free(mz);

> +                       rte_free(te);
> +                       rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
> +                       return 0;

It should be return NULL?

> +               }
> 

With above changes:

Acked-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>

>                 te->data = (void *) r;
>                 r->r.memzone = mz;
> --
> 2.7.4
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [dpdk-stable] [PATCH v2] event: fix check in ring init() in event ring code
  2018-08-02  8:36 [dpdk-stable] [PATCH] event: fix check in ring_init() in event ring code Harry van Haaren
  2018-08-02 12:43 ` Jerin Jacob
@ 2018-08-02 14:43 ` Harry van Haaren
  2018-08-05 12:52   ` [dpdk-stable] [dpdk-dev] " Thomas Monjalon
  1 sibling, 1 reply; 4+ messages in thread
From: Harry van Haaren @ 2018-08-02 14:43 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, bruce.richardson, stable, thomas, jerin.jacob

This commit fixes a bug in a 32-bit environment where the
generic ring_init() would fail, but given the interaction
with memzones the next iteration of the event_ring_autotest
would actually *pass* because the ring in question would
exist already an be looked-up.

This commit rightly error checks the result of ring_init(),
and calls rte_free() on the memory as required.

Fixes: dc39e2f359b5 ("eventdev: add ring structure for events")
Cc: bruce.richardson@intel.com
Cc: stable@dpdk.org

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
Acked-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>

---

v2:
- Removed _ from headline for check git log (Jerin)
- Added memzone free (good catch, thanks Jerin)
- Return NULL instead of 0 (Jerin)
- Added Jerin's Ack

Cc: thomas@monjalon.net
Cc: jerin.jacob@caviumnetworks.com

Please consider this for RC3, as it fixes the unit tests
on 32-bit systems.
---
 lib/librte_eventdev/rte_event_ring.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/lib/librte_eventdev/rte_event_ring.c b/lib/librte_eventdev/rte_event_ring.c
index eb67751..16d02a9 100644
--- a/lib/librte_eventdev/rte_event_ring.c
+++ b/lib/librte_eventdev/rte_event_ring.c
@@ -82,11 +82,16 @@ rte_event_ring_create(const char *name, unsigned int count, int socket_id,
 	mz = rte_memzone_reserve(mz_name, ring_size, socket_id, mz_flags);
 	if (mz != NULL) {
 		r = mz->addr;
-		/*
-		 * no need to check return value here, we already checked the
-		 * arguments above
-		 */
-		rte_event_ring_init(r, name, requested_count, flags);
+		/* Check return value in case rte_ring_init() fails on size */
+		int err = rte_event_ring_init(r, name, requested_count, flags);
+		if (err) {
+			RTE_LOG(ERR, RING, "Ring init failed\n");
+			if (rte_memzone_free(mz) != 0)
+				RTE_LOG(ERR, RING, "Cannot free memzone\n");
+			rte_free(te);
+			rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
+			return NULL;
+		}
 
 		te->data = (void *) r;
 		r->r.memzone = mz;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-stable] [dpdk-dev] [PATCH v2] event: fix check in ring init() in event ring code
  2018-08-02 14:43 ` [dpdk-stable] [PATCH v2] event: fix check in ring init() " Harry van Haaren
@ 2018-08-05 12:52   ` Thomas Monjalon
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Monjalon @ 2018-08-05 12:52 UTC (permalink / raw)
  To: Harry van Haaren; +Cc: dev, bruce.richardson, stable, jerin.jacob

02/08/2018 16:43, Harry van Haaren:
> This commit fixes a bug in a 32-bit environment where the
> generic ring_init() would fail, but given the interaction
> with memzones the next iteration of the event_ring_autotest
> would actually *pass* because the ring in question would
> exist already an be looked-up.
> 
> This commit rightly error checks the result of ring_init(),
> and calls rte_free() on the memory as required.
> 
> Fixes: dc39e2f359b5 ("eventdev: add ring structure for events")
> Cc: bruce.richardson@intel.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
> Acked-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
> 
> ---
> 
> v2:
> - Removed _ from headline for check git log (Jerin)

This is not the spirit of this check.
You are expected to not use function names at all,
in order to provide a title readable by someone who does not know
the function or structure names of this area.

In this case, it can be:
	event: fix ring init failure handling

> - Added memzone free (good catch, thanks Jerin)
> - Return NULL instead of 0 (Jerin)
> - Added Jerin's Ack
> 
> Cc: thomas@monjalon.net
> Cc: jerin.jacob@caviumnetworks.com
> 
> Please consider this for RC3, as it fixes the unit tests
> on 32-bit systems.

Applied, thanks

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-08-05 12:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-02  8:36 [dpdk-stable] [PATCH] event: fix check in ring_init() in event ring code Harry van Haaren
2018-08-02 12:43 ` Jerin Jacob
2018-08-02 14:43 ` [dpdk-stable] [PATCH v2] event: fix check in ring init() " Harry van Haaren
2018-08-05 12:52   ` [dpdk-stable] [dpdk-dev] " Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).