Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 2/3] drm/i915/bios: fold pci rom map/unmap into copy function
Date: Fri, 22 Nov 2019 15:49:49 +0200	[thread overview]
Message-ID: <20191122134949.GK1208@intel.com> (raw)
In-Reply-To: <20191120234608.17775-2-lucas.demarchi@intel.com>

On Wed, Nov 20, 2019 at 03:46:07PM -0800, Lucas De Marchi wrote:
> We don't need to keep the pci rom mapped during the entire
> intel_bios_init() anymore. Move it to the previous copy_vbt() function
> and rename it to oprom_get_vbt() since now it's responsible to to all
> operations related to get the vbt from the oprom.
> 
> v2: fix double __iomem attribute detected by sparse
> 
> Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
> ---
>  drivers/gpu/drm/i915/display/intel_bios.c | 40 +++++++++++------------
>  1 file changed, 19 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/display/intel_bios.c b/drivers/gpu/drm/i915/display/intel_bios.c
> index 8bdfc1d55040..aa9b182efee5 100644
> --- a/drivers/gpu/drm/i915/display/intel_bios.c
> +++ b/drivers/gpu/drm/i915/display/intel_bios.c
> @@ -1896,12 +1896,17 @@ bool intel_bios_is_valid_vbt(const void *buf, size_t size)
>  	return vbt;
>  }
>  
> -static struct vbt_header *copy_vbt(void __iomem *oprom, size_t size)
> +static struct vbt_header *oprom_get_vbt(struct drm_i915_private *dev_priv)
>  {
> -	void __iomem *p = NULL;
> +	struct pci_dev *pdev = dev_priv->drm.pdev;
> +	void __iomem *p = NULL, *oprom;
>  	struct vbt_header *vbt;
>  	u16 vbt_size;
> -	size_t i;
> +	size_t i, 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++) {
> @@ -1914,23 +1919,23 @@ static struct vbt_header *copy_vbt(void __iomem *oprom, size_t size)
>  	}
>  
>  	if (!p)
> -		return NULL;
> +		goto err_unmap_oprom;
>  
>  	if (sizeof(struct vbt_header) > size) {
>  		DRM_DEBUG_DRIVER("VBT header incomplete\n");
> -		return NULL;
> +		goto err_unmap_oprom;
>  	}
>  
>  	vbt_size = ioread16(p + offsetof(struct vbt_header, vbt_size));
>  	if (vbt_size > size) {
>  		DRM_DEBUG_DRIVER("VBT incomplete (vbt_size overflows)\n");
> -		return NULL;
> +		goto err_unmap_oprom;
>  	}
>  
>  	/* The rest will be validated by intel_bios_is_valid_vbt() */
>  	vbt = kmalloc(vbt_size, GFP_KERNEL);
>  	if (!vbt)
> -		return NULL;
> +		goto err_unmap_oprom;
>  
>  	memcpy_fromio(vbt, p, vbt_size);
>  

Where is the unmap for the non-error path?

> @@ -1941,6 +1946,8 @@ static struct vbt_header *copy_vbt(void __iomem *oprom, size_t size)
>  
>  err_free_vbt:
>  	kfree(vbt);
> +err_unmap_oprom:
> +	pci_unmap_rom(pdev, oprom);
>  
>  	return NULL;
>  }
> @@ -1955,10 +1962,9 @@ static struct vbt_header *copy_vbt(void __iomem *oprom, size_t size)
>   */
>  void intel_bios_init(struct drm_i915_private *dev_priv)
>  {
> -	struct pci_dev *pdev = dev_priv->drm.pdev;
>  	const struct vbt_header *vbt = dev_priv->opregion.vbt;
> +	struct vbt_header *oprom_vbt = NULL;
>  	const struct bdb_header *bdb;
> -	u8 __iomem *oprom = NULL;
>  
>  	INIT_LIST_HEAD(&dev_priv->vbt.display_devices);
>  
> @@ -1971,15 +1977,11 @@ void intel_bios_init(struct drm_i915_private *dev_priv)
>  
>  	/* If the OpRegion does not have VBT, look in PCI ROM. */
>  	if (!vbt) {
> -		size_t size;
> -
> -		oprom = pci_map_rom(pdev, &size);
> -		if (!oprom)
> +		oprom_vbt = oprom_get_vbt(dev_priv);
> +		if (!oprom_vbt)
>  			goto out;
>  
> -		vbt = copy_vbt(oprom, size);
> -		if (!vbt)
> -			goto out;
> +		vbt = oprom_vbt;
>  
>  		DRM_DEBUG_KMS("Found valid VBT in PCI ROM\n");
>  	}
> @@ -2012,11 +2014,7 @@ void intel_bios_init(struct drm_i915_private *dev_priv)
>  		init_vbt_missing_defaults(dev_priv);
>  	}
>  
> -	if (oprom)
> -		pci_unmap_rom(pdev, oprom);
> -
> -	if (vbt != dev_priv->opregion.vbt)
> -		kfree(vbt);
> +	kfree(oprom_vbt);
>  }
>  
>  /**
> -- 
> 2.24.0

-- 
Ville Syrjälä
Intel
_______________________________________________
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: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [Intel-gfx] [PATCH 2/3] drm/i915/bios: fold pci rom map/unmap into copy function
Date: Fri, 22 Nov 2019 15:49:49 +0200	[thread overview]
Message-ID: <20191122134949.GK1208@intel.com> (raw)
Message-ID: <20191122134949.VFviYOHLbj8zeggf2ZCeMkpbdRNwGxAxcFYtlrTBrJ8@z> (raw)
In-Reply-To: <20191120234608.17775-2-lucas.demarchi@intel.com>

On Wed, Nov 20, 2019 at 03:46:07PM -0800, Lucas De Marchi wrote:
> We don't need to keep the pci rom mapped during the entire
> intel_bios_init() anymore. Move it to the previous copy_vbt() function
> and rename it to oprom_get_vbt() since now it's responsible to to all
> operations related to get the vbt from the oprom.
> 
> v2: fix double __iomem attribute detected by sparse
> 
> Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
> ---
>  drivers/gpu/drm/i915/display/intel_bios.c | 40 +++++++++++------------
>  1 file changed, 19 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/display/intel_bios.c b/drivers/gpu/drm/i915/display/intel_bios.c
> index 8bdfc1d55040..aa9b182efee5 100644
> --- a/drivers/gpu/drm/i915/display/intel_bios.c
> +++ b/drivers/gpu/drm/i915/display/intel_bios.c
> @@ -1896,12 +1896,17 @@ bool intel_bios_is_valid_vbt(const void *buf, size_t size)
>  	return vbt;
>  }
>  
> -static struct vbt_header *copy_vbt(void __iomem *oprom, size_t size)
> +static struct vbt_header *oprom_get_vbt(struct drm_i915_private *dev_priv)
>  {
> -	void __iomem *p = NULL;
> +	struct pci_dev *pdev = dev_priv->drm.pdev;
> +	void __iomem *p = NULL, *oprom;
>  	struct vbt_header *vbt;
>  	u16 vbt_size;
> -	size_t i;
> +	size_t i, 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++) {
> @@ -1914,23 +1919,23 @@ static struct vbt_header *copy_vbt(void __iomem *oprom, size_t size)
>  	}
>  
>  	if (!p)
> -		return NULL;
> +		goto err_unmap_oprom;
>  
>  	if (sizeof(struct vbt_header) > size) {
>  		DRM_DEBUG_DRIVER("VBT header incomplete\n");
> -		return NULL;
> +		goto err_unmap_oprom;
>  	}
>  
>  	vbt_size = ioread16(p + offsetof(struct vbt_header, vbt_size));
>  	if (vbt_size > size) {
>  		DRM_DEBUG_DRIVER("VBT incomplete (vbt_size overflows)\n");
> -		return NULL;
> +		goto err_unmap_oprom;
>  	}
>  
>  	/* The rest will be validated by intel_bios_is_valid_vbt() */
>  	vbt = kmalloc(vbt_size, GFP_KERNEL);
>  	if (!vbt)
> -		return NULL;
> +		goto err_unmap_oprom;
>  
>  	memcpy_fromio(vbt, p, vbt_size);
>  

Where is the unmap for the non-error path?

> @@ -1941,6 +1946,8 @@ static struct vbt_header *copy_vbt(void __iomem *oprom, size_t size)
>  
>  err_free_vbt:
>  	kfree(vbt);
> +err_unmap_oprom:
> +	pci_unmap_rom(pdev, oprom);
>  
>  	return NULL;
>  }
> @@ -1955,10 +1962,9 @@ static struct vbt_header *copy_vbt(void __iomem *oprom, size_t size)
>   */
>  void intel_bios_init(struct drm_i915_private *dev_priv)
>  {
> -	struct pci_dev *pdev = dev_priv->drm.pdev;
>  	const struct vbt_header *vbt = dev_priv->opregion.vbt;
> +	struct vbt_header *oprom_vbt = NULL;
>  	const struct bdb_header *bdb;
> -	u8 __iomem *oprom = NULL;
>  
>  	INIT_LIST_HEAD(&dev_priv->vbt.display_devices);
>  
> @@ -1971,15 +1977,11 @@ void intel_bios_init(struct drm_i915_private *dev_priv)
>  
>  	/* If the OpRegion does not have VBT, look in PCI ROM. */
>  	if (!vbt) {
> -		size_t size;
> -
> -		oprom = pci_map_rom(pdev, &size);
> -		if (!oprom)
> +		oprom_vbt = oprom_get_vbt(dev_priv);
> +		if (!oprom_vbt)
>  			goto out;
>  
> -		vbt = copy_vbt(oprom, size);
> -		if (!vbt)
> -			goto out;
> +		vbt = oprom_vbt;
>  
>  		DRM_DEBUG_KMS("Found valid VBT in PCI ROM\n");
>  	}
> @@ -2012,11 +2014,7 @@ void intel_bios_init(struct drm_i915_private *dev_priv)
>  		init_vbt_missing_defaults(dev_priv);
>  	}
>  
> -	if (oprom)
> -		pci_unmap_rom(pdev, oprom);
> -
> -	if (vbt != dev_priv->opregion.vbt)
> -		kfree(vbt);
> +	kfree(oprom_vbt);
>  }
>  
>  /**
> -- 
> 2.24.0

-- 
Ville Syrjälä
Intel
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2019-11-22 13:49 UTC|newest]

Thread overview: 24+ 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ä [this message]
2019-11-22 13:49     ` 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
2019-11-21 13:09     ` [Intel-gfx] " 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-26 22:51 [PATCH 0/3] bios: dot " Lucas De Marchi
2019-11-26 22:51 ` [PATCH 2/3] drm/i915/bios: fold pci rom map/unmap into copy function Lucas De Marchi
2019-11-15 23:35 [PATCH 1/3] drm/i915/bios: do not discard address space Lucas De Marchi
2019-11-15 23:35 ` [PATCH 2/3] drm/i915/bios: fold pci rom map/unmap into copy function 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=20191122134949.GK1208@intel.com \
    --to=ville.syrjala@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