From owner-svn-src-stable@freebsd.org Fri Sep 30 01:13:58 2016 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C598EC0133B; Fri, 30 Sep 2016 01:13:58 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A10F917EA; Fri, 30 Sep 2016 01:13:58 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u8U1DvI8080301; Fri, 30 Sep 2016 01:13:57 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u8U1DvZ1080299; Fri, 30 Sep 2016 01:13:57 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201609300113.u8U1DvZ1080299@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Fri, 30 Sep 2016 01:13:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r306469 - in stable: 10/share/man/man4 10/sys/dev/pci 11/share/man/man4 11/sys/dev/pci X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Sep 2016 01:13:58 -0000 Author: jhb Date: Fri Sep 30 01:13:57 2016 New Revision: 306469 URL: https://svnweb.freebsd.org/changeset/base/306469 Log: MFC 303881: Reliably return PCI_GETCONF_LAST_DEVICE from PCIOCGETCONF. Previously the loop in PCIIOCGETCONF would terminate as soon as it found enough matches. Now it will continue iterating through the PCI device list and only terminate if it finds another matching device for which it has no room to store a conf structure. This means that PCI_GETCONF_LAST_DEVICE is reliably returned when the number of matching devices is equal to the number of slots in the matches buffer. For example, if a program requests the conf structure for a single PCI function with a specified domain/bus/slot/function it will now get PCI_GETCONF_LAST_DEVICE instead of PCI_GETCONF_MORE_DEVS. While here, simplify the loop conditional a bit more by explicitly breaking out of the loop if copyout() fails and removing a redundant i < pci_numdevs check. Sponsored by: Chelsio Communications Modified: stable/11/share/man/man4/pci.4 stable/11/sys/dev/pci/pci_user.c Directory Properties: stable/11/ (props changed) Changes in other areas also in this revision: Modified: stable/10/share/man/man4/pci.4 stable/10/sys/dev/pci/pci_user.c Directory Properties: stable/10/ (props changed) Modified: stable/11/share/man/man4/pci.4 ============================================================================== --- stable/11/share/man/man4/pci.4 Fri Sep 30 00:43:30 2016 (r306468) +++ stable/11/share/man/man4/pci.4 Fri Sep 30 01:13:57 2016 (r306469) @@ -254,7 +254,8 @@ The status tells the user the dispositio The possible status values are: .Bl -ohang .It PCI_GETCONF_LAST_DEVICE -This means that there are no more devices in the PCI device list after the +This means that there are no more devices in the PCI device list matching +the specified criteria after the ones returned in the .Va matches buffer. @@ -270,9 +271,7 @@ and to zero to start over at the beginning of the list. .It PCI_GETCONF_MORE_DEVS This tells the user that his buffer was not large enough to hold all of the -remaining devices in the device list that possibly match his criteria. -It is possible for this status to be returned, even when none of the remaining -devices in the list would match the user's criteria. +remaining devices in the device list that match his criteria. .It PCI_GETCONF_ERROR This indicates a general error while servicing the user's request. If the Modified: stable/11/sys/dev/pci/pci_user.c ============================================================================== --- stable/11/sys/dev/pci/pci_user.c Fri Sep 30 00:43:30 2016 (r306468) +++ stable/11/sys/dev/pci/pci_user.c Fri Sep 30 01:13:57 2016 (r306469) @@ -708,10 +708,9 @@ pci_ioctl(struct cdev *dev, u_long cmd, * Go through the list of devices and copy out the devices * that match the user's criteria. */ - for (cio->num_matches = 0, error = 0, i = 0, + for (cio->num_matches = 0, i = 0, dinfo = STAILQ_FIRST(devlist_head); - (dinfo != NULL) && (cio->num_matches < ionum) && - (error == 0) && (i < pci_numdevs); + dinfo != NULL; dinfo = STAILQ_NEXT(dinfo, pci_links), i++) { if (i < cio->offset) @@ -833,11 +832,12 @@ pci_ioctl(struct cdev *dev, u_long cmd, } else #endif /* PRE7_COMPAT */ confdata = &dinfo->conf; - /* Only if we can copy it out do we count it. */ - if (!(error = copyout(confdata, + error = copyout(confdata, (caddr_t)cio->matches + - confsz * cio->num_matches, confsz))) - cio->num_matches++; + confsz * cio->num_matches, confsz); + if (error) + break; + cio->num_matches++; } }