summaryrefslogtreecommitdiffstats
path: root/pcilib/pci.c
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2015-08-12 20:57:37 +0200
committerSuren A. Chilingaryan <csa@suren.me>2015-08-12 20:57:37 +0200
commit5001621745651443d3825a30a92897cac7f1ec53 (patch)
tree15522e3620947547a0c57a3b9a97c2729ac6fefb /pcilib/pci.c
parent55783eb24e983786056f4ba7925aa23fca13c79e (diff)
downloadpcitool-5001621745651443d3825a30a92897cac7f1ec53.tar.gz
pcitool-5001621745651443d3825a30a92897cac7f1ec53.tar.bz2
pcitool-5001621745651443d3825a30a92897cac7f1ec53.tar.xz
pcitool-5001621745651443d3825a30a92897cac7f1ec53.zip
Do not fail if PCI configuration is not fully available to unprivileged user
Diffstat (limited to 'pcilib/pci.c')
-rw-r--r--pcilib/pci.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/pcilib/pci.c b/pcilib/pci.c
index 4351c1e..62ac92d 100644
--- a/pcilib/pci.c
+++ b/pcilib/pci.c
@@ -425,11 +425,16 @@ static int pcilib_update_pci_configuration_space(pcilib_t *ctx) {
}
size = read(ctx->pci_cfg_space_fd, ctx->pci_cfg_space_cache, 256);
- if (size != 256) {
- pcilib_error("Failed to read PCI configuration from sysfs");
+ if (size < 64) {
+ if (size <= 0)
+ pcilib_error("Failed to read PCI configuration from sysfs, errno: %i", errno);
+ else
+ pcilib_error("Failed to read PCI configuration from sysfs, only %zu bytes read (expected at least 64)", size);
return PCILIB_ERROR_FAILED;
}
+ ctx->pci_cfg_space_size = size;
+
return 0;
}
@@ -452,7 +457,7 @@ static uint32_t *pcilib_get_pci_capabilities(pcilib_t *ctx, int cap_id) {
cap = ctx->pci_cfg_space_cache[(0x34>>2)];
cap_offset = cap&0xFC;
- while ((cap_offset)&&(cap_offset < 256)) {
+ while ((cap_offset)&&(cap_offset < ctx->pci_cfg_space_size)) {
cap = ctx->pci_cfg_space_cache[cap_offset>>2];
if ((cap&0xFF) == cap_id)
return &ctx->pci_cfg_space_cache[cap_offset>>2];