From patchwork Wed Sep 19 02:40:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yijing Wang X-Patchwork-Id: 1475711 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id CAE323FCFC for ; Wed, 19 Sep 2012 02:42:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755300Ab2ISCms (ORCPT ); Tue, 18 Sep 2012 22:42:48 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:53377 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755259Ab2ISCmr (ORCPT ); Tue, 18 Sep 2012 22:42:47 -0400 Received: from 172.24.2.119 (EHLO szxeml209-edg.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.4-GA FastPath queued) with ESMTP id APF89280; Wed, 19 Sep 2012 10:42:39 +0800 (CST) Received: from SZXEML421-HUB.china.huawei.com (10.82.67.160) by szxeml209-edg.china.huawei.com (172.24.2.184) with Microsoft SMTP Server (TLS) id 14.1.323.3; Wed, 19 Sep 2012 10:41:15 +0800 Received: from localhost (10.135.76.84) by szxeml421-hub.china.huawei.com (10.82.67.160) with Microsoft SMTP Server id 14.1.323.3; Wed, 19 Sep 2012 10:41:10 +0800 From: Yijing Wang To: Bjorn Helgaas , Huang Ying , Chen Gong CC: , Hanjun Guo , , Yijing Wang Subject: [PATCH 4/6] PCI/AER: clean pci_bus_ops when related pci bus was removed Date: Wed, 19 Sep 2012 10:40:40 +0800 Message-ID: <1348022442-7816-5-git-send-email-wangyijing@huawei.com> X-Mailer: git-send-email 1.7.11.msysgit.1 In-Reply-To: <1348022442-7816-1-git-send-email-wangyijing@huawei.com> References: <1348022442-7816-1-git-send-email-wangyijing@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.135.76.84] X-CFilter-Loop: Reflected Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org When Inject aer errors to the target pci device, a pci_bus_ops will be allocated for the pci device's pci bus.When the pci bus was removed, we should also release the pci_bus_ops. Signed-off-by: Yijing Wang Reviewed-by: Sven Dietrich --- drivers/pci/pcie/aer/aer_inject.c | 48 ++++++++++++++++++++++++++++++++++++- 1 files changed, 47 insertions(+), 1 deletions(-) diff --git a/drivers/pci/pcie/aer/aer_inject.c b/drivers/pci/pcie/aer/aer_inject.c index e2400b5..0a12ac7 100644 --- a/drivers/pci/pcie/aer/aer_inject.c +++ b/drivers/pci/pcie/aer/aer_inject.c @@ -570,10 +570,55 @@ static struct miscdevice aer_inject_device = { .fops = &aer_inject_fops, }; +static void aer_clean_pci_bus_ops(struct pci_dev *dev) +{ + unsigned long flags; + struct pci_bus_ops *bus_ops, *tmp_ops; + struct pci_bus *bus; + bus = dev->subordinate; + if (!bus) + return; + + spin_lock_irqsave(&inject_lock, flags); + list_for_each_entry_safe(bus_ops, tmp_ops, &pci_bus_ops_list, list) + if (bus_ops->bus == bus) { + list_del(&bus_ops->list); + kfree(bus_ops); + break; + } + spin_unlock_irqrestore(&inject_lock, flags); +} + +static int aer_hp_notify_fn(struct notifier_block *nb, + unsigned long event, void *data) +{ + switch (event) { + case BUS_NOTIFY_DEL_DEVICE: + aer_clean_pci_bus_ops(to_pci_dev(data)); + break; + default: + return NOTIFY_DONE; + } + + return NOTIFY_OK; +} + +static struct notifier_block aerinj_hp_notifier = { + .notifier_call = &aer_hp_notify_fn, +}; static int __init aer_inject_init(void) { - return misc_register(&aer_inject_device); + int ret; + ret = misc_register(&aer_inject_device); + if (ret) + goto out; + + ret = bus_register_notifier(&pci_bus_type, &aerinj_hp_notifier); + if (ret) + misc_deregister(&aer_inject_device); +out: + return ret; } static void __exit aer_inject_exit(void) @@ -582,6 +627,7 @@ static void __exit aer_inject_exit(void) unsigned long flags; struct pci_bus_ops *bus_ops = NULL; + bus_unregister_notifier(&pci_bus_type, &aerinj_hp_notifier); misc_deregister(&aer_inject_device); /* clean pci_bus_ops tracked in pci_bus_ops_list */