diff options
author | Lucas De Marchi <lucas.demarchi@intel.com> | 2018-06-06 15:27:41 -0700 |
---|---|---|
committer | Arkadiusz Hiler <arkadiusz.hiler@intel.com> | 2018-07-12 11:08:30 +0300 |
commit | 25362a3b601f6f59e9a364b11213ddaa29f92b42 (patch) | |
tree | 8e4582204737cd1f75a01510fbcc2cba3dcc2ebf /lib/igt_kms.c | |
parent | c963fb78ba77273fbd7d351d11a045487135c561 (diff) |
lib/igt_kms: simplify pipe <-> name conversion
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@intel.com>
Reviewed-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
Diffstat (limited to 'lib/igt_kms.c')
-rw-r--r-- | lib/igt_kms.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/lib/igt_kms.c b/lib/igt_kms.c index 2318658e..476a7862 100644 --- a/lib/igt_kms.c +++ b/lib/igt_kms.c @@ -384,9 +384,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"; @@ -394,7 +395,7 @@ const char *kmstest_pipe_name(enum pipe pipe) if (pipe >= IGT_MAX_PIPES) return "invalid"; - return str[pipe]; + return str + (pipe * 2); } /** @@ -405,20 +406,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; } /** |