From patchwork Tue Nov 26 11:25:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Farnsworth X-Patchwork-Id: 3238921 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5E0CAC045B for ; Tue, 26 Nov 2013 12:13:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BB5D9203B5 for ; Tue, 26 Nov 2013 12:13:08 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 5CC902039C for ; Tue, 26 Nov 2013 12:13:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 56320FB7A4 for ; Tue, 26 Nov 2013 04:13:06 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org X-Greylist: delayed 2819 seconds by postgrey-1.32 at gabe; Tue, 26 Nov 2013 04:12:53 PST 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) Received: from 110.100.155.90.in-addr.arpa ([90.155.100.110]:59428 helo=f19simon.office.onelan.co.uk) by relay17.mail.eu.clara.net (relay.clara.net [81.171.239.37]:1025) with esmtpa (authdaemon_plain:simon.farnsworth@onelan.co.uk) id 1VlGm8-0005f6-O0 (return-path ); Tue, 26 Nov 2013 11:25:52 +0000 From: Simon Farnsworth To: dri-devel@lists.freedesktop.org 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> X-Mailer: git-send-email 1.8.3.1 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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; }