Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[xsrc/trunk]: xsrc/external/mit/libdrm/dist - don't return random values to t...



details:   https://anonhg.NetBSD.org/xsrc/rev/6581069865f1
branches:  trunk
changeset: 9990:6581069865f1
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Sep 21 18:33:08 2018 +0000

description:
- don't return random values to the caller
- don't leak fd's.

diffstat:

 external/mit/libdrm/dist/xf86drm.c |  15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diffs (37 lines):

diff -r 5fef0dd28dda -r 6581069865f1 external/mit/libdrm/dist/xf86drm.c
--- a/external/mit/libdrm/dist/xf86drm.c        Sun Sep 09 03:58:37 2018 +0000
+++ b/external/mit/libdrm/dist/xf86drm.c        Fri Sep 21 18:33:08 2018 +0000
@@ -3347,22 +3347,29 @@
     if ((pcifd = open(fname, O_RDONLY)) == -1)
        return -errno;
 
+    ret = -1;
     /* Read the id and class pci config registers.  */
     if (pcibus_conf_read(pcifd, businfo.bus, businfo.dev, businfo.func,
            PCI_ID_REG, &id) == -1)
-       return -errno;
+       goto out;
     if (pcibus_conf_read(pcifd, businfo.bus, businfo.dev, businfo.func,
            PCI_CLASS_REG, &class) == -1)
-       return -errno;
+       goto out;
     if (pcibus_conf_read(pcifd, businfo.bus, businfo.dev, businfo.func,
            PCI_SUBSYS_ID_REG, &subsys) == -1)
-       return -errno;
-
+       goto out;
+
+    ret = 0;
     device->vendor_id = PCI_VENDOR(id);
     device->device_id = PCI_PRODUCT(id);
     device->subvendor_id = PCI_SUBSYS_VENDOR(subsys);
     device->subdevice_id = PCI_SUBSYS_ID(subsys);
     device->revision_id = PCI_REVISION(class);
+out:
+    if (ret == -1)
+       ret = -errno;
+    close(pcifd);
+    return ret;
 #elif defined(__OpenBSD__)
     struct drm_pciinfo pinfo;
     int fd, type;



Home | Main Index | Thread Index | Old Index