From patchwork Tue May 23 09:32:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 97938 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2011793vqo; Tue, 23 May 2023 02:42:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6V1hUo+ObDk5HLr18+3ibFH16gmtPZlkVA57B2EkPtfXEVQlYKzobAfBnqkvrgTLIpxtei X-Received: by 2002:a17:902:e848:b0:1ab:275:5abf with SMTP id t8-20020a170902e84800b001ab02755abfmr17608255plg.55.1684834969344; Tue, 23 May 2023 02:42:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684834969; cv=none; d=google.com; s=arc-20160816; b=bI0mwk1RwOkKbWXaWcpz4+2jVL5rs6/8SMPuwBd9Jed2CCaWP+0Bg6gONZVY/zaQes D19b0VJePp+UkbKBQleFbUV4XlWZSY1telmt/rIMEtzWaLgoen/uCXdISJpE8dgVHVdJ Bs6tKTeqO6TXgvLLxPtvIZkAQOmNkzF5LoGJ+um+ImnCjSgbCQ5tjnxeKID9xEj0z8F5 /kRjuY68QTLtNQq2gRtYtfXSoJQsBgt0wMRUw6kt85YytVg5OsToyWH615/kXFRnvYMl NOtBZ0PxDZhp4OCQ2+pJmYJBtY3x1uiCojOABdiVnAra7zGpm9c4lt6biYlrMw58B9CG 2jeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=pozcEYdB457UOzbYZWRE4UiDnTR5HVuZUKIMRt2DvNk=; b=IYWFwatWNgqFAAaPwfNBUwrLanwm8ddaUOK2PVYWjJbRX+qK1JYk2Y81wK3IUeWR4p ujeWGnrfsluYePdVUxNITqpTqrukCqqAnq5YRJmkVlPAPwLXT0KCHaJllC2pFTkKjxiy l2w3WeiOSGSzg1PUahRJTBOm3hNT6hRhSphUO0Uf9oQov3Tq2YqghHsg6oXLYEmQtg9T 3ehDrECgXbPMCowjTdSboUg/URrP2xX6QZ3m5aQHDgrf1AacnQ9vMaROi1OSctTE/lhO 5W0fzVDhJphNSiqd0h30S0McIxYP8kpMJK2Nve4Qxu1H6fJ056D0uFPedfcCvEt/ic8O G0gQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jj2-20020a170903048200b001a986ca38easi82539plb.15.2023.05.23.02.42.37; Tue, 23 May 2023 02:42:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235975AbjEWJd7 (ORCPT + 99 others); Tue, 23 May 2023 05:33:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235518AbjEWJd4 (ORCPT ); Tue, 23 May 2023 05:33:56 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70FB219D; Tue, 23 May 2023 02:33:48 -0700 (PDT) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QQTZf5YxVzLptm; Tue, 23 May 2023 17:30:50 +0800 (CST) Received: from localhost.localdomain (10.50.163.32) by canpemm500009.china.huawei.com (7.192.105.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 23 May 2023 17:33:46 +0800 From: Yicong Yang To: , , , , , CC: , , , , Subject: [PATCH v3 1/4] hwtracing: hisi_ptt: Factor out filter allocation and release operation Date: Tue, 23 May 2023 17:32:25 +0800 Message-ID: <20230523093228.48149-2-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230523093228.48149-1-yangyicong@huawei.com> References: <20230523093228.48149-1-yangyicong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766677512656120901?= X-GMAIL-MSGID: =?utf-8?q?1766677512656120901?= From: Yicong Yang Factor out the allocation and release of filters. This will make it easier to extend and manage the function of the filter. Signed-off-by: Yicong Yang Reviewed-by: Jonathan Cameron --- drivers/hwtracing/ptt/hisi_ptt.c | 63 ++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/drivers/hwtracing/ptt/hisi_ptt.c b/drivers/hwtracing/ptt/hisi_ptt.c index 30f1525639b5..548cfef51ace 100644 --- a/drivers/hwtracing/ptt/hisi_ptt.c +++ b/drivers/hwtracing/ptt/hisi_ptt.c @@ -354,6 +354,39 @@ static int hisi_ptt_register_irq(struct hisi_ptt *hisi_ptt) return 0; } +static void hisi_ptt_del_free_filter(struct hisi_ptt *hisi_ptt, + struct hisi_ptt_filter_desc *filter) +{ + list_del(&filter->list); + kfree(filter); +} + +static struct hisi_ptt_filter_desc * +hisi_ptt_alloc_add_filter(struct hisi_ptt *hisi_ptt, struct pci_dev *pdev) +{ + struct hisi_ptt_filter_desc *filter; + + filter = kzalloc(sizeof(*filter), GFP_KERNEL); + if (!filter) { + pci_err(hisi_ptt->pdev, "failed to add filter for %s\n", + pci_name(pdev)); + return NULL; + } + + filter->devid = PCI_DEVID(pdev->bus->number, pdev->devfn); + filter->is_port = pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT; + if (filter->is_port) { + list_add_tail(&filter->list, &hisi_ptt->port_filters); + + /* Update the available port mask */ + hisi_ptt->port_mask |= hisi_ptt_get_filter_val(filter->devid, true); + } else { + list_add_tail(&filter->list, &hisi_ptt->req_filters); + } + + return filter; +} + static int hisi_ptt_init_filters(struct pci_dev *pdev, void *data) { struct pci_dev *root_port = pcie_find_root_port(pdev); @@ -374,23 +407,9 @@ static int hisi_ptt_init_filters(struct pci_dev *pdev, void *data) * should be partial initialized and users would know which filter fails * through the log. Other functions of PTT device are still available. */ - filter = kzalloc(sizeof(*filter), GFP_KERNEL); - if (!filter) { - pci_err(hisi_ptt->pdev, "failed to add filter %s\n", pci_name(pdev)); + filter = hisi_ptt_alloc_add_filter(hisi_ptt, pdev); + if (!filter) return -ENOMEM; - } - - filter->devid = PCI_DEVID(pdev->bus->number, pdev->devfn); - - if (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT) { - filter->is_port = true; - list_add_tail(&filter->list, &hisi_ptt->port_filters); - - /* Update the available port mask */ - hisi_ptt->port_mask |= hisi_ptt_get_filter_val(filter->devid, true); - } else { - list_add_tail(&filter->list, &hisi_ptt->req_filters); - } return 0; } @@ -400,15 +419,11 @@ static void hisi_ptt_release_filters(void *data) struct hisi_ptt_filter_desc *filter, *tmp; struct hisi_ptt *hisi_ptt = data; - list_for_each_entry_safe(filter, tmp, &hisi_ptt->req_filters, list) { - list_del(&filter->list); - kfree(filter); - } + list_for_each_entry_safe(filter, tmp, &hisi_ptt->req_filters, list) + hisi_ptt_del_free_filter(hisi_ptt, filter); - list_for_each_entry_safe(filter, tmp, &hisi_ptt->port_filters, list) { - list_del(&filter->list); - kfree(filter); - } + list_for_each_entry_safe(filter, tmp, &hisi_ptt->port_filters, list) + hisi_ptt_del_free_filter(hisi_ptt, filter); } static int hisi_ptt_config_trace_buf(struct hisi_ptt *hisi_ptt)