modetest: add support for parsing big-endian formats

When specifying a frame buffer format like "RG16_BE" (big-endian RG16),
modetest still uses the little-endian variant, as the format string is
truncated to four characters.

Fix this by increasing the format string size to 8 bytes (7 characters +
NUL terminator).

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
v5:
  - Add Reviewed-by,

v4:
  - No changes,

v3:
  - Update for suffix change from "be" to "_BE", cfr. commit
    ffb9375a50 ("xf86drm: handle DRM_FORMAT_BIG_ENDIAN in
    drmGetFormatName()"),
  - Replace hardcoded numbers in code by sizeof(),

v2:
  - New.
main
Geert Uytterhoeven 2022-07-03 14:35:49 +02:00 committed by Dmitry Baryshkov
parent 9d7024218f
commit bc37db5c66
1 changed files with 9 additions and 6 deletions

View File

@ -817,7 +817,7 @@ struct pipe_arg {
unsigned int num_cons; unsigned int num_cons;
uint32_t crtc_id; uint32_t crtc_id;
char mode_str[64]; char mode_str[64];
char format_str[5]; char format_str[8]; /* need to leave room for "_BE" and terminating \0 */
float vrefresh; float vrefresh;
unsigned int fourcc; unsigned int fourcc;
drmModeModeInfo *mode; drmModeModeInfo *mode;
@ -841,7 +841,7 @@ struct plane_arg {
unsigned int old_fb_id; unsigned int old_fb_id;
struct bo *bo; struct bo *bo;
struct bo *old_bo; struct bo *old_bo;
char format_str[5]; /* need to leave room for terminating \0 */ char format_str[8]; /* need to leave room for "_BE" and terminating \0 */
unsigned int fourcc; unsigned int fourcc;
}; };
@ -2032,8 +2032,9 @@ static int parse_connector(struct pipe_arg *pipe, const char *arg)
} }
if (*p == '@') { if (*p == '@') {
strncpy(pipe->format_str, p + 1, 4); len = sizeof(pipe->format_str) - 1;
pipe->format_str[4] = '\0'; strncpy(pipe->format_str, p + 1, len);
pipe->format_str[len] = '\0';
} }
pipe->fourcc = util_format_fourcc(pipe->format_str); pipe->fourcc = util_format_fourcc(pipe->format_str);
@ -2047,6 +2048,7 @@ static int parse_connector(struct pipe_arg *pipe, const char *arg)
static int parse_plane(struct plane_arg *plane, const char *p) static int parse_plane(struct plane_arg *plane, const char *p)
{ {
unsigned int len;
char *end; char *end;
plane->plane_id = strtoul(p, &end, 10); plane->plane_id = strtoul(p, &end, 10);
@ -2085,8 +2087,9 @@ static int parse_plane(struct plane_arg *plane, const char *p)
} }
if (*end == '@') { if (*end == '@') {
strncpy(plane->format_str, end + 1, 4); len = sizeof(plane->format_str) - 1;
plane->format_str[4] = '\0'; strncpy(plane->format_str, end + 1, len);
plane->format_str[len] = '\0';
} else { } else {
strcpy(plane->format_str, "XR24"); strcpy(plane->format_str, "XR24");
} }