From: Lucas De Marchi <lucas.demarchi@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 4/4] lib/igt_kms: simplify pipe <-> name conversion
Date: Wed, 6 Jun 2018 15:27:41 -0700 [thread overview]
Message-ID: <20180606222741.24096-4-lucas.demarchi@intel.com> (raw)
In-Reply-To: <20180606222741.24096-1-lucas.demarchi@intel.com>
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>
---
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
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next prev parent reply other threads:[~2018-06-06 22:29 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-06 22:27 [igt-dev] [PATCH i-g-t 1/4] tests/sw_sync: fix pthread start_routine declaration Lucas De Marchi
2018-06-06 22:27 ` [igt-dev] [PATCH i-g-t 2/4] build: bump c std to gnu11 Lucas De Marchi
2018-06-06 22:27 ` [igt-dev] [PATCH i-g-t 3/4] lib/igt_core: fix check for running under gdb Lucas De Marchi
2018-07-11 21:25 ` [igt-dev] [PATCH i-g-t v2 " Lucas De Marchi
2018-06-06 22:27 ` Lucas De Marchi [this message]
2018-06-06 23:36 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/4] tests/sw_sync: fix pthread start_routine declaration Patchwork
2018-06-07 1:19 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2018-06-19 6:46 ` [igt-dev] [PATCH i-g-t 1/4] " Lucas De Marchi
2018-06-19 7:37 ` Petri Latvala
2018-06-19 20:30 ` Lucas De Marchi
2018-06-20 9:57 ` Petri Latvala
2018-07-05 20:15 ` Lucas De Marchi
2018-07-11 23:21 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/4] tests/sw_sync: fix pthread start_routine declaration (rev2) Patchwork
2018-07-12 0:14 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180606222741.24096-4-lucas.demarchi@intel.com \
--to=lucas.demarchi@intel.com \
--cc=igt-dev@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).