From: Jani Nikula <jani.nikula@linux.intel.com>
To: Ville Syrjala <ville.syrjala@linux.intel.com>,
intel-gfx@lists.freedesktop.org
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH 3/5] drm/i915/bios: Extract intel_spi_read16()
Date: Thu, 12 Sep 2024 15:02:03 +0300 [thread overview]
Message-ID: <871q1pgjwk.fsf@intel.com> (raw)
In-Reply-To: <20240910134219.28479-4-ville.syrjala@linux.intel.com>
On Tue, 10 Sep 2024, Ville Syrjala <ville.syrjala@linux.intel.com> wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> The SPI VBT codepath only knows how to read 4 bytes at a time.
> So to read the 2 byte vbt_size it masks out the unwanted msbs.
> Hide that little implementation detail inside a new intel_spi_read16()
> helper. Alse rename the existing intel_spi_read() to intel_spi_read32()
> to make it clear what it does.
>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
> drivers/gpu/drm/i915/display/intel_bios.c | 16 ++++++++++------
> 1 file changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_bios.c b/drivers/gpu/drm/i915/display/intel_bios.c
> index cc4a4cc2bf3e..cbbda94c3dab 100644
> --- a/drivers/gpu/drm/i915/display/intel_bios.c
> +++ b/drivers/gpu/drm/i915/display/intel_bios.c
> @@ -3053,13 +3053,18 @@ static struct vbt_header *firmware_get_vbt(struct intel_display *display,
> return vbt;
> }
>
> -static u32 intel_spi_read(struct intel_uncore *uncore, u32 offset)
> +static u32 intel_spi_read32(struct intel_uncore *uncore, u32 offset)
> {
> intel_uncore_write(uncore, PRIMARY_SPI_ADDRESS, offset);
>
> return intel_uncore_read(uncore, PRIMARY_SPI_TRIGGER);
> }
>
> +static u16 intel_spi_read16(struct intel_uncore *uncore, u32 offset)
> +{
> + return intel_spi_read32(uncore, offset) & 0xffff;
> +}
> +
> static struct vbt_header *spi_oprom_get_vbt(struct intel_display *display,
> size_t *size)
> {
> @@ -3078,7 +3083,7 @@ static struct vbt_header *spi_oprom_get_vbt(struct intel_display *display,
> oprom_offset &= OROM_OFFSET_MASK;
>
> for (count = 0; count < oprom_size; count += 4) {
> - data = intel_spi_read(&i915->uncore, oprom_offset + count);
> + data = intel_spi_read32(&i915->uncore, oprom_offset + count);
> if (data == *((const u32 *)"$VBT")) {
> found = oprom_offset + count;
> break;
> @@ -3094,9 +3099,8 @@ static struct vbt_header *spi_oprom_get_vbt(struct intel_display *display,
> }
>
> /* Get VBT size and allocate space for the VBT */
> - vbt_size = intel_spi_read(&i915->uncore,
> - found + offsetof(struct vbt_header, vbt_size));
> - vbt_size &= 0xffff;
> + vbt_size = intel_spi_read16(&i915->uncore,
> + found + offsetof(struct vbt_header, vbt_size));
Pedantically if vbt_size was the last member of struct vbt_header this
could read past the checked size, but it's not and meh. Also nothing to
do with this change, apart from this hiding the detail. Still meh.
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
>
> if (vbt_size > oprom_size - count) {
> drm_dbg(display->drm,
> @@ -3109,7 +3113,7 @@ static struct vbt_header *spi_oprom_get_vbt(struct intel_display *display,
> goto err_not_found;
>
> for (count = 0; count < vbt_size; count += 4)
> - *(vbt + store++) = intel_spi_read(&i915->uncore, found + count);
> + *(vbt + store++) = intel_spi_read32(&i915->uncore, found + count);
>
> if (!intel_bios_is_valid_vbt(display, vbt, vbt_size))
> goto err_free_vbt;
--
Jani Nikula, Intel
next prev parent reply other threads:[~2024-09-12 12:02 UTC|newest]
Thread overview: 31+ 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 [this message]
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ä
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 15:21 ` ✓ CI.Patch_applied: success for drm/i915/bios: Refactor ROM access Patchwork
2024-09-10 15:21 ` ✗ CI.checkpatch: warning " Patchwork
2024-09-10 15:22 ` ✓ CI.KUnit: success " Patchwork
2024-09-10 15:34 ` ✓ CI.Build: " Patchwork
2024-09-10 15:37 ` ✓ CI.Hooks: " Patchwork
2024-09-10 15:39 ` ✗ CI.checksparse: warning " Patchwork
2024-09-10 16:21 ` ✓ CI.BAT: success " Patchwork
2024-09-10 17:29 ` ✗ Fi.CI.CHECKPATCH: warning " Patchwork
2024-09-10 17:29 ` ✗ Fi.CI.SPARSE: " Patchwork
2024-09-10 17:46 ` ✓ Fi.CI.BAT: success " Patchwork
2024-09-10 18:20 ` ✗ CI.FULL: failure " Patchwork
2024-09-11 9:10 ` ✗ Fi.CI.IGT: " 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=871q1pgjwk.fsf@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=ville.syrjala@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.