[PATCH edid-decode v2 1/2] Make do_checksum reusable for DisplayID checksums.
Mark Ferry
mark at cognomen.co.uk
Mon Feb 6 13:51:44 UTC 2017
DisplayID, unlike EDID and CEA, is a variable length structure.
Allow for reuse of do_checksum by adding a length parameter.
Return a boolean to allow the caller to record failure.
---
edid-decode.c | 45 ++++++++++++++++++++++++++++-----------------
1 file changed, 28 insertions(+), 17 deletions(-)
diff --git a/edid-decode.c b/edid-decode.c
index c18697f..15660dc 100644
--- a/edid-decode.c
+++ b/edid-decode.c
@@ -34,6 +34,10 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
+enum {
+ EDID_PAGE_SIZE = 128u
+};
+
static int claims_one_point_oh = 0;
static int claims_one_point_two = 0;
static int claims_one_point_three = 0;
@@ -208,7 +212,7 @@ detailed_cvt_descriptor(unsigned char *x, int first)
static char *
extract_string(unsigned char *x, int *valid_termination, int len)
{
- static char ret[128];
+ static char ret[EDID_PAGE_SIZE];
int i, seen_newline = 0;
memset(ret, 0, sizeof(ret));
@@ -560,21 +564,25 @@ detailed_block(unsigned char *x, int in_extension)
return 1;
}
-static void
-do_checksum(unsigned char *x)
+static int
+do_checksum(unsigned char *x, size_t len)
{
- printf("Checksum: 0x%hx", x[0x7f]);
- {
- unsigned char sum = 0;
- int i;
- for (i = 0; i < 128; i++)
- sum += x[i];
- if (sum) {
- printf(" (should be 0x%hx)", (unsigned char)(x[0x7f] - sum));
- has_valid_checksum = 0;
- } else printf(" (valid)");
+ unsigned char check = x[len - 1];
+ unsigned char sum = 0;
+ int i;
+
+ printf("Checksum: 0x%hx", check);
+
+ for (i = 0; i < len-1; i++)
+ sum += x[i];
+
+ if ((unsigned char)(check + sum) != 0) {
+ printf(" (should be 0x%hx)\n", -sum & 0xff);
+ return 0;
}
- printf("\n");
+
+ printf(" (valid)\n");
+ return 1;
}
/* CEA extension */
@@ -1281,7 +1289,7 @@ parse_cea(unsigned char *x)
detailed_block(detailed, 1);
} while (0);
- do_checksum(x);
+ do_checksum(x, EDID_PAGE_SIZE);
return ret;
}
@@ -1371,6 +1379,9 @@ parse_displayid(unsigned char *x)
int ext_count = x[4];
int i;
printf("Length %d, version %d, extension count %d\n", length, version, ext_count);
+
+ do_checksum(x+1, length + 5);
+
int offset = 5;
while (length > 0) {
int tag = x[offset];
@@ -2037,11 +2048,11 @@ int main(int argc, char **argv)
has_valid_extension_count = 1;
}
- do_checksum(edid);
+ do_checksum(edid, EDID_PAGE_SIZE);
x = edid;
for (edid_lines /= 8; edid_lines > 1; edid_lines--) {
- x += 128;
+ x += EDID_PAGE_SIZE;
nonconformant_extension += parse_extension(x);
}
--
Cognomen Ltd
http://cognomen.co.uk
+44 7855 790184
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <https://lists.x.org/archives/xorg-devel/attachments/20170206/38c2c933/attachment.sig>
More information about the xorg-devel
mailing list