diff mbox

linux-generic: timer: fix allocation from an empty pool

Message ID 1424781184-31277-1-git-send-email-taras.kondratiuk@linaro.org
State Accepted
Commit d9f0b98f25a0757f0e14bd8f55d72e074780d51f
Headers show

Commit Message

Taras Kondratiuk Feb. 24, 2015, 12:33 p.m. UTC
Allocation timeout from an empty pool causes segmentation fault
because an invalid event it passed to odp_timeout_from_event() which
eventually calls _odp_buffer_type() with ODP_BUFFER_INVALID.

Check allocated buffer before passing it further.

Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
---
 platform/linux-generic/odp_timer.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Bill Fischofer Feb. 24, 2015, 10:13 p.m. UTC | #1
On Tue, Feb 24, 2015 at 6:33 AM, Taras Kondratiuk <
taras.kondratiuk@linaro.org> wrote:

> Allocation timeout from an empty pool causes segmentation fault
> because an invalid event it passed to odp_timeout_from_event() which
> eventually calls _odp_buffer_type() with ODP_BUFFER_INVALID.
>
> Check allocated buffer before passing it further.
>
> Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
>

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


> ---
>  platform/linux-generic/odp_timer.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/platform/linux-generic/odp_timer.c
> b/platform/linux-generic/odp_timer.c
> index 7b5fe15..61a02b6 100644
> --- a/platform/linux-generic/odp_timer.c
> +++ b/platform/linux-generic/odp_timer.c
> @@ -845,6 +845,8 @@ void *odp_timeout_user_ptr(odp_timeout_t tmo)
>  odp_timeout_t odp_timeout_alloc(odp_pool_t pool)
>  {
>         odp_buffer_t buf = odp_buffer_alloc(pool);
> +       if (odp_unlikely(buf == ODP_BUFFER_INVALID))
> +               return ODP_TIMEOUT_INVALID;
>         return odp_timeout_from_event(odp_buffer_to_event(buf));
>  }
>
> --
> 1.9.1
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
>
Taras Kondratiuk Feb. 25, 2015, 9:18 a.m. UTC | #2
On 02/24/2015 02:33 PM, Taras Kondratiuk wrote:
> Allocation timeout from an empty pool causes segmentation fault
> because an invalid event it passed to odp_timeout_from_event() which

Maxim, will you be able to fix a typo during merge?
s/event it passed/event is passed/

> eventually calls _odp_buffer_type() with ODP_BUFFER_INVALID.
> 
> Check allocated buffer before passing it further.
> 
> Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
> ---
>  platform/linux-generic/odp_timer.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c
> index 7b5fe15..61a02b6 100644
> --- a/platform/linux-generic/odp_timer.c
> +++ b/platform/linux-generic/odp_timer.c
> @@ -845,6 +845,8 @@ void *odp_timeout_user_ptr(odp_timeout_t tmo)
>  odp_timeout_t odp_timeout_alloc(odp_pool_t pool)
>  {
>  	odp_buffer_t buf = odp_buffer_alloc(pool);
> +	if (odp_unlikely(buf == ODP_BUFFER_INVALID))
> +		return ODP_TIMEOUT_INVALID;
>  	return odp_timeout_from_event(odp_buffer_to_event(buf));
>  }
>  
>
Maxim Uvarov Feb. 25, 2015, 1:17 p.m. UTC | #3
On 02/25/2015 12:18 PM, Taras Kondratiuk wrote:
> On 02/24/2015 02:33 PM, Taras Kondratiuk wrote:
>> Allocation timeout from an empty pool causes segmentation fault
>> because an invalid event it passed to odp_timeout_from_event() which
> Maxim, will you be able to fix a typo during merge?
> s/event it passed/event is passed/
Sorry I missed that. It's already merged.

Maxim.
>> eventually calls _odp_buffer_type() with ODP_BUFFER_INVALID.
>>
>> Check allocated buffer before passing it further.
>>
>> Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
>> ---
>>   platform/linux-generic/odp_timer.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c
>> index 7b5fe15..61a02b6 100644
>> --- a/platform/linux-generic/odp_timer.c
>> +++ b/platform/linux-generic/odp_timer.c
>> @@ -845,6 +845,8 @@ void *odp_timeout_user_ptr(odp_timeout_t tmo)
>>   odp_timeout_t odp_timeout_alloc(odp_pool_t pool)
>>   {
>>   	odp_buffer_t buf = odp_buffer_alloc(pool);
>> +	if (odp_unlikely(buf == ODP_BUFFER_INVALID))
>> +		return ODP_TIMEOUT_INVALID;
>>   	return odp_timeout_from_event(odp_buffer_to_event(buf));
>>   }
>>   
>>
>
diff mbox

Patch

diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c
index 7b5fe15..61a02b6 100644
--- a/platform/linux-generic/odp_timer.c
+++ b/platform/linux-generic/odp_timer.c
@@ -845,6 +845,8 @@  void *odp_timeout_user_ptr(odp_timeout_t tmo)
 odp_timeout_t odp_timeout_alloc(odp_pool_t pool)
 {
 	odp_buffer_t buf = odp_buffer_alloc(pool);
+	if (odp_unlikely(buf == ODP_BUFFER_INVALID))
+		return ODP_TIMEOUT_INVALID;
 	return odp_timeout_from_event(odp_buffer_to_event(buf));
 }