linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI: make pci_size() return real size
@ 2018-10-13  0:49 changbin.du
  2018-10-17 14:11 ` Du Changbin
  2019-01-30 16:53 ` Bjorn Helgaas
  0 siblings, 2 replies; 3+ messages in thread
From: changbin.du @ 2018-10-13  0:49 UTC (permalink / raw)
  To: bhelgaas; +Cc: linux-pci, linux-kernel, Du Changbin

From: Du Changbin <changbin.du@gmail.com>

Currently, the pci_size() function actually return 'size-1'.
Make it return real size to avoid confusing.

Signed-off-by: Du Changbin <changbin.du@gmail.com>
---
 drivers/pci/probe.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 201f9e5ff55c..8ff2b1413865 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -121,13 +121,13 @@ static u64 pci_size(u64 base, u64 maxbase, u64 mask)
 	 * Get the lowest of them to find the decode size, and from that
 	 * the extent.
 	 */
-	size = (size & ~(size-1)) - 1;
+	size = size & ~(size-1);
 
 	/*
 	 * base == maxbase can be valid only if the BAR has already been
 	 * programmed with all 1s.
 	 */
-	if (base == maxbase && ((base | size) & mask) != mask)
+	if (base == maxbase && ((base | (size - 1)) & mask) != mask)
 		return 0;
 
 	return size;
@@ -278,7 +278,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
 			/* Above 32-bit boundary; try to reallocate */
 			res->flags |= IORESOURCE_UNSET;
 			res->start = 0;
-			res->end = sz64;
+			res->end = sz64 - 1;
 			pci_info(dev, "reg 0x%x: can't handle BAR above 4GB (bus address %#010llx)\n",
 				 pos, (unsigned long long)l64);
 			goto out;
@@ -286,7 +286,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
 	}
 
 	region.start = l64;
-	region.end = l64 + sz64;
+	region.end = l64 + sz64 - 1;
 
 	pcibios_bus_to_resource(dev->bus, res, &region);
 	pcibios_resource_to_bus(dev->bus, &inverted_region, res);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] PCI: make pci_size() return real size
  2018-10-13  0:49 [PATCH] PCI: make pci_size() return real size changbin.du
@ 2018-10-17 14:11 ` Du Changbin
  2019-01-30 16:53 ` Bjorn Helgaas
  1 sibling, 0 replies; 3+ messages in thread
From: Du Changbin @ 2018-10-17 14:11 UTC (permalink / raw)
  To: bhelgaas, changbin.du; +Cc: linux-pci, linux-kernel

Hi Bjorn. Have you checked this little improvment? The idea here is that
this is not a hotspot, so readbility matters than trick. Thanks!

On Sat, Oct 13, 2018 at 08:49:19AM +0800, changbin.du@gmail.com wrote:
> From: Du Changbin <changbin.du@gmail.com>
> 
> Currently, the pci_size() function actually return 'size-1'.
> Make it return real size to avoid confusing.
> 
> Signed-off-by: Du Changbin <changbin.du@gmail.com>
> ---
>  drivers/pci/probe.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index 201f9e5ff55c..8ff2b1413865 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -121,13 +121,13 @@ static u64 pci_size(u64 base, u64 maxbase, u64 mask)
>  	 * Get the lowest of them to find the decode size, and from that
>  	 * the extent.
>  	 */
> -	size = (size & ~(size-1)) - 1;
> +	size = size & ~(size-1);
>  
>  	/*
>  	 * base == maxbase can be valid only if the BAR has already been
>  	 * programmed with all 1s.
>  	 */
> -	if (base == maxbase && ((base | size) & mask) != mask)
> +	if (base == maxbase && ((base | (size - 1)) & mask) != mask)
>  		return 0;
>  
>  	return size;
> @@ -278,7 +278,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
>  			/* Above 32-bit boundary; try to reallocate */
>  			res->flags |= IORESOURCE_UNSET;
>  			res->start = 0;
> -			res->end = sz64;
> +			res->end = sz64 - 1;
>  			pci_info(dev, "reg 0x%x: can't handle BAR above 4GB (bus address %#010llx)\n",
>  				 pos, (unsigned long long)l64);
>  			goto out;
> @@ -286,7 +286,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
>  	}
>  
>  	region.start = l64;
> -	region.end = l64 + sz64;
> +	region.end = l64 + sz64 - 1;
>  
>  	pcibios_bus_to_resource(dev->bus, res, &region);
>  	pcibios_resource_to_bus(dev->bus, &inverted_region, res);
> -- 
> 2.17.1
> 

-- 
Thanks,
Du Changbin

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PCI: make pci_size() return real size
  2018-10-13  0:49 [PATCH] PCI: make pci_size() return real size changbin.du
  2018-10-17 14:11 ` Du Changbin
@ 2019-01-30 16:53 ` Bjorn Helgaas
  1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2019-01-30 16:53 UTC (permalink / raw)
  To: changbin.du; +Cc: linux-pci, linux-kernel

On Sat, Oct 13, 2018 at 08:49:19AM +0800, changbin.du@gmail.com wrote:
> From: Du Changbin <changbin.du@gmail.com>
> 
> Currently, the pci_size() function actually return 'size-1'.
> Make it return real size to avoid confusing.
> 
> Signed-off-by: Du Changbin <changbin.du@gmail.com>

Applied to pci/enumeration for v5.1, thanks!

I think it's good to have the "end = start + size - 1" idiom made more
obvious to help avoid off-by-one errors.

> ---
>  drivers/pci/probe.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index 201f9e5ff55c..8ff2b1413865 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -121,13 +121,13 @@ static u64 pci_size(u64 base, u64 maxbase, u64 mask)
>  	 * Get the lowest of them to find the decode size, and from that
>  	 * the extent.
>  	 */
> -	size = (size & ~(size-1)) - 1;
> +	size = size & ~(size-1);
>  
>  	/*
>  	 * base == maxbase can be valid only if the BAR has already been
>  	 * programmed with all 1s.
>  	 */
> -	if (base == maxbase && ((base | size) & mask) != mask)
> +	if (base == maxbase && ((base | (size - 1)) & mask) != mask)
>  		return 0;
>  
>  	return size;
> @@ -278,7 +278,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
>  			/* Above 32-bit boundary; try to reallocate */
>  			res->flags |= IORESOURCE_UNSET;
>  			res->start = 0;
> -			res->end = sz64;
> +			res->end = sz64 - 1;
>  			pci_info(dev, "reg 0x%x: can't handle BAR above 4GB (bus address %#010llx)\n",
>  				 pos, (unsigned long long)l64);
>  			goto out;
> @@ -286,7 +286,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
>  	}
>  
>  	region.start = l64;
> -	region.end = l64 + sz64;
> +	region.end = l64 + sz64 - 1;
>  
>  	pcibios_bus_to_resource(dev->bus, res, &region);
>  	pcibios_resource_to_bus(dev->bus, &inverted_region, res);
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-01-30 16:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-13  0:49 [PATCH] PCI: make pci_size() return real size changbin.du
2018-10-17 14:11 ` Du Changbin
2019-01-30 16:53 ` Bjorn Helgaas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).