From mboxrd@z Thu Jan 1 00:00:00 1970 From: Simon Farnsworth Subject: [PATCH edid-decode] Read extension blocks in xrandr EDID property Date: Tue, 26 Nov 2013 11:25:49 +0000 Message-ID: <1385465149-4331-1-git-send-email-simon.farnsworth@onelan.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from claranet-outbound-smtp07.uk.clara.net (claranet-outbound-smtp07.uk.clara.net [195.8.89.40]) by gabe.freedesktop.org (Postfix) with ESMTP id BAEE3FA821 for ; Tue, 26 Nov 2013 04:12:53 -0800 (PST) List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org Errors-To: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org To: dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org Extend the parsing of the xrandr EDID property block to read extension blocks, not just the basic block. Signed-off-by: Simon Farnsworth --- edid-decode.c | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/edid-decode.c b/edid-decode.c index 4265843..e26ad3e 100644 --- a/edid-decode.c +++ b/edid-decode.c @@ -1126,38 +1126,56 @@ extract_edid(int fd) start = strstr(ret, "EDID_DATA:"); if (start == NULL) start = strstr(ret, "EDID:"); - /* Look for xrandr --verbose output (8 lines of 16 hex bytes) */ + /* Look for xrandr --verbose output (lines of 16 hex bytes) */ if (start != NULL) { const char indentation1[] = " "; const char indentation2[] = "\t\t"; + /* Used to detect that we've gone past the EDID property */ + const char half_indentation1[] = " "; + const char half_indentation2[] = "\t"; const char *indentation; char *s; - out = malloc(128); - if (out == NULL) { - free(ret); - return NULL; - } - - for (i = 0; i < 8; i++) { + lines = 0; + for (i = 0;; i++) { int j; - /* Get the next start of the line of EDID hex. */ + /* Get the next start of the line of EDID hex, assuming spaces for indentation */ s = strstr(start, indentation = indentation1); - if (!s) + /* Did we skip the start of another property? */ + if (s && s > strstr(start, half_indentation1)) + break; + + /* If we failed, retry assuming tabs for indentation */ + if (!s) { s = strstr(start, indentation = indentation2); - if (s == NULL) { + /* Did we skip the start of another property? */ + if (s && s > strstr(start, half_indentation2)) + break; + } + + if (!s) + break; + + lines++; + start = s + strlen(indentation); + + s = realloc(out, lines * 16); + if (!s) { free(ret); free(out); return NULL; } - start = s + strlen(indentation); - + out = (unsigned char *)s; c = start; for (j = 0; j < 16; j++) { char buf[3]; /* Read a %02x from the log */ if (!isxdigit(c[0]) || !isxdigit(c[1])) { + if (j != 0) { + lines--; + break; + } free(ret); free(out); return NULL; @@ -1171,6 +1189,7 @@ extract_edid(int fd) } free(ret); + edid_lines = lines; return out; } -- 1.8.3.1