[04/10] gbm: handle queryImage() failure for GBM_BO_IMPORT_EGL_IMAGE

Submitted by Emil Velikov on Oct. 16, 2017, 4:04 p.m.

Details

Message ID 20171016160412.11563-2-emil.l.velikov@gmail.com
State New
Headers show
Series "Series without cover letter" ( rev: 2 ) in Mesa

Not browsing as part of any series.

Commit Message

Emil Velikov Oct. 16, 2017, 4:04 p.m.
From: Emil Velikov <emil.velikov@collabora.com>

The function can fail. Check and teardown accordingly.

Fixes: a43d286ef7f ("gbm: Add import from fd")
Cc: Kristian Høgsberg <krh@bitplanet.net>
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
---
 src/gbm/backends/dri/gbm_dri.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 4a51bd39903..9c9066e6661 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -891,6 +891,7 @@  gbm_dri_bo_import(struct gbm_device *gbm,
    __DRIimage *image;
    unsigned dri_use = 0;
    int gbm_format;
+   unsigned query; /* EGLBoolean, but we cannot include the header */
 
    /* Required for query image WIDTH & HEIGHT */
    if (dri->image == NULL || dri->image->base.version < 4) {
@@ -934,7 +935,12 @@  gbm_dri_bo_import(struct gbm_device *gbm,
 
       image = dri->lookup_image(dri->screen, buffer, dri->lookup_user_data);
       image = dri->image->dupImage(image, NULL);
-      dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_FORMAT, &dri_format);
+      query = dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_FORMAT, &dri_format);
+      if (!query) {
+         errno = EINVAL;
+         dri->image->destroyImage(image);
+         break;
+      }
       gbm_format = gbm_dri_to_gbm_format(dri_format);
       if (gbm_format == 0) {
          errno = EINVAL;

Comments

On Monday, 2017-10-16 16:04:06 +0000, Emil Velikov wrote:
> From: Emil Velikov <emil.velikov@collabora.com>
> 
> The function can fail. Check and teardown accordingly.
> 
> Fixes: a43d286ef7f ("gbm: Add import from fd")
> Cc: Kristian Høgsberg <krh@bitplanet.net>
> Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
> ---
>  src/gbm/backends/dri/gbm_dri.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
> index 4a51bd39903..9c9066e6661 100644
> --- a/src/gbm/backends/dri/gbm_dri.c
> +++ b/src/gbm/backends/dri/gbm_dri.c
> @@ -891,6 +891,7 @@ gbm_dri_bo_import(struct gbm_device *gbm,
>     __DRIimage *image;
>     unsigned dri_use = 0;
>     int gbm_format;
> +   unsigned query; /* EGLBoolean, but we cannot include the header */

`bool`?  <stdbool.h> is already included.

>  
>     /* Required for query image WIDTH & HEIGHT */
>     if (dri->image == NULL || dri->image->base.version < 4) {
> @@ -934,7 +935,12 @@ gbm_dri_bo_import(struct gbm_device *gbm,
>  
>        image = dri->lookup_image(dri->screen, buffer, dri->lookup_user_data);
>        image = dri->image->dupImage(image, NULL);
> -      dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_FORMAT, &dri_format);
> +      query = dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_FORMAT, &dri_format);
> +      if (!query) {
> +         errno = EINVAL;
> +         dri->image->destroyImage(image);
> +         break;
> +      }
>        gbm_format = gbm_dri_to_gbm_format(dri_format);
>        if (gbm_format == 0) {
>           errno = EINVAL;
> -- 
> 2.14.1
>
On 17 October 2017 at 11:09, Eric Engestrom <eric.engestrom@imgtec.com> wrote:
> On Monday, 2017-10-16 16:04:06 +0000, Emil Velikov wrote:
>> From: Emil Velikov <emil.velikov@collabora.com>
>>
>> The function can fail. Check and teardown accordingly.
>>
>> Fixes: a43d286ef7f ("gbm: Add import from fd")
>> Cc: Kristian Høgsberg <krh@bitplanet.net>
>> Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
>> ---
>>  src/gbm/backends/dri/gbm_dri.c | 8 +++++++-
>>  1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
>> index 4a51bd39903..9c9066e6661 100644
>> --- a/src/gbm/backends/dri/gbm_dri.c
>> +++ b/src/gbm/backends/dri/gbm_dri.c
>> @@ -891,6 +891,7 @@ gbm_dri_bo_import(struct gbm_device *gbm,
>>     __DRIimage *image;
>>     unsigned dri_use = 0;
>>     int gbm_format;
>> +   unsigned query; /* EGLBoolean, but we cannot include the header */
>
I stand corrected - s/EGLBoolean/GLboolean/

> `bool`?  <stdbool.h> is already included.
>
Having a skim through dri_interface.h we could drop the GL types in
favour of the standard ones, all together.
Any objection if I do that as a follow-up?

-Emil