From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Jani Nikula <jani.nikula@linux.intel.com>
Cc: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH 4/5] drm/i915/bios: Extract vbt_signature[]
Date: Mon, 23 Sep 2024 17:22:34 +0300 [thread overview]
Message-ID: <ZvF5qm-uT8yXt6p7@intel.com> (raw)
In-Reply-To: <87frpq7myg.fsf@intel.com>
On Mon, Sep 23, 2024 at 12:12:39PM +0300, Jani Nikula wrote:
> On Fri, 20 Sep 2024, Ville Syrjälä <ville.syrjala@linux.intel.com> wrote:
> > On Thu, Sep 12, 2024 at 03:15:52PM +0300, Jani Nikula wrote:
> >> On Tue, 10 Sep 2024, Ville Syrjala <ville.syrjala@linux.intel.com> wrote:
> >> > From: Ville Syrjälä <ville.syrjala@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@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.
> >
> > I guess we could make it look less like a string with eg.
> > static const u8 vbt_signature[] = { '$', 'V', 'B', 'T' };
> > ?
>
> Alternatively,
>
> static const char *vbt_signature = "$VBT";
Or could just be something like:
static const char vbt_signature[] = "$VBT";
static const int vbt_signature_len = 4;
BUILD_BUG_ON(vbt_signature_len != sizeof(vbt_signature) - 1);
BUILD_BUG_ON(vbt_signature_len != sizeof(u32));
and use vbt_signature_len instead sizeof(vbt_signature) everwhere.
>
> >
> >> Reviewed-by: Jani Nikula <jani.nikula@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))) {
>
> But then this would need strlen()
>
> >> > 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));
>
> And maybe this could be sizeof(vbt_signature) < sizeof(u32)
>
> All of the alternatives are a bit disappointing, so maybe let's just
> roll with the patch you already have here?
>
> BR,
> Jani.
>
> >> > +
> >> > 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
>
> --
> Jani Nikula, Intel
--
Ville Syrjälä
Intel
next prev parent reply other threads:[~2024-09-23 14:22 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-10 13:42 [PATCH 0/5] drm/i915/bios: Refactor ROM access Ville Syrjala
2024-09-10 13:42 ` [PATCH 1/5] drm/i915/bios: Add some size checks to SPI VBT read Ville Syrjala
2024-09-12 11:56 ` Jani Nikula
2024-09-10 13:42 ` [PATCH 2/5] drm/i915/bios: Round PCI ROM VBT allocation to multiple of 4 Ville Syrjala
2024-09-12 11:57 ` Jani Nikula
2024-09-10 13:42 ` [PATCH 3/5] drm/i915/bios: Extract intel_spi_read16() Ville Syrjala
2024-09-12 12:02 ` Jani Nikula
2024-09-20 17:00 ` Ville Syrjälä
2024-09-10 13:42 ` [PATCH 4/5] drm/i915/bios: Extract vbt_signature[] Ville Syrjala
2024-09-12 12:15 ` Jani Nikula
2024-09-20 16:59 ` Ville Syrjälä
2024-09-23 9:12 ` Jani Nikula
2024-09-23 14:22 ` Ville Syrjälä [this message]
2024-09-23 14:24 ` Jani Nikula
2024-09-23 14:29 ` Ville Syrjälä
2024-09-10 13:42 ` [PATCH 5/5] drm/i915/bios: Extract soc/intel_rom.c Ville Syrjala
2024-09-12 12:44 ` Jani Nikula
2024-09-20 17:02 ` Ville Syrjälä
2024-09-23 9:13 ` Jani Nikula
2024-09-10 17:29 ` ✗ Fi.CI.CHECKPATCH: warning for drm/i915/bios: Refactor ROM access Patchwork
2024-09-10 17:29 ` ✗ Fi.CI.SPARSE: " Patchwork
2024-09-10 17:46 ` ✓ Fi.CI.BAT: success " Patchwork
2024-09-11 9:10 ` ✗ Fi.CI.IGT: failure " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZvF5qm-uT8yXt6p7@intel.com \
--to=ville.syrjala@linux.intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox