[PATCH 4/5] drm/i915/bios: Extract vbt_signature[]
Jani Nikula
jani.nikula at linux.intel.com
Thu Sep 12 12:15:52 UTC 2024
On Tue, 10 Sep 2024, Ville Syrjala <ville.syrjala at linux.intel.com> wrote:
> From: Ville Syrjälä <ville.syrjala at linux.intel.com>
>
> Replace the three hand rolled "$VBT"s with a vbt_signature[]
> to avoid accidents.
>
> Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
> ---
> drivers/gpu/drm/i915/display/intel_bios.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_bios.c b/drivers/gpu/drm/i915/display/intel_bios.c
> index cbbda94c3dab..0b92b494117f 100644
> --- a/drivers/gpu/drm/i915/display/intel_bios.c
> +++ b/drivers/gpu/drm/i915/display/intel_bios.c
> @@ -2964,6 +2964,8 @@ static const struct bdb_header *get_bdb_header(const struct vbt_header *vbt)
> return _vbt + vbt->bdb_offset;
> }
>
> +static const char vbt_signature[4] = "$VBT";
Always a bit scary to add strings without termination, but I guess it's
justified here.
Reviewed-by: Jani Nikula <jani.nikula at intel.com>
> +
> /**
> * intel_bios_is_valid_vbt - does the given buffer contain a valid VBT
> * @display: display device
> @@ -2986,7 +2988,7 @@ bool intel_bios_is_valid_vbt(struct intel_display *display,
> return false;
> }
>
> - if (memcmp(vbt->signature, "$VBT", 4)) {
> + if (memcmp(vbt->signature, vbt_signature, sizeof(vbt_signature))) {
> drm_dbg_kms(display->drm, "VBT invalid signature\n");
> return false;
> }
> @@ -3082,9 +3084,11 @@ static struct vbt_header *spi_oprom_get_vbt(struct intel_display *display,
> oprom_offset = intel_uncore_read(&i915->uncore, OROM_OFFSET);
> oprom_offset &= OROM_OFFSET_MASK;
>
> + BUILD_BUG_ON(sizeof(vbt_signature) != sizeof(u32));
> +
> for (count = 0; count < oprom_size; count += 4) {
> data = intel_spi_read32(&i915->uncore, oprom_offset + count);
> - if (data == *((const u32 *)"$VBT")) {
> + if (data == *((const u32 *)vbt_signature)) {
> found = oprom_offset + count;
> break;
> }
> @@ -3144,9 +3148,11 @@ static struct vbt_header *oprom_get_vbt(struct intel_display *display,
> if (!oprom)
> return NULL;
>
> + BUILD_BUG_ON(sizeof(vbt_signature) != sizeof(u32));
> +
> /* Scour memory looking for the VBT signature. */
> for (i = 0; i + 4 < size; i += 4) {
> - if (ioread32(oprom + i) != *((const u32 *)"$VBT"))
> + if (ioread32(oprom + i) != *((const u32 *)vbt_signature))
> continue;
>
> p = oprom + i;
--
Jani Nikula, Intel
More information about the Intel-gfx
mailing list