[igt-dev] [PATCH i-g-t 4/4] lib/igt_kms: simplify pipe <-> name conversion
Lucas De Marchi
lucas.demarchi at intel.com
Wed Jun 6 22:27:41 UTC 2018
Now that we can use _Static_assert() due to C11, make it future proof so
we remember to update this if IGT_MAX_PIPES changes. Also reduce
verbosity a little bit by calculating indexes instead of if/else chain.
Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
---
lib/igt_kms.c | 27 ++++++++++-----------------
1 file changed, 10 insertions(+), 17 deletions(-)
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 0438f641..40146867 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -324,9 +324,10 @@ const unsigned char* igt_kms_get_alt_edid(void)
*/
const char *kmstest_pipe_name(enum pipe pipe)
{
- static const char * const str[] = {
- "A", "B", "C", "D", "E", "F",
- };
+ static const char str[] = "A\0B\0C\0D\0E\0F";
+
+ _Static_assert(sizeof(str) == IGT_MAX_PIPES * 2,
+ "Missing pipe name");
if (pipe == PIPE_NONE)
return "None";
@@ -334,7 +335,7 @@ const char *kmstest_pipe_name(enum pipe pipe)
if (pipe >= IGT_MAX_PIPES)
return "invalid";
- return str[pipe];
+ return str + (pipe * 2);
}
/**
@@ -345,20 +346,12 @@ const char *kmstest_pipe_name(enum pipe pipe)
*/
int kmstest_pipe_to_index(char pipe)
{
- if (pipe == 'A')
- return 0;
- else if (pipe == 'B')
- return 1;
- else if (pipe == 'C')
- return 2;
- else if (pipe == 'D')
- return 3;
- else if (pipe == 'E')
- return 4;
- else if (pipe == 'F')
- return 5;
- else
+ int r = pipe - 'A';
+
+ if (r < 0 || r >= IGT_MAX_PIPES)
return -EINVAL;
+
+ return r;
}
/**
--
2.17.1
More information about the igt-dev
mailing list