OSDN Git Service

etnaviv: prevent deadlock in error path
authorPhilipp Zabel <p.zabel@pengutronix.de>
Wed, 13 Sep 2017 14:08:19 +0000 (16:08 +0200)
committerEric Engestrom <eric.engestrom@imgtec.com>
Thu, 14 Sep 2017 09:36:07 +0000 (10:36 +0100)
If drmPrimeFDToHandle fails in etna_bo_from_dmabuf, the function must
not return with the table_lock mutex held. Unlock the mutex in the error
path.

Based on ceb70a6b1015 ("freedreno: prevent deadlock in error path").

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
etnaviv/etnaviv_bo.c

index 4fe877f..78b9cd2 100644 (file)
@@ -206,10 +206,15 @@ struct etna_bo *etna_bo_from_dmabuf(struct etna_device *dev, int fd)
        int ret, size;
        uint32_t handle;
 
+       /* take the lock before calling drmPrimeFDToHandle to avoid
+        * racing against etna_bo_del, which might invalidate the
+        * returned handle.
+        */
        pthread_mutex_lock(&table_lock);
 
        ret = drmPrimeFDToHandle(dev->fd, fd, &handle);
        if (ret) {
+               pthread_mutex_unlock(&table_lock);
                return NULL;
        }