From e8d56ca415f6214681daa65c0da505cd2d0bdc75 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 28 Dec 2020 10:52:40 +0100 Subject: backend/session: allow wlr_session_find_gpus to return an error Sometimes wlr_session_find_gpus will encounter an error. This is different from finding zero GPUs. On error, wlr_session_find_gpus already returns -1. However, this is casted to size_t, so callers uncorrectly assume this is a success. Instead, make wlr_session_find_gpus return a ssize_t and allow callers to handle the error accordingly. --- backend/session/session.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'backend/session') diff --git a/backend/session/session.c b/backend/session/session.c index b58bd967..1c6321a5 100644 --- a/backend/session/session.c +++ b/backend/session/session.c @@ -278,12 +278,12 @@ out_dev: return NULL; } -static size_t explicit_find_gpus(struct wlr_session *session, +static ssize_t explicit_find_gpus(struct wlr_session *session, size_t ret_len, struct wlr_device *ret[static ret_len], const char *str) { char *gpus = strdup(str); if (!gpus) { wlr_log_errno(WLR_ERROR, "Allocation failed"); - return 0; + return -1; } size_t i = 0; @@ -345,7 +345,7 @@ static void find_gpus_handle_add(struct wl_listener *listener, void *data) { /* Tries to find the primary GPU by checking for the "boot_vga" attribute. * If it's not found, it returns the first valid GPU it finds. */ -size_t wlr_session_find_gpus(struct wlr_session *session, +ssize_t wlr_session_find_gpus(struct wlr_session *session, size_t ret_len, struct wlr_device **ret) { const char *explicit = getenv("WLR_DRM_DEVICES"); if (explicit) { -- cgit v1.2.3