From ba7f7978679a4101df96818969c8891a6358b3d1 Mon Sep 17 00:00:00 2001 From: Weifeng Liu Date: Wed, 19 Feb 2025 03:02:17 +0000 Subject: [PATCH 1/2] Fix double free in driver loading Tracked-On: OAM-131321 Signed-off-by: Weifeng Liu --- cros_gralloc/cros_gralloc_driver.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cros_gralloc/cros_gralloc_driver.cc b/cros_gralloc/cros_gralloc_driver.cc index 39784c45..cc60ba15 100644 --- a/cros_gralloc/cros_gralloc_driver.cc +++ b/cros_gralloc/cros_gralloc_driver.cc @@ -204,11 +204,8 @@ cros_gralloc_driver::cros_gralloc_driver(): drivers_(GPU_GRP_TYPE_NR, nullptr) } // hit any of undesired render node - if (j < ARRAY_SIZE(undesired)) { - drmFreeVersion(version); - close(fd); + if (j < ARRAY_SIZE(undesired)) continue; - } if (fallback_fd == -1) fallback_fd = fd; From 4b38f78be38040df90deef27c199c88c8261ff27 Mon Sep 17 00:00:00 2001 From: Weifeng Liu Date: Mon, 24 Mar 2025 14:26:56 +0000 Subject: [PATCH 2/2] Fix bugs in driver loading * Reserve enough space for storing drm fds. * Don't close fd when we want to destroy a driver and recreate it soon. Tracked-On: OAM-131321 Signed-off-by: Weifeng Liu --- cros_gralloc/cros_gralloc_driver.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cros_gralloc/cros_gralloc_driver.cc b/cros_gralloc/cros_gralloc_driver.cc index cc60ba15..655c827c 100644 --- a/cros_gralloc/cros_gralloc_driver.cc +++ b/cros_gralloc/cros_gralloc_driver.cc @@ -174,7 +174,7 @@ cros_gralloc_driver::cros_gralloc_driver(): drivers_(GPU_GRP_TYPE_NR, nullptr) int fallback_fd = -1; drmVersionPtr version; const int render_num = 10; - std::vector driver_fds{GPU_GRP_TYPE_NR, -1}; + std::vector driver_fds(GPU_GRP_TYPE_NR, -1); char buf[PROP_VALUE_MAX]; property_get("ro.product.device", buf, "unknown"); @@ -252,7 +252,8 @@ cros_gralloc_driver::cros_gralloc_driver(): drivers_(GPU_GRP_TYPE_NR, nullptr) if (!(gpu_grp_type_ & (1ull << i))) continue; if (drivers_[i] != nullptr) { - DRV_DESTROY(drivers_[i]); + drv_destroy(drivers_[i]); + drivers_[i] = nullptr; } struct driver *drv = drv_create(driver_fds[i], gpu_grp_type_); if (!drv) {