edid: switch to a statically allocated extension array

The spec defines an upper bound for the extension block count,
which means we don't need to dynamically allocate the array. This
simplifies our logic a bit by removing an allocation error codepath.

The array is NULL-terminated, so EDID_MAX_BLOCK_COUNT is suitable
since it's the max number of extension blocks including the base
block, and the array doesn't include the base block.

Signed-off-by: Simon Ser <contact@emersion.fr>
This commit is contained in:
Simon Ser 2022-05-25 18:47:02 +02:00
parent 6238439643
commit 6cbaf27c91
2 changed files with 7 additions and 13 deletions

12
edid.c
View file

@ -9,11 +9,6 @@
* The size of an EDID block, defined in section 2.2.
*/
#define EDID_BLOCK_SIZE 128
/**
* The maximum number of EDID blocks (including the base block), defined in
* section 2.2.1.
*/
#define EDID_MAX_BLOCK_COUNT 256
/**
* Fixed EDID header, defined in section 3.1.
@ -168,12 +163,6 @@ di_edid_parse(const void *data, size_t size)
parse_vendor_product(data, &edid->vendor_product);
edid->exts = calloc(exts_len + 1, sizeof(struct di_edid_ext *));
if (!edid->exts) {
di_edid_destroy(edid);
return NULL;
}
for (i = 0; i < exts_len; i++) {
ext_data = (const uint8_t *) data + (i + 1) * EDID_BLOCK_SIZE;
if (!parse_ext(edid, ext_data) && errno != ENOTSUP) {
@ -194,7 +183,6 @@ di_edid_destroy(struct di_edid *edid)
free(edid->exts[i]);
}
free(edid->exts);
free(edid);
}

View file

@ -9,11 +9,17 @@
#include <libdisplay-info/edid.h>
/**
* The maximum number of EDID blocks (including the base block), defined in
* section 2.2.1.
*/
#define EDID_MAX_BLOCK_COUNT 256
struct di_edid {
struct di_edid_vendor_product vendor_product;
int version, revision;
/* NULL-terminated, doesn't include the base block */
struct di_edid_ext **exts;
struct di_edid_ext *exts[EDID_MAX_BLOCK_COUNT];
size_t exts_len;
};