pci: remove unnecessary access() check
PATCH 1/1 pci: remove unnecessary access() check
Just open the sysfs file and handle failure, rather than using access(). This eliminates Coverity warnings about "time of check versus time of use"; although for this sysfs file that is not really an issue anyway.
Coverity ID: 347276
--- drivers/bus/pci/linux/pci.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/bus/pci/linux/pci.c +7 -6
@@ -512,18 +512,19 @@ pci_device_iommu_support_va(const struct rte_pci_device *dev)"%s/" PCI_PRI_FMT "/iommu/intel-iommu/cap" ,rte_pci_get_sysfs_path (), addr->domain, addr->bus, addr->devid, addr->function); -if (access (filename,F_OK ) ==-1 ) { -/* We don't have an Intel IOMMU, assume VA supported*/ -return true; - } -/* We have an intel IOMMU */ fp =fopen (filename,"r" );if (fp ==NULL ) { -RTE_LOG (ERR ,EAL ,"%s(): can't open %s\n" , __func__, filename); +/* We don't have an Intel IOMMU, assume VA supported*/ +if (errno ==ENOENT ) +return true; + +RTE_LOG (ERR ,EAL ,"%s(): can't open %s: %s\n" , + __func__, filename,strerror (errno));return false; } +/* We have an intel IOMMU */ if (fscanf (fp,"%" PRIx64, &vtd_cap_reg) !=1 ) {RTE_LOG (ERR ,EAL ,"%s(): can't read %s\n" , __func__, filename);fclose (fp);
Signature · 1 line
2.20.1
Quoted 8 lines · Stephen Hemminger
Just open the sysfs file and handle failure, rather than using
access(). This eliminates Coverity warnings about "time of check versus time of use"; although for this sysfs file that is not really an issue anyway.Coverity ID: 347276
Signed-off-by Stephen Hemminger <[email protected]>
Title prefix should be "bus/pci: " (check-git-log.sh).
Quoted 12 lines
--- drivers/bus/pci/linux/pci.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)drivers/bus/pci/linux/pci.c +0
-0@@ -512,18 +512,19 @@ pci_device_iommu_support_va(const struct rte_pci_device *dev)"%s/" PCI_PRI_FMT "/iommu/intel-iommu/cap" ,rte_pci_get_sysfs_path (), addr->domain, addr->bus, addr->devid, addr->function);
drivers/bus/pci/linux/pci.c pci_device_iommu_support_va(const struct rte_pci_device *dev) · line 518
Quoted 10 lines
drivers/bus/pci/linux/pci.c +1
-6-if (access (filename,F_OK ) ==-1 ) { -/* We don't have an Intel IOMMU, assume VA supported*/ -return true; - } -/* We have an intel IOMMU */ fp =fopen (filename,"r" );if (fp ==NULL ) { -RTE_LOG (ERR ,EAL ,"%s(): can't open %s\n" , __func__, filename); +/* We don't have an Intel IOMMU, assume VA supported*/
Nit: missing a space before closing the comment.
Quoted 13 lines
drivers/bus/pci/linux/pci.c +6
-1+if (errno ==ENOENT ) +return true; + +RTE_LOG (ERR ,EAL ,"%s(): can't open %s: %s\n" , + __func__, filename,strerror (errno));return false; } +/* We have an intel IOMMU */ if (fscanf (fp,"%" PRIx64, &vtd_cap_reg) !=1 ) {RTE_LOG (ERR ,EAL ,"%s(): can't read %s\n" , __func__, filename);fclose (fp); --
Quoted 2 lines
2.20.1
Signature · 1 line
David Marchand
David Marchand
AppliedQuoted 10 lines · David Marchand
Quoted 7 lines · Stephen Hemminger
Just open the sysfs file and handle failure, rather than using
access(). This eliminates Coverity warnings about "time of check versus time of use"; although for this sysfs file that is not really an issue anyway.Coverity ID: 347276
Fixed Coverity tag.
Added Fixes: + Cc: [email protected]
Quoted 3 lines
Quoted 1 line
Signed-off-by Stephen Hemminger <[email protected]>Title prefix should be "bus/pci: " (
check-git-log.sh).
Updated commit title.
Quoted 19 lines
Quoted 19 lines
--- drivers/bus/pci/linux/pci.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)drivers/bus/pci/linux/pci.c +0
-4@@ -512,18 +512,19 @@ pci_device_iommu_support_va(const struct rte_pci_device *dev)"%s/" PCI_PRI_FMT "/iommu/intel-iommu/cap" ,rte_pci_get_sysfs_path (), addr->domain, addr->bus, addr->devid, addr->function); -if (access (filename,F_OK ) ==-1 ) { -/* We don't have an Intel IOMMU, assume VA supported*/ -return true; - }
Quoted 17 lines
drivers/bus/pci/linux/pci.c pci_device_iommu_support_va(const struct rte_pci_device *dev) · line 518
Quoted 5 lines
drivers/bus/pci/linux/pci.c +1
-2-/* We have an intel IOMMU */ fp =fopen (filename,"r" );if (fp ==NULL ) { -RTE_LOG (ERR ,EAL ,"%s(): can't open %s\n" , __func__, filename); +/* We don't have an Intel IOMMU, assume VA supported*/ Nit: missing a space before closing the comment.
Quoted 9 lines
drivers/bus/pci/linux/pci.c +6
-0+if (errno ==ENOENT ) +return true; + +RTE_LOG (ERR ,EAL ,"%s(): can't open %s: %s\n" , + __func__, filename,strerror (errno));return false; } +/* We have an intel IOMMU */
s/intel/Intel/
Quoted 8 lines
Quoted 6 lines
drivers/bus/pci/linux/pci.c +0
-1if (fscanf (fp,"%" PRIx64, &vtd_cap_reg) !=1 ) {RTE_LOG (ERR ,EAL ,"%s(): can't read %s\n" , __func__, filename);fclose (fp); --2.20.1
Reviewed-by David Marchand <[email protected]>
Applied, thanks!
--
David Marchand