linux-generic: pool: don't allocate buffers from invalid pool

Message ID 20170309120107.26687-1-dmitry.ereminsolenikov@linaro.org
State New
Headers show

Commit Message

Dmitry Eremin-Solenikov March 9, 2017, 12:01 p.m.
Check that passed pool is not ODP_POOL_INVALID before goint to try to
allocate buffers from that pool.

Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

---
 platform/linux-generic/odp_pool.c | 3 +++
 1 file changed, 3 insertions(+)

-- 
2.11.0

Comments

Maxim Uvarov March 9, 2017, 12:21 p.m. | #1
On 03/09/2017 03:01 PM, Dmitry Eremin-Solenikov wrote:
> Check that passed pool is not ODP_POOL_INVALID before goint to try to

> allocate buffers from that pool.

>

> Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

> ---

>   platform/linux-generic/odp_pool.c | 3 +++

>   1 file changed, 3 insertions(+)

>

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

> index cf7c2c41..f0b64932 100644

> --- a/platform/linux-generic/odp_pool.c

> +++ b/platform/linux-generic/odp_pool.c

> @@ -768,6 +768,9 @@ odp_buffer_t odp_buffer_alloc(odp_pool_t pool_hdl)

>   	pool_t *pool;

>   	int ret;

>   

> +	if (ODP_POOL_INVALID == pool_hdl)

> +		return ODP_BUFFER_INVALID;

> +

That is fast path function. Or is has to be under ifdef ODP_DEBUG or not 
completely be here. Right behavior is
segfault on bad input.

Maxim.
>   	pool = pool_entry_from_hdl(pool_hdl);

>   	ret = buffer_alloc_multi(pool, &buf, NULL, 1);

>
Bill Fischofer March 9, 2017, 12:40 p.m. | #2
On Thu, Mar 9, 2017 at 1:21 PM Maxim Uvarov <maxim.uvarov@linaro.org> wrote:

> On 03/09/2017 03:01 PM, Dmitry Eremin-Solenikov wrote:

> > Check that passed pool is not ODP_POOL_INVALID before goint to try to

> > allocate buffers from that pool.

> >

> > Signed-off-by: Dmitry Eremin-Solenikov <

> dmitry.ereminsolenikov@linaro.org>

> > ---

> >   platform/linux-generic/odp_pool.c | 3 +++

> >   1 file changed, 3 insertions(+)

> >

> > diff --git a/platform/linux-generic/odp_pool.c

> b/platform/linux-generic/odp_pool.c

> > index cf7c2c41..f0b64932 100644

> > --- a/platform/linux-generic/odp_pool.c

> > +++ b/platform/linux-generic/odp_pool.c

> > @@ -768,6 +768,9 @@ odp_buffer_t odp_buffer_alloc(odp_pool_t pool_hdl)

> >       pool_t *pool;

> >       int ret;

> >

> > +     if (ODP_POOL_INVALID == pool_hdl)

> > +             return ODP_BUFFER_INVALID;

> > +

> That is fast path function. Or is has to be under ifdef ODP_DEBUG or not

> completely be here. Right behavior is

> segfault on bad input.

>

> Maxim.




The correct test is to use ODP_ASSERT as that only expands for debug builds.


> >       pool = pool_entry_from_hdl(pool_hdl);

> >       ret = buffer_alloc_multi(pool, &buf, NULL, 1);

> >

>

>

>

Patch hide | download patch | download mbox

diff --git a/platform/linux-generic/odp_pool.c b/platform/linux-generic/odp_pool.c
index cf7c2c41..f0b64932 100644
--- a/platform/linux-generic/odp_pool.c
+++ b/platform/linux-generic/odp_pool.c
@@ -768,6 +768,9 @@  odp_buffer_t odp_buffer_alloc(odp_pool_t pool_hdl)
 	pool_t *pool;
 	int ret;
 
+	if (ODP_POOL_INVALID == pool_hdl)
+		return ODP_BUFFER_INVALID;
+
 	pool = pool_entry_from_hdl(pool_hdl);
 	ret = buffer_alloc_multi(pool, &buf, NULL, 1);