From 00dad26ce2f84a6c688bccaa54328d9432f1a269 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 26 Jan 2021 13:46:25 +0100 Subject: [PATCH] gbm: fail early when modifier list only contains INVALID The current check only accomodates for a list with a single INVALID item. However the driver won't be able to pick any modifier if the list only contains INVALID. This includes the following cases: - The modifier list is empty (count == 0) - The modifier list contains more than a single item, but all items are INVALID In these cases, also fail early. Signed-off-by: Simon Ser References: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7601#note_778845 Reviewed-by: Daniel Stone Part-of: --- src/gbm/backends/dri/gbm_dri.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c index b5634741554..f381754aa40 100644 --- a/src/gbm/backends/dri/gbm_dri.c +++ b/src/gbm/backends/dri/gbm_dri.c @@ -1109,7 +1109,8 @@ gbm_dri_bo_create(struct gbm_device *gbm, struct gbm_dri_device *dri = gbm_dri_device(gbm); struct gbm_dri_bo *bo; int dri_format; - unsigned dri_use = 0; + unsigned dri_use = 0, i; + bool has_valid_modifier; /* Callers of this may specify a modifier, or a dri usage, but not both. The * newer modifier interface deprecates the older usage flags. @@ -1162,7 +1163,14 @@ gbm_dri_bo_create(struct gbm_device *gbm, * the check here is a convenient debug check likely pointing at whatever * interface the client is using to build its modifier list. */ - if (count == 1 && modifiers[0] == DRM_FORMAT_MOD_INVALID) { + has_valid_modifier = false; + for (i = 0; i < count; i++) { + if (modifiers[i] != DRM_FORMAT_MOD_INVALID) { + has_valid_modifier = true; + break; + } + } + if (!has_valid_modifier) { fprintf(stderr, "Only invalid modifier specified\n"); errno = EINVAL; goto failed;