+static void destroy_default_lease_configs(int num_configs,
+ struct lease_config *configs)
+{
+ for (int i = 0; i < num_configs; i++) {
+ free(configs[i].connector_ids);
+ free(configs[i].lease_name);
+ }
+
+ free(configs);
+}
+
+static int create_default_lease_configs(struct lm *lm,
+ struct lease_config **configs)
+{
+ struct lease_config *def_configs;
+ int num_configs = lm->drm_resource->count_connectors;
+
+ if (num_configs < 0)
+ return -1;
+
+ def_configs = calloc(num_configs, sizeof(*def_configs));
+ if (!def_configs) {
+ DEBUG_LOG("Memory allocation failed: %s\n", strerror(errno));
+ return -1;
+ }
+
+ for (int i = 0; i < num_configs; i++) {
+ uint32_t cid = lm->drm_resource->connectors[i];
+
+ def_configs[i].connector_ids = malloc(sizeof(uint32_t));
+ if (!def_configs[i].connector_ids) {
+ DEBUG_LOG("Memory allocation failed: %s\n",
+ strerror(errno));
+ goto err;
+ }
+
+ drmModeConnectorPtr connector;
+ connector = drmModeGetConnector(lm->drm_fd, cid);
+ def_configs[i].lease_name =
+ drm_create_default_lease_name(lm, connector);
+
+ if (!def_configs[i].lease_name) {
+ DEBUG_LOG(
+ "Can't create lease name for connector %d: %s\n",
+ cid, strerror(errno));
+ goto err;
+ }
+
+ drmModeFreeConnector(connector);
+
+ def_configs[i].connector_ids[0] = cid;
+ def_configs[i].ncids = 1;
+ }
+
+ *configs = def_configs;
+ return num_configs;
+
+err:
+ destroy_default_lease_configs(num_configs, def_configs);
+ return -1;
+}
+
+static struct lm *drm_device_get_resources(const char *device)