From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3097C43381 for ; Fri, 1 Mar 2019 16:16:36 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7202A2083D for ; Fri, 1 Mar 2019 16:16:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=yadro.com header.i=@yadro.com header.b="NN5Oip+j" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7202A2083D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=yadro.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 449vgQ21htzDqVM for ; Sat, 2 Mar 2019 03:16:34 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=yadro.com (client-ip=89.207.88.251; helo=mta-01.yadro.com; envelope-from=s.miroshnichenko@yadro.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=yadro.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=yadro.com header.i=@yadro.com header.b="NN5Oip+j"; dkim-atps=neutral Received: from mta-01.yadro.com (mta-01.yadro.com [89.207.88.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 449vQ30vlXzDqKW for ; Sat, 2 Mar 2019 03:04:59 +1100 (AEDT) Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 5085741987; Fri, 1 Mar 2019 16:04:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1551456290; x=1553270691; bh=EGFRNzILany3zm5GGSc2LUnOIDP3eTpA2Y6 Txtw04xI=; b=NN5Oip+j7/NmP2zW0bM2WjT0gk+zbXmT0p0wBSMB/uVDfuVNWrs e22lpJ5Bwpchogyd5HVubzffNPp5Vhq/26zV1PLYW5JbCBO6zNPZU5TrdCV94NCP sE55hcqUay08EJb4SiqBzKln7op7x+RewzdjGlUq/MkS7cFdLKvbDvpo= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LcPxSD7XSv2o; Fri, 1 Mar 2019 19:04:50 +0300 (MSK) Received: from T-EXCH-02.corp.yadro.com (t-exch-02.corp.yadro.com [172.17.10.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 728EB41997; Fri, 1 Mar 2019 19:04:48 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.60) by T-EXCH-02.corp.yadro.com (172.17.10.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 1 Mar 2019 19:04:48 +0300 From: Sergey Miroshnichenko To: Subject: [PATCH RFC v4 4/9] powerpc/pci: Reduce code duplication in pci_add_device_node_info Date: Fri, 1 Mar 2019 19:04:35 +0300 Message-ID: <20190301160440.26262-5-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190301160440.26262-1-s.miroshnichenko@yadro.com> References: <20190301160440.26262-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.17.15.60] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-02.corp.yadro.com (172.17.10.102) X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stewart Smith , Alexey Kardashevskiy , Sergey Miroshnichenko , linux@yadro.com, Oliver O'Halloran Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" It is possible now to allocate and fill a new pdn with add_one_dev_pci_data Signed-off-by: Sergey Miroshnichenko --- arch/powerpc/kernel/pci_dn.c | 38 +++++++++++++++--------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/arch/powerpc/kernel/pci_dn.c b/arch/powerpc/kernel/pci_dn.c index 67ccd7be8344..ed1aab424e91 100644 --- a/arch/powerpc/kernel/pci_dn.c +++ b/arch/powerpc/kernel/pci_dn.c @@ -159,15 +159,10 @@ static struct pci_dn *add_one_dev_pci_data(struct pci_dn *parent, { struct pci_dn *pdn; - /* Except PHB, we always have the parent */ - if (!parent) - return NULL; - pdn = kzalloc(sizeof(*pdn), GFP_KERNEL); if (!pdn) return NULL; - pdn->phb = parent->phb; pdn->parent = parent; pdn->busno = busno; pdn->devfn = devfn; @@ -177,7 +172,10 @@ static struct pci_dn *add_one_dev_pci_data(struct pci_dn *parent, pdn->pe_number = IODA_INVALID_PE; INIT_LIST_HEAD(&pdn->child_list); INIT_LIST_HEAD(&pdn->list); - list_add_tail(&pdn->list, &parent->child_list); + if (parent) { + pdn->phb = parent->phb; + list_add_tail(&pdn->list, &parent->child_list); + } return pdn; } @@ -346,25 +344,29 @@ struct pci_dn *pci_add_device_node_info(struct pci_controller *hose, const __be32 *regs; struct device_node *parent; struct pci_dn *pdn; + int busno = 0, devfn = 0; #ifdef CONFIG_EEH struct eeh_dev *edev; #endif - pdn = kzalloc(sizeof(*pdn), GFP_KERNEL); - if (pdn == NULL) - return NULL; - dn->data = pdn; - pdn->phb = hose; - pdn->pe_number = IODA_INVALID_PE; regs = of_get_property(dn, "reg", NULL); if (regs) { u32 addr = of_read_number(regs, 1); /* First register entry is addr (00BBSS00) */ - pdn->busno = (addr >> 16) & 0xff; - pdn->devfn = (addr >> 8) & 0xff; + busno = (addr >> 16) & 0xff; + devfn = (addr >> 8) & 0xff; } + parent = of_get_parent(dn); + pdn = add_one_dev_pci_data(parent ? PCI_DN(parent) : NULL, + 0, busno, devfn); + if (!pdn) + return NULL; + + dn->data = pdn; + pdn->phb = hose; + /* vendor/device IDs and class code */ regs = of_get_property(dn, "vendor-id", NULL); pdn->vendor_id = regs ? of_read_number(regs, 1) : 0; @@ -385,14 +387,6 @@ struct pci_dn *pci_add_device_node_info(struct pci_controller *hose, } #endif - /* Attach to parent node */ - INIT_LIST_HEAD(&pdn->child_list); - INIT_LIST_HEAD(&pdn->list); - parent = of_get_parent(dn); - pdn->parent = parent ? PCI_DN(parent) : NULL; - if (pdn->parent) - list_add_tail(&pdn->list, &pdn->parent->child_list); - return pdn; } EXPORT_SYMBOL_GPL(pci_add_device_node_info); -- 2.20.1