From patchwork Fri May 15 04:59:05 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hidetoshi Seto X-Patchwork-Id: 23967 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 n4F502PW004957 for ; Fri, 15 May 2009 05:00:02 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752006AbZEOFAA (ORCPT ); Fri, 15 May 2009 01:00:00 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752736AbZEOE77 (ORCPT ); Fri, 15 May 2009 00:59:59 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:41963 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752006AbZEOE77 (ORCPT ); Fri, 15 May 2009 00:59:59 -0400 Received: from mt1.gw.fujitsu.co.jp ([10.0.50.74]) by fgwmail6.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id n4F4xxaP013086 for (envelope-from seto.hidetoshi@jp.fujitsu.com); Fri, 15 May 2009 13:59:59 +0900 Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 275DF45DE54 for ; Fri, 15 May 2009 13:59:59 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.fujitsu.co.jp [10.0.50.94]) by m4.gw.fujitsu.co.jp (Postfix) with ESMTP id E696C45DE53 for ; Fri, 15 May 2009 13:59:58 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id B1C971DB8042 for ; Fri, 15 May 2009 13:59:58 +0900 (JST) Received: from m106.s.css.fujitsu.com (m106.s.css.fujitsu.com [10.249.87.106]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 6AFE91DB803B for ; Fri, 15 May 2009 13:59:58 +0900 (JST) Received: from m106.css.fujitsu.com (m106 [127.0.0.1]) by m106.s.css.fujitsu.com (Postfix) with ESMTP id 3D3AF5B8723; Fri, 15 May 2009 13:59:58 +0900 (JST) Received: from [127.0.0.1] (unknown [10.124.100.141]) by m106.s.css.fujitsu.com (Postfix) with ESMTP id BF49B5B8612; Fri, 15 May 2009 13:59:57 +0900 (JST) Message-ID: <4A0CF699.2060904@jp.fujitsu.com> Date: Fri, 15 May 2009 13:59:05 +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 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, instead of continuing the setup. It will let drivers to retry pci_enable_msix() with less number of entries. Signed-off-by: Hidetoshi Seto Acked-by: Michael Ellerman --- drivers/pci/msi.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c index 6f2e629..952432a 100644 --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c @@ -445,8 +445,10 @@ 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) { + msi_free_irqs(dev); + return i; + } j = entries[i].entry; entry->msi_attrib.is_msix = 1;