[PATCH 1/4] PCI/sysfs: Stop reporting _DSM failures as -EPERM

Krzysztof Wilczyński <[email protected]>
Newsgroups org.kernel.vger.linux-pci
Message-ID <[email protected]>
Currently, dsm_get_label() returns the literal -1 on every failure
path.  The sysfs read path passes that value to userspace as
-EPERM.  Reading the "label" or "acpi_index" attribute on a platform
where the Device Name _DSM returns a malformed result then fails
with:

  $ cat /sys/bus/pci/devices/0000:00:08.3/label
  cat: /sys/bus/pci/devices/0000:00:08.3/label: Operation not permitted

Nothing in that path performs a permission check, and the read
fails the same way for a privileged reader.  The error code points
at a cause that does not exist, and tools such as lspci report it
on every invocation.

Thus, return -ENODEV when the device has no ACPI companion, and
-EIO when the _DSM evaluation fails or returns an object that
cannot be parsed.  Other _DSM users in the tree report such
failures the same way.

The set of reads that succeed, and the bytes they return, stay
the same.  Only the error code of reads that already fail differs.

Link: https://github.com/pciutils/pciutils/issues/175
Fixes: 6058989bad05 ("PCI: Export ACPI _DSM provided firmware instance number and string name to sysfs")
Signed-off-by: Krzysztof Wilczyński <[email protected]>
---
 drivers/pci/pci-label.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/pci-label.c b/drivers/pci/pci-label.c
index 0c6446519640..255e0ecffb09 100644
--- a/drivers/pci/pci-label.c
+++ b/drivers/pci/pci-label.c
@@ -160,12 +160,12 @@ static int dsm_get_label(struct device *dev, char *buf,
 	int len = 0;
 
 	if (!handle)
-		return -1;
+		return -ENODEV;
 
 	obj = acpi_evaluate_dsm(handle, &pci_acpi_dsm_guid, 0x2,
 				DSM_PCI_DEVICE_NAME, NULL);
 	if (!obj)
-		return -1;
+		return -EIO;
 
 	tmp = obj->package.elements;
 	if (obj->type == ACPI_TYPE_PACKAGE && obj->package.count == 2 &&
@@ -190,7 +190,7 @@ static int dsm_get_label(struct device *dev, char *buf,
 
 	ACPI_FREE(obj);
 
-	return len > 0 ? len : -1;
+	return len > 0 ? len : -EIO;
 }
 
 static ssize_t label_show(struct device *dev, struct device_attribute *attr,
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.