Skip to content

Commit a3ecaba

Browse files
Yicong YangSuzuki K Poulose
authored andcommitted
hwtracing: hisi_ptt: Factor out filter allocation and release operation
Factor out the allocation and release of filters. This will make it easier to extend and manage the function of the filter. Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> Link: https://lore.kernel.org/r/20230621092804.15120-2-yangyicong@huawei.com
1 parent 185891f commit a3ecaba

1 file changed

Lines changed: 39 additions & 24 deletions

File tree

drivers/hwtracing/ptt/hisi_ptt.c

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,39 @@ static int hisi_ptt_register_irq(struct hisi_ptt *hisi_ptt)
354354
return 0;
355355
}
356356

357+
static void hisi_ptt_del_free_filter(struct hisi_ptt *hisi_ptt,
358+
struct hisi_ptt_filter_desc *filter)
359+
{
360+
list_del(&filter->list);
361+
kfree(filter);
362+
}
363+
364+
static struct hisi_ptt_filter_desc *
365+
hisi_ptt_alloc_add_filter(struct hisi_ptt *hisi_ptt, struct pci_dev *pdev)
366+
{
367+
struct hisi_ptt_filter_desc *filter;
368+
369+
filter = kzalloc(sizeof(*filter), GFP_KERNEL);
370+
if (!filter) {
371+
pci_err(hisi_ptt->pdev, "failed to add filter for %s\n",
372+
pci_name(pdev));
373+
return NULL;
374+
}
375+
376+
filter->devid = PCI_DEVID(pdev->bus->number, pdev->devfn);
377+
filter->is_port = pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT;
378+
if (filter->is_port) {
379+
list_add_tail(&filter->list, &hisi_ptt->port_filters);
380+
381+
/* Update the available port mask */
382+
hisi_ptt->port_mask |= hisi_ptt_get_filter_val(filter->devid, true);
383+
} else {
384+
list_add_tail(&filter->list, &hisi_ptt->req_filters);
385+
}
386+
387+
return filter;
388+
}
389+
357390
static int hisi_ptt_init_filters(struct pci_dev *pdev, void *data)
358391
{
359392
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)
374407
* should be partial initialized and users would know which filter fails
375408
* through the log. Other functions of PTT device are still available.
376409
*/
377-
filter = kzalloc(sizeof(*filter), GFP_KERNEL);
378-
if (!filter) {
379-
pci_err(hisi_ptt->pdev, "failed to add filter %s\n", pci_name(pdev));
410+
filter = hisi_ptt_alloc_add_filter(hisi_ptt, pdev);
411+
if (!filter)
380412
return -ENOMEM;
381-
}
382-
383-
filter->devid = PCI_DEVID(pdev->bus->number, pdev->devfn);
384-
385-
if (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT) {
386-
filter->is_port = true;
387-
list_add_tail(&filter->list, &hisi_ptt->port_filters);
388-
389-
/* Update the available port mask */
390-
hisi_ptt->port_mask |= hisi_ptt_get_filter_val(filter->devid, true);
391-
} else {
392-
list_add_tail(&filter->list, &hisi_ptt->req_filters);
393-
}
394413

395414
return 0;
396415
}
@@ -400,15 +419,11 @@ static void hisi_ptt_release_filters(void *data)
400419
struct hisi_ptt_filter_desc *filter, *tmp;
401420
struct hisi_ptt *hisi_ptt = data;
402421

403-
list_for_each_entry_safe(filter, tmp, &hisi_ptt->req_filters, list) {
404-
list_del(&filter->list);
405-
kfree(filter);
406-
}
422+
list_for_each_entry_safe(filter, tmp, &hisi_ptt->req_filters, list)
423+
hisi_ptt_del_free_filter(hisi_ptt, filter);
407424

408-
list_for_each_entry_safe(filter, tmp, &hisi_ptt->port_filters, list) {
409-
list_del(&filter->list);
410-
kfree(filter);
411-
}
425+
list_for_each_entry_safe(filter, tmp, &hisi_ptt->port_filters, list)
426+
hisi_ptt_del_free_filter(hisi_ptt, filter);
412427
}
413428

414429
static int hisi_ptt_config_trace_buf(struct hisi_ptt *hisi_ptt)

0 commit comments

Comments
 (0)