rem: char leaf[256];
add: char buffer[sizeof(struct dirent) + SYS_MAX_NAME_LEN + 1]; struct dirent *dirent = (struct dirent *)buffer;
context: static int bus_find_device_recurse(int *n, char *base_path, int base_fd, id_list *vendor_ids, id_list *device_ids){	char leaf[256];	int base_path_len = strlen(base_path);	ssize_t len;	int fd;	int err;	struct stat stat;	while((len = sys_read(base_fd, &leaf, -1, sizeof(leaf))) > 0) {		// reset the base_path to the original string passed in		base_path[base_path_len] = 0;		strlcat(base_path, leaf, sizeof(leaf));		fd = sys_open(base_path, STREAM_TYPE_ANY, 0);		if(fd < 0)			continue;		err = sys_rstat(base_path, &stat);		if(err < 0) {			sys_close(fd);			continue;		}		if(S_ISDIR(stat.st_mode)) {			strcat(base_path, "/");	/* XXXfreston... this is unsafe!!!! */			err = bus_find_device_recurse(n, base_path, fd, vendor_ids, device_ids);			sys_close(fd);			if(err >= 0)				return err;			continue;		} else if(S_ISREG(stat.st_mode)) {			// we opened the device			// XXX assumes PCI			struct pci_cfg cfg;			uint32 i, j;			err = sys_ioctl(fd, PCI_GET_CFG, &cfg, sizeof(struct pci_cfg));			if(err >= 0) {				// see if the vendor & device id matches				for(i=0; i<vendor_ids->num_ids; i++) {					if(cfg.vendor_id == vendor_ids->id[i]) {						for(j=0; j<device_ids->num_ids; j++) {							if(cfg.device_id == device_ids->id[j]) {								// found it								(*n)--;								if(*n <= 0)									return fd;							}						}					}				}			}			sys_close(fd);		}	}	return ENODEV;}