From patchwork Fri May 15 07:48:10 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hidetoshi Seto X-Patchwork-Id: 23996 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n4F7nRDa017447 for ; Fri, 15 May 2009 07:49:27 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753295AbZEOHtJ (ORCPT ); Fri, 15 May 2009 03:49:09 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756549AbZEOHtI (ORCPT ); Fri, 15 May 2009 03:49:08 -0400 Received: from fgwmail7.fujitsu.co.jp ([192.51.44.37]:52171 "EHLO fgwmail7.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753295AbZEOHtH (ORCPT ); Fri, 15 May 2009 03:49:07 -0400 Received: from m1.gw.fujitsu.co.jp ([10.0.50.71]) by fgwmail7.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id n4F7n7Ca016704 for (envelope-from seto.hidetoshi@jp.fujitsu.com); Fri, 15 May 2009 16:49:08 +0900 Received: from smail (m1 [127.0.0.1]) by outgoing.m1.gw.fujitsu.co.jp (Postfix) with ESMTP id 6D61045DD74 for ; Fri, 15 May 2009 16:49:07 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (s1.gw.fujitsu.co.jp [10.0.50.91]) by m1.gw.fujitsu.co.jp (Postfix) with ESMTP id 3263D45DD72 for ; Fri, 15 May 2009 16:49:07 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id 1E84C1DB8016 for ; Fri, 15 May 2009 16:49:07 +0900 (JST) Received: from m105.s.css.fujitsu.com (m105.s.css.fujitsu.com [10.249.87.105]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id A0895E08002 for ; Fri, 15 May 2009 16:49:06 +0900 (JST) Received: from m105.css.fujitsu.com (m105 [127.0.0.1]) by m105.s.css.fujitsu.com (Postfix) with ESMTP id 6B7F55D8011; Fri, 15 May 2009 16:49:06 +0900 (JST) Received: from [127.0.0.1] (unknown [10.124.100.141]) by m105.s.css.fujitsu.com (Postfix) with ESMTP id 04F325D800E; Fri, 15 May 2009 16:49:05 +0900 (JST) Message-ID: <4A0D1E3A.9040305@jp.fujitsu.com> Date: Fri, 15 May 2009 16:48:10 +0900 From: Hidetoshi Seto User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 To: linux-pci@vger.kernel.org CC: Michael Ellerman , Matthew Wilcox Subject: [PATCH] pci, msi: return if alloc_msi_entry for MSI-X failed v2 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org In current code it continues setup even if alloc_msi_entry for MSI-X is failed due to lack of memory. It means arch_setup_msi_irqs() might be called with msi_desc entries less than its argument nvec. At least x86's arch_setup_msi_irqs() uses list_for_each_entry() for dev->msi_list that suspected to have entries same numbers as nvec, and it doesn't check the number of allocated vectors and passed arg nvec. Therefore it will result in success of pci_enable_msix(), with less vectors allocated than requested. This patch fixes the error route to return the number of entries can be allocated (or -ENOMEM), instead of continuing the setup. It will let drivers to retry pci_enable_msix() with less number of entries. v2: we should return -ENOMEM if it fails with i==0. Signed-off-by: Hidetoshi Seto Tested-by: Hidetoshi Seto --- drivers/pci/msi.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c index 6f2e629..247464d 100644 --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c @@ -445,8 +445,12 @@ static int msix_capability_init(struct pci_dev *dev, /* MSI-X Table Initialization */ for (i = 0; i < nvec; i++) { entry = alloc_msi_entry(dev); - if (!entry) - break; + if (!entry) { + if (!i) + return -ENOMEM; + msi_free_irqs(dev); + return i; + } j = entries[i].entry; entry->msi_attrib.is_msix = 1;