From: Jani Nikula <jani.nikula@linux.intel.com>
To: Lucas De Marchi <lucas.demarchi@intel.com>,
intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 3/3] drm/i915/i915: assume vbt is 4-byte aligned into oprom
Date: Thu, 21 Nov 2019 15:09:03 +0200 [thread overview]
Message-ID: <878so9wf4g.fsf@intel.com> (raw)
In-Reply-To: <20191120234608.17775-3-lucas.demarchi@intel.com>
On Wed, 20 Nov 2019, Lucas De Marchi <lucas.demarchi@intel.com> wrote:
> The unaligned ioread32() will make us read byte by byte looking for the
> vbt. We could just as well have done a ioread8() + a shift and avoid the
> extra confusion on how we are looking for "$VBT".
>
> However when using ACPI it's guaranteed the VBT is 4-byte aligned
> per spec, so we can probably assume it here as well.
>
> Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
> ---
> drivers/gpu/drm/i915/display/intel_bios.c | 19 ++++++-------------
> 1 file changed, 6 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_bios.c b/drivers/gpu/drm/i915/display/intel_bios.c
> index aa9b182efee5..6bf57b1ad056 100644
> --- a/drivers/gpu/drm/i915/display/intel_bios.c
> +++ b/drivers/gpu/drm/i915/display/intel_bios.c
> @@ -1902,27 +1902,20 @@ static struct vbt_header *oprom_get_vbt(struct drm_i915_private *dev_priv)
> void __iomem *p = NULL, *oprom;
> struct vbt_header *vbt;
> u16 vbt_size;
> - size_t i, size;
> + size_t size;
>
> oprom = pci_map_rom(pdev, &size);
> if (!oprom)
> return NULL;
>
> /* Scour memory looking for the VBT signature. */
> - for (i = 0; i + 4 < size; i++) {
> - if (ioread32(oprom + i) != *((const u32 *)"$VBT"))
> - continue;
> -
> - p = oprom + i;
> - size -= i;
> - break;
> - }
> -
> - if (!p)
> - goto err_unmap_oprom;
> + for (p = oprom; size >= 4; p += 4, size -= 4)
> + if (ioread32(p) == *((const u32 *)"$VBT"))
> + break;
I think the original is easier to read. You only really need to change
"i++" to "i += 4" and be done with it.
BR,
Jani.
>
> if (sizeof(struct vbt_header) > size) {
> - DRM_DEBUG_DRIVER("VBT header incomplete\n");
> + if (size >= 4)
> + DRM_DEBUG_DRIVER("VBT header incomplete\n");
> goto err_unmap_oprom;
> }
--
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
WARNING: multiple messages have this Message-ID (diff)
From: Jani Nikula <jani.nikula@linux.intel.com>
To: Lucas De Marchi <lucas.demarchi@intel.com>,
intel-gfx@lists.freedesktop.org
Subject: Re: [Intel-gfx] [PATCH 3/3] drm/i915/i915: assume vbt is 4-byte aligned into oprom
Date: Thu, 21 Nov 2019 15:09:03 +0200 [thread overview]
Message-ID: <878so9wf4g.fsf@intel.com> (raw)
Message-ID: <20191121130903.CYS3j4GoG26sl4MVKqHju-SQSAP3oSRgKAqiff2vR2M@z> (raw)
In-Reply-To: <20191120234608.17775-3-lucas.demarchi@intel.com>
On Wed, 20 Nov 2019, Lucas De Marchi <lucas.demarchi@intel.com> wrote:
> The unaligned ioread32() will make us read byte by byte looking for the
> vbt. We could just as well have done a ioread8() + a shift and avoid the
> extra confusion on how we are looking for "$VBT".
>
> However when using ACPI it's guaranteed the VBT is 4-byte aligned
> per spec, so we can probably assume it here as well.
>
> Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
> ---
> drivers/gpu/drm/i915/display/intel_bios.c | 19 ++++++-------------
> 1 file changed, 6 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_bios.c b/drivers/gpu/drm/i915/display/intel_bios.c
> index aa9b182efee5..6bf57b1ad056 100644
> --- a/drivers/gpu/drm/i915/display/intel_bios.c
> +++ b/drivers/gpu/drm/i915/display/intel_bios.c
> @@ -1902,27 +1902,20 @@ static struct vbt_header *oprom_get_vbt(struct drm_i915_private *dev_priv)
> void __iomem *p = NULL, *oprom;
> struct vbt_header *vbt;
> u16 vbt_size;
> - size_t i, size;
> + size_t size;
>
> oprom = pci_map_rom(pdev, &size);
> if (!oprom)
> return NULL;
>
> /* Scour memory looking for the VBT signature. */
> - for (i = 0; i + 4 < size; i++) {
> - if (ioread32(oprom + i) != *((const u32 *)"$VBT"))
> - continue;
> -
> - p = oprom + i;
> - size -= i;
> - break;
> - }
> -
> - if (!p)
> - goto err_unmap_oprom;
> + for (p = oprom; size >= 4; p += 4, size -= 4)
> + if (ioread32(p) == *((const u32 *)"$VBT"))
> + break;
I think the original is easier to read. You only really need to change
"i++" to "i += 4" and be done with it.
BR,
Jani.
>
> if (sizeof(struct vbt_header) > size) {
> - DRM_DEBUG_DRIVER("VBT header incomplete\n");
> + if (size >= 4)
> + DRM_DEBUG_DRIVER("VBT header incomplete\n");
> goto err_unmap_oprom;
> }
--
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2019-11-21 13:09 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-20 23:46 [PATCH 1/3] drm/i915/bios: do not discard address space Lucas De Marchi
2019-11-20 23:46 ` [Intel-gfx] " Lucas De Marchi
2019-11-20 23:46 ` [PATCH 2/3] drm/i915/bios: fold pci rom map/unmap into copy function Lucas De Marchi
2019-11-20 23:46 ` [Intel-gfx] " Lucas De Marchi
2019-11-21 13:02 ` Jani Nikula
2019-11-21 13:02 ` [Intel-gfx] " Jani Nikula
2019-11-22 13:49 ` Ville Syrjälä
2019-11-22 13:49 ` [Intel-gfx] " Ville Syrjälä
2019-11-20 23:46 ` [PATCH 3/3] drm/i915/i915: assume vbt is 4-byte aligned into oprom Lucas De Marchi
2019-11-20 23:46 ` [Intel-gfx] " Lucas De Marchi
2019-11-21 13:09 ` Jani Nikula [this message]
2019-11-21 13:09 ` Jani Nikula
2019-11-21 18:54 ` Lucas De Marchi
2019-11-21 18:54 ` [Intel-gfx] " Lucas De Marchi
2019-11-22 13:55 ` Ville Syrjälä
2019-11-22 13:55 ` [Intel-gfx] " Ville Syrjälä
2019-11-25 17:43 ` Lucas De Marchi
2019-11-25 17:43 ` [Intel-gfx] " Lucas De Marchi
2019-11-21 3:44 ` ✓ Fi.CI.BAT: success for series starting with [1/3] drm/i915/bios: do not discard address space Patchwork
2019-11-21 3:44 ` [Intel-gfx] " Patchwork
2019-11-22 5:42 ` ✗ Fi.CI.IGT: failure " Patchwork
2019-11-22 5:42 ` [Intel-gfx] " Patchwork
-- strict thread matches above, loose matches on Subject: below --
2019-11-15 23:35 [PATCH 1/3] " Lucas De Marchi
2019-11-15 23:35 ` [PATCH 3/3] drm/i915/i915: assume vbt is 4-byte aligned into oprom Lucas De Marchi
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=878so9wf4g.fsf@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=lucas.demarchi@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