21510615 Xorg should not hold pci nexus drivers open
authorhenryzh <henry.zhao@oracle.com>
Thu, 20 Aug 2015 14:41:17 -0700
changeset 1567 d638bfcf9ec2
parent 1566 2bd576843a62
child 1568 f85b5a8a5c43
21510615 Xorg should not hold pci nexus drivers open
open-src/lib/libpciaccess/21510615.patch
open-src/lib/libpciaccess/Makefile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libpciaccess/21510615.patch	Thu Aug 20 14:41:17 2015 -0700
@@ -0,0 +1,123 @@
+--- src/solx_devfs.c	Thu Aug 13 19:36:20 2015
++++ src/solx_devfs.c	Thu Aug 13 19:30:51 2015
+@@ -1,6 +1,6 @@
+ /*
+  * (C) Copyright IBM Corporation 2006
+- * Copyright (c) 2007, 2009, 2011, 2012, 2013 Oracle and/or its affiliates.
++ * Copyright (c) 2007, 2009, 2011, 2012, 2015 Oracle and/or its affiliates.
+  * All Rights Reserved.
+  *
+  * Permission is hereby granted, free of charge, to any person obtaining a
+@@ -59,7 +59,6 @@
+ } i_devnode_t;
+ 
+ typedef struct nexus {
+-    int fd;
+     int first_bus;
+     int last_bus;
+     int domain;
+@@ -143,7 +142,6 @@
+ 
+     for (nexus = nexus_list ; nexus != NULL ; nexus = next) {
+ 	next = nexus->next;
+-	close(nexus->fd);
+ 	free(nexus->path);
+ 	free(nexus->dev_path);
+ 	free(nexus);
+@@ -303,7 +301,6 @@
+     di_prom_prop_t prom_prop;
+ #endif
+ 
+-
+ #ifdef DEBUG
+     nexus_name = di_devfs_minor_path(minor);
+     fprintf(stderr, "-- device name: %s\n", nexus_name);
+@@ -418,7 +415,6 @@
+     if ((fd = open(nexus_path, O_RDWR | O_CLOEXEC)) >= 0) {
+ 	probe_args_t args;
+ 
+-	nexus->fd = fd;
+ 	nexus->path = strdup(nexus_path);
+ 	nexus_dev_path = di_devfs_path(di_node);
+ 	nexus->dev_path = strdup(nexus_dev_path);
+@@ -426,7 +422,7 @@
+ 
+ 	if ((rnode = di_init(nexus->dev_path, DINFOCPYALL)) == DI_NODE_NIL) {
+ 	    (void) fprintf(stderr, "di_init failed: %s\n", strerror(errno));
+-	    close(nexus->fd);
++	    close(fd);
+ 	    free(nexus->path);
+ 	    free(nexus->dev_path);
+ 	    free(nexus);
+@@ -439,8 +435,10 @@
+ 	args.ret = 0;
+ 
+ 	(void) di_walk_node(rnode, DI_WALK_CLDFIRST, (void *)&args, probe_device_node);
++
++	close(fd);
++
+ 	if (args.ret) {
+-	    close(nexus->fd);
+ 	    free(nexus->path);
+ 	    free(nexus->dev_path);
+ 	    free(nexus);
+@@ -787,6 +785,7 @@
+     int err = 0;
+     unsigned int i = 0;
+     nexus_t *nexus;
++    int fd;
+ 
+     nexus = find_nexus_for_bus(dev->domain, dev->bus);
+ 
+@@ -804,11 +803,14 @@
+     cfg_prg.barnum = 0;
+     cfg_prg.user_version = PCITOOL_USER_VERSION;
+ 
++    if ((fd = open(nexus->path, O_RDWR | O_CLOEXEC)) < 0)
++	return ENOENT;
++ 
+     for (i = 0; i < size; i += PCITOOL_ACC_ATTR_SIZE(PCITOOL_ACC_ATTR_SIZE_1))
+     {
+ 	cfg_prg.offset = offset + i;
+ 
+-	if ((err = ioctl(nexus->fd, PCITOOL_DEVICE_GET_REG, &cfg_prg)) != 0) {
++	if ((err = ioctl(fd, PCITOOL_DEVICE_GET_REG, &cfg_prg)) != 0) {
+ 	    fprintf(stderr, "read bdf<%s,%x,%x,%x,%llx> config space failure\n",
+ 		    nexus->path,
+ 		    cfg_prg.bus_no,
+@@ -826,6 +828,8 @@
+     }
+     *bytes_read = i;
+ 
++    close(fd);
++
+     return (err);
+ }
+ 
+@@ -841,6 +845,7 @@
+     int err = 0;
+     int cmd;
+     nexus_t *nexus;
++    int fd;
+ 
+     nexus = find_nexus_for_bus(dev->domain, dev->bus);
+ 
+@@ -888,11 +893,17 @@
+      */
+     cmd = PCITOOL_DEVICE_SET_REG;
+ 
+-    if ((err = ioctl(nexus->fd, cmd, &cfg_prg)) != 0) {
++    if ((fd = open(nexus->path, O_RDWR | O_CLOEXEC)) < 0)
++	return ENOENT;
++
++    if ((err = ioctl(fd, cmd, &cfg_prg)) != 0) {
++	close(fd);
+ 	return (err);
+     }
+     *bytes_written = size;
+ 
++    close(fd);
++
+     return (err);
+ }
+ 
--- a/open-src/lib/libpciaccess/Makefile	Wed Aug 12 13:24:11 2015 -0700
+++ b/open-src/lib/libpciaccess/Makefile	Thu Aug 20 14:41:17 2015 -0700
@@ -36,7 +36,8 @@
 TARBALL_SHA256= 6cd76ccae4e06eee47d3ead84a118740e9406e2a9b7adc9b08e92c69ce89c2e3
 
 # Patches to apply to source after unpacking, in order
-SOURCE_PATCHES = scanpci.man.patch 
+SOURCE_PATCHES = scanpci.man.patch \
+		21510615.patch
 
 # Library name
 LIBNAME=libpciaccess