From patchwork Fri Jan 9 09:26:56 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Len Brown X-Patchwork-Id: 1500 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 n099NxO1003124 for ; Fri, 9 Jan 2009 01:25:03 -0800 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753688AbZAIJ2p (ORCPT ); Fri, 9 Jan 2009 04:28:45 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754112AbZAIJ2p (ORCPT ); Fri, 9 Jan 2009 04:28:45 -0500 Received: from vms173003pub.verizon.net ([206.46.173.3]:44602 "EHLO vms173003pub.verizon.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753688AbZAIJ2W (ORCPT ); Fri, 9 Jan 2009 04:28:22 -0500 Received: from localhost.localdomain ([96.237.168.40]) by vms173003.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0KD70042I6B339ID@vms173003.mailsrvcs.net> for linux-acpi@vger.kernel.org; Fri, 09 Jan 2009 03:28:17 -0600 (CST) Received: from localhost.localdomain (d975xbx2 [127.0.0.1]) by localhost.localdomain (8.14.2/8.14.2) with ESMTP id n099SFIa012015; Fri, 09 Jan 2009 04:28:15 -0500 Received: (from lenb@localhost) by localhost.localdomain (8.14.2/8.14.2/Submit) id n099SF27012014; Fri, 09 Jan 2009 04:28:15 -0500 Date: Fri, 09 Jan 2009 04:26:56 -0500 From: Len Brown Subject: [PATCH 54/94] ACPI: PCI: simplify list of _PRT entries In-reply-to: <1231493256-11678-1-git-send-email-lenb@kernel.org> In-reply-to: To: linux-acpi@vger.kernel.org Cc: Bjorn Helgaas , Len Brown Message-id: <3604a9f445afde2801b8c24b63dd289c33e290a6.1231492610.git.len.brown@intel.com> Organization: Intel Open Source Technology Center X-Mailer: git-send-email 1.6.1.76.gc123b References: <1231493256-11678-1-git-send-email-lenb@kernel.org> References: Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Bjorn Helgaas We don't need a struct containing a count and a list_head; a simple list_head is sufficient. The list iterators handle empty lists fine. Signed-off-by: Bjorn Helgaas Signed-off-by: Len Brown --- drivers/acpi/pci_irq.c | 60 +++++++++-------------------------------------- 1 files changed, 12 insertions(+), 48 deletions(-) diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c index b03bb84..42b195e 100644 --- a/drivers/acpi/pci_irq.c +++ b/drivers/acpi/pci_irq.c @@ -42,7 +42,7 @@ ACPI_MODULE_NAME("pci_irq"); struct acpi_prt_entry { - struct list_head node; + struct list_head list; struct acpi_pci_id id; u8 pin; struct { @@ -52,12 +52,7 @@ struct acpi_prt_entry { u32 irq; }; -struct acpi_prt_list { - int count; - struct list_head entries; -}; - -static struct acpi_prt_list acpi_prt; +static LIST_HEAD(acpi_prt_list); static DEFINE_SPINLOCK(acpi_prt_lock); static inline char pin_name(int pin) @@ -72,21 +67,13 @@ static inline char pin_name(int pin) static struct acpi_prt_entry *acpi_pci_irq_find_prt_entry(struct pci_dev *dev, int pin) { - struct acpi_prt_entry *entry = NULL; + struct acpi_prt_entry *entry; int segment = pci_domain_nr(dev->bus); int bus = dev->bus->number; int device = PCI_SLOT(dev->devfn); - if (!acpi_prt.count) - return NULL; - - /* - * Parse through all PRT entries looking for a match on the specified - * PCI device's segment, bus, device, and pin (don't care about func). - * - */ spin_lock(&acpi_prt_lock); - list_for_each_entry(entry, &acpi_prt.entries, node) { + list_for_each_entry(entry, &acpi_prt_list, list) { if ((segment == entry->id.segment) && (bus == entry->id.bus) && (device == entry->id.device) @@ -95,7 +82,6 @@ static struct acpi_prt_entry *acpi_pci_irq_find_prt_entry(struct pci_dev *dev, return entry; } } - spin_unlock(&acpi_prt_lock); return NULL; } @@ -201,7 +187,7 @@ static int acpi_pci_irq_add_entry(acpi_handle handle, int segment, int bus, struct acpi_pci_routing_table *prt) { - struct acpi_prt_entry *entry = NULL; + struct acpi_prt_entry *entry; entry = kzalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL); if (!entry) @@ -253,35 +239,17 @@ acpi_pci_irq_add_entry(acpi_handle handle, prt->source, entry->link.index)); spin_lock(&acpi_prt_lock); - list_add_tail(&entry->node, &acpi_prt.entries); - acpi_prt.count++; + list_add_tail(&entry->list, &acpi_prt_list); spin_unlock(&acpi_prt_lock); return 0; } -static void -acpi_pci_irq_del_entry(int segment, int bus, struct acpi_prt_entry *entry) -{ - if (segment == entry->id.segment && bus == entry->id.bus) { - acpi_prt.count--; - list_del(&entry->node); - kfree(entry); - } -} - int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus) { acpi_status status; struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; struct acpi_pci_routing_table *entry; - static int first_time = 1; - - if (first_time) { - acpi_prt.count = 0; - INIT_LIST_HEAD(&acpi_prt.entries); - first_time = 0; - } /* 'handle' is the _PRT's parent (root bridge or PCI-PCI bridge) */ status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); @@ -317,21 +285,17 @@ int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus) void acpi_pci_irq_del_prt(int segment, int bus) { - struct list_head *node = NULL, *n = NULL; - struct acpi_prt_entry *entry = NULL; - - if (!acpi_prt.count) { - return; - } + struct acpi_prt_entry *entry, *tmp; printk(KERN_DEBUG "ACPI: Delete PCI Interrupt Routing Table for %04x:%02x\n", segment, bus); spin_lock(&acpi_prt_lock); - list_for_each_safe(node, n, &acpi_prt.entries) { - entry = list_entry(node, struct acpi_prt_entry, node); - - acpi_pci_irq_del_entry(segment, bus, entry); + list_for_each_entry_safe(entry, tmp, &acpi_prt_list, list) { + if (segment == entry->id.segment && bus == entry->id.bus) { + list_del(&entry->list); + kfree(entry); + } } spin_unlock(&acpi_prt_lock); }