[PATCH 1/3] xfree86: Add a xf86MonitorFindHDMIBlock()

Chris Wilson chris at chris-wilson.co.uk
Fri Aug 9 06:05:54 PDT 2013


On Wed, Aug 07, 2013 at 05:04:58PM +0100, Damien Lespiau wrote:
> The HDMI CEA vendor specific block has some interesting information,
> such as the maximum TMDS dot clock.
> 
> Signed-off-by: Damien Lespiau <damien.lespiau at intel.com>
> Tested-by: Cancan Feng <cancan.feng at intel.com>
> ---
>  hw/xfree86/ddc/interpret_edid.c | 88 +++++++++++++++++++++++++++++++++++++++++
>  hw/xfree86/ddc/xf86DDC.h        |  2 +
>  2 files changed, 90 insertions(+)
> 
> diff --git a/hw/xfree86/ddc/interpret_edid.c b/hw/xfree86/ddc/interpret_edid.c
> index e6b4d5b..10c1c3a 100644
> --- a/hw/xfree86/ddc/interpret_edid.c
> +++ b/hw/xfree86/ddc/interpret_edid.c
> @@ -332,6 +332,94 @@ xf86ForEachVideoBlock(xf86MonPtr mon, handle_video_fn fn, void *data)
>      }
>  }
>  
> +static void
> +cea_db_offsets(Uchar *cea, int *start, int *end)
> +{
> +    /* Data block offset in CEA extension block */
> +    *start = CEA_EXT_MIN_DATA_OFFSET;
> +    *end = cea[2];
> +    if (*end == 0 || *end > CEA_EXT_MAX_DATA_OFFSET)
> +        *end = CEA_EXT_MAX_DATA_OFFSET;
> +    if (*end < CEA_EXT_MIN_DATA_OFFSET)
> +        *end = CEA_EXT_MIN_DATA_OFFSET;
> +}
> +
> +static int
> +cea_db_len(Uchar *db)
> +{
> +    return db[0] & 0x1f;
> +}
> +
> +static int
> +cea_db_tag(Uchar *db)
> +{
> +    return db[0] >> 5;
> +}
> +
> +typedef void (*handle_cea_db_fn) (Uchar *, void *);
> +
> +static void
> +cea_for_each_db(xf86MonPtr mon, handle_cea_db_fn fn, void *data)
> +{
> +    int i;
> +
> +    if (!mon)
> +        return;
> +
> +    if (!(mon->flags & EDID_COMPLETE_RAWDATA))
> +        return;
> +
> +    if (!mon->no_sections)
> +        return;
> +
> +    if (!mon->rawData)
> +        return;
> +
> +    for (i = 0; i < mon->no_sections; i++) {
> +        int start, end, offset;
> +        Uchar *ext;
> +
> +        ext = mon->rawData + EDID1_LEN * (i + 1);
> +        if (ext[EXT_TAG] != CEA_EXT)
> +            continue;
> +
> +        cea_db_offsets(ext, &start, &end);

Since the iterator depends upon parsing inline metadata, is it wise to
read anything at all if cea_db_offset() detects garbage?

> +        for (offset = start;
> +             offset < end && offset + cea_db_len(&(ext)[(i)]) < end;

cea_db_len(&(ext)[(i)]) smells funny here

I presume the check is that the entirety of the db fits within the
memory block to avoid invalid access, so cea_db_len(&ext[offset]) would
look more natural.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the xorg-devel mailing list