diff --git a/src/ratbagd-device.c b/src/ratbagd-device.c index 20865c8d..07685a61 100644 --- a/src/ratbagd-device.c +++ b/src/ratbagd-device.c @@ -366,32 +366,3 @@ struct ratbagd_device *ratbagd_device_next(struct ratbagd_device *device) node = rbnode_next(&device->node); return node ? ratbagd_device_from_node(node) : NULL; } - -int ratbagd_device_list(struct ratbagd *ctx, char ***paths) -{ - struct ratbagd_device *device; - char **devices, **pos; - - devices = calloc(ctx->n_devices + 1, sizeof(char *)); - if (!devices) - return -ENOMEM; - - pos = devices; - - RATBAGD_DEVICE_FOREACH(device, ctx) { - *pos = strdup(device->path); - if (!*pos) - goto error; - ++pos; - } - - *pos = NULL; - *paths = devices; - return 1; - -error: - for (pos = devices; *pos; ++pos) - free(*pos); - free(devices); - return -ENOMEM; -} diff --git a/src/ratbagd.c b/src/ratbagd.c index 960b926d..29ca73c3 100644 --- a/src/ratbagd.c +++ b/src/ratbagd.c @@ -67,10 +67,31 @@ static int ratbagd_list_devices(sd_bus *bus, sd_bus_error *error) { struct ratbagd *ctx = userdata; - int r; + struct ratbagd_device *device; + char **devices, **pos; - r = ratbagd_device_list(ctx, paths); - return r < 0 ? r : 1; + devices = calloc(ctx->n_devices + 1, sizeof(char *)); + if (!devices) + return -ENOMEM; + + pos = devices; + + RATBAGD_DEVICE_FOREACH(device, ctx) { + *pos = strdup(ratbagd_device_get_path(device)); + if (!*pos) + goto error; + ++pos; + } + + *pos = NULL; + *paths = devices; + return 1; + +error: + for (pos = devices; *pos; ++pos) + free(*pos); + free(devices); + return -ENOMEM; } static void ratbagd_process_device(struct ratbagd *ctx, diff --git a/src/ratbagd.h b/src/ratbagd.h index 43a7ac93..50e96d85 100644 --- a/src/ratbagd.h +++ b/src/ratbagd.h @@ -76,7 +76,6 @@ struct ratbagd_device *ratbagd_device_lookup(struct ratbagd *ctx, const char *name); struct ratbagd_device *ratbagd_device_first(struct ratbagd *ctx); struct ratbagd_device *ratbagd_device_next(struct ratbagd_device *device); -int ratbagd_device_list(struct ratbagd *ctx, char ***paths); #define RATBAGD_DEVICE_FOREACH(_device, _ctx) \ for ((_device) = ratbagd_device_first(_ctx); \