From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LUnDp-0006Zc-3h for qemu-devel@nongnu.org; Wed, 04 Feb 2009 14:15:41 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LUnDn-0006ZQ-NX for qemu-devel@nongnu.org; Wed, 04 Feb 2009 14:15:39 -0500 Received: from [199.232.76.173] (port=51882 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LUnDn-0006ZN-Hm for qemu-devel@nongnu.org; Wed, 04 Feb 2009 14:15:39 -0500 Received: from mail-qy0-f20.google.com ([209.85.221.20]:39215) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LUnDn-0004PG-8c for qemu-devel@nongnu.org; Wed, 04 Feb 2009 14:15:39 -0500 Received: by qyk13 with SMTP id 13so5115131qyk.10 for ; Wed, 04 Feb 2009 11:15:38 -0800 (PST) Message-ID: <4989E947.9020201@codemonkey.ws> Date: Wed, 04 Feb 2009 13:15:19 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [patch 01/18] qemu: add pci helper functions References: <20090204133303.113145633@localhost.localdomain> <20090204133923.175155873@localhost.localdomain> <200902041456.20944.paul@codesourcery.com> In-Reply-To: <200902041456.20944.paul@codesourcery.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Marcelo Tosatti Paul Brook wrote: > On Wednesday 04 February 2009, Marcelo Tosatti wrote: > >> +PCIDevice *pci_find_device(int bus_num, int slot) >> +{ >> + int devfn; >> + PCIDevice *d; >> + PCIBus *bus = pci_find_bus(bus_num); >> + >> + if (!bus) >> + return NULL; >> + >> + for(devfn = 0; devfn < 256; devfn++) { >> + d = bus->devices[devfn]; >> + if (d && PCI_SLOT(devfn) == slot) >> + return d; >> + } >> + return NULL; >> +} >> > > This loop is bogus. You already know the devfn from the slot. > It's also completely busted if you have multifunction devices. > It should probably try a bit harder to handle the multifunction case. You know your device is bus->devices[slot * 8] but you should also check slot * 8 + 1..slot * 8 + 7 to see if there are any sub functions and return NULL or something. Regards, Anthony Liguori > Paul > > >