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 <contact@emersion.fr>
References: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7601#note_778845
Reviewed-by: Daniel Stone <daniel@fooishbar.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8715>
This commit is contained in:
Simon Ser 2021-01-26 13:46:25 +01:00 committed by Marge Bot
parent d85d780202
commit 00dad26ce2

View file

@ -1109,7 +1109,8 @@ gbm_dri_bo_create(struct gbm_device *gbm,
struct gbm_dri_device *dri = gbm_dri_device(gbm); struct gbm_dri_device *dri = gbm_dri_device(gbm);
struct gbm_dri_bo *bo; struct gbm_dri_bo *bo;
int dri_format; 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 /* Callers of this may specify a modifier, or a dri usage, but not both. The
* newer modifier interface deprecates the older usage flags. * 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 * the check here is a convenient debug check likely pointing at whatever
* interface the client is using to build its modifier list. * 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"); fprintf(stderr, "Only invalid modifier specified\n");
errno = EINVAL; errno = EINVAL;
goto failed; goto failed;