linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] PCI: Fix return value from pci_user_{read,write}_config_*()
@ 2014-05-21  5:23 Gavin Shan
  2014-05-21 16:00 ` Greg Thelen
  2014-05-27 23:16 ` Bjorn Helgaas
  0 siblings, 2 replies; 3+ messages in thread
From: Gavin Shan @ 2014-05-21  5:23 UTC (permalink / raw)
  To: linux-pci; +Cc: gthelen, bhelgaas, Gavin Shan

PCI accessors from user space pci_user_{read,write}_config_*()
return negative error number, which was introduced by commit
34e32072 ("PCI: handle positive error codes"). That patch coverts
all positive error numbers from platform specific PCI config
accessors to -EINVAL. The upper layer calling to those PCI config
accessors hardly know the specific cause from the return value
when hitting failures.

The patch fixes the issue by doing the conversion (from positive
to negative) using existing function pcibios_err_to_errno().

v2: pcibios_err_to_errno() translates unrecognized value to -ERANGE.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 drivers/pci/access.c | 12 ++++--------
 include/linux/pci.h  |  4 ++--
 2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/pci/access.c b/drivers/pci/access.c
index 7f8b78c..8c148f3 100644
--- a/drivers/pci/access.c
+++ b/drivers/pci/access.c
@@ -148,7 +148,7 @@ static noinline void pci_wait_cfg(struct pci_dev *dev)
 int pci_user_read_config_##size						\
 	(struct pci_dev *dev, int pos, type *val)			\
 {									\
-	int ret = 0;							\
+	int ret = PCIBIOS_SUCCESSFUL;					\
 	u32 data = -1;							\
 	if (PCI_##size##_BAD)						\
 		return -EINVAL;						\
@@ -159,9 +159,7 @@ int pci_user_read_config_##size						\
 					pos, sizeof(type), &data);	\
 	raw_spin_unlock_irq(&pci_lock);				\
 	*val = (type)data;						\
-	if (ret > 0)							\
-		ret = -EINVAL;						\
-	return ret;							\
+	return pcibios_err_to_errno(ret);				\
 }									\
 EXPORT_SYMBOL_GPL(pci_user_read_config_##size);
 
@@ -170,7 +168,7 @@ EXPORT_SYMBOL_GPL(pci_user_read_config_##size);
 int pci_user_write_config_##size					\
 	(struct pci_dev *dev, int pos, type val)			\
 {									\
-	int ret = -EIO;							\
+	int ret = PCIBIOS_SUCCESSFUL;					\
 	if (PCI_##size##_BAD)						\
 		return -EINVAL;						\
 	raw_spin_lock_irq(&pci_lock);				\
@@ -179,9 +177,7 @@ int pci_user_write_config_##size					\
 	ret = dev->bus->ops->write(dev->bus, dev->devfn,		\
 					pos, sizeof(type), val);	\
 	raw_spin_unlock_irq(&pci_lock);				\
-	if (ret > 0)							\
-		ret = -EINVAL;						\
-	return ret;							\
+	return pcibios_err_to_errno(ret);				\
 }									\
 EXPORT_SYMBOL_GPL(pci_user_write_config_##size);
 
diff --git a/include/linux/pci.h b/include/linux/pci.h
index aab57b4..ece7bef 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -518,7 +518,7 @@ static inline int pcibios_err_to_errno(int err)
 	case PCIBIOS_FUNC_NOT_SUPPORTED:
 		return -ENOENT;
 	case PCIBIOS_BAD_VENDOR_ID:
-		return -EINVAL;
+		return -ENOTTY;
 	case PCIBIOS_DEVICE_NOT_FOUND:
 		return -ENODEV;
 	case PCIBIOS_BAD_REGISTER_NUMBER:
@@ -529,7 +529,7 @@ static inline int pcibios_err_to_errno(int err)
 		return -ENOSPC;
 	}
 
-	return -ENOTTY;
+	return -ERANGE;
 }
 
 /* Low-level architecture-dependent routines */
-- 
1.8.3.2


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

* Re: [PATCH v2] PCI: Fix return value from pci_user_{read,write}_config_*()
  2014-05-21  5:23 [PATCH v2] PCI: Fix return value from pci_user_{read,write}_config_*() Gavin Shan
@ 2014-05-21 16:00 ` Greg Thelen
  2014-05-27 23:16 ` Bjorn Helgaas
  1 sibling, 0 replies; 3+ messages in thread
From: Greg Thelen @ 2014-05-21 16:00 UTC (permalink / raw)
  To: Gavin Shan; +Cc: linux-pci, bhelgaas


On Tue, May 20 2014, Gavin Shan <gwshan@linux.vnet.ibm.com> wrote:

> PCI accessors from user space pci_user_{read,write}_config_*()
> return negative error number, which was introduced by commit
> 34e32072 ("PCI: handle positive error codes"). That patch coverts
> all positive error numbers from platform specific PCI config
> accessors to -EINVAL. The upper layer calling to those PCI config
> accessors hardly know the specific cause from the return value
> when hitting failures.
>
> The patch fixes the issue by doing the conversion (from positive
> to negative) using existing function pcibios_err_to_errno().
>
> v2: pcibios_err_to_errno() translates unrecognized value to -ERANGE.
>
> Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>

Acked-by: Greg Thelen <gthelen@google.com>

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

* Re: [PATCH v2] PCI: Fix return value from pci_user_{read,write}_config_*()
  2014-05-21  5:23 [PATCH v2] PCI: Fix return value from pci_user_{read,write}_config_*() Gavin Shan
  2014-05-21 16:00 ` Greg Thelen
@ 2014-05-27 23:16 ` Bjorn Helgaas
  1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2014-05-27 23:16 UTC (permalink / raw)
  To: Gavin Shan; +Cc: linux-pci, gthelen

On Wed, May 21, 2014 at 03:23:30PM +1000, Gavin Shan wrote:
> PCI accessors from user space pci_user_{read,write}_config_*()
> return negative error number, which was introduced by commit
> 34e32072 ("PCI: handle positive error codes"). That patch coverts
> all positive error numbers from platform specific PCI config
> accessors to -EINVAL. The upper layer calling to those PCI config
> accessors hardly know the specific cause from the return value
> when hitting failures.
> 
> The patch fixes the issue by doing the conversion (from positive
> to negative) using existing function pcibios_err_to_errno().
> 
> v2: pcibios_err_to_errno() translates unrecognized value to -ERANGE.
> 
> Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>

Applied with Greg's ack to pci/misc for v3.16, thanks!

> ---
>  drivers/pci/access.c | 12 ++++--------
>  include/linux/pci.h  |  4 ++--
>  2 files changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/pci/access.c b/drivers/pci/access.c
> index 7f8b78c..8c148f3 100644
> --- a/drivers/pci/access.c
> +++ b/drivers/pci/access.c
> @@ -148,7 +148,7 @@ static noinline void pci_wait_cfg(struct pci_dev *dev)
>  int pci_user_read_config_##size						\
>  	(struct pci_dev *dev, int pos, type *val)			\
>  {									\
> -	int ret = 0;							\
> +	int ret = PCIBIOS_SUCCESSFUL;					\
>  	u32 data = -1;							\
>  	if (PCI_##size##_BAD)						\
>  		return -EINVAL;						\
> @@ -159,9 +159,7 @@ int pci_user_read_config_##size						\
>  					pos, sizeof(type), &data);	\
>  	raw_spin_unlock_irq(&pci_lock);				\
>  	*val = (type)data;						\
> -	if (ret > 0)							\
> -		ret = -EINVAL;						\
> -	return ret;							\
> +	return pcibios_err_to_errno(ret);				\
>  }									\
>  EXPORT_SYMBOL_GPL(pci_user_read_config_##size);
>  
> @@ -170,7 +168,7 @@ EXPORT_SYMBOL_GPL(pci_user_read_config_##size);
>  int pci_user_write_config_##size					\
>  	(struct pci_dev *dev, int pos, type val)			\
>  {									\
> -	int ret = -EIO;							\
> +	int ret = PCIBIOS_SUCCESSFUL;					\
>  	if (PCI_##size##_BAD)						\
>  		return -EINVAL;						\
>  	raw_spin_lock_irq(&pci_lock);				\
> @@ -179,9 +177,7 @@ int pci_user_write_config_##size					\
>  	ret = dev->bus->ops->write(dev->bus, dev->devfn,		\
>  					pos, sizeof(type), val);	\
>  	raw_spin_unlock_irq(&pci_lock);				\
> -	if (ret > 0)							\
> -		ret = -EINVAL;						\
> -	return ret;							\
> +	return pcibios_err_to_errno(ret);				\
>  }									\
>  EXPORT_SYMBOL_GPL(pci_user_write_config_##size);
>  
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index aab57b4..ece7bef 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -518,7 +518,7 @@ static inline int pcibios_err_to_errno(int err)
>  	case PCIBIOS_FUNC_NOT_SUPPORTED:
>  		return -ENOENT;
>  	case PCIBIOS_BAD_VENDOR_ID:
> -		return -EINVAL;
> +		return -ENOTTY;
>  	case PCIBIOS_DEVICE_NOT_FOUND:
>  		return -ENODEV;
>  	case PCIBIOS_BAD_REGISTER_NUMBER:
> @@ -529,7 +529,7 @@ static inline int pcibios_err_to_errno(int err)
>  		return -ENOSPC;
>  	}
>  
> -	return -ENOTTY;
> +	return -ERANGE;
>  }
>  
>  /* Low-level architecture-dependent routines */
> -- 
> 1.8.3.2
> 

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

end of thread, other threads:[~2014-05-27 23:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-21  5:23 [PATCH v2] PCI: Fix return value from pci_user_{read,write}_config_*() Gavin Shan
2014-05-21 16:00 ` Greg Thelen
2014-05-27 23:16 ` 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).