linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Yicong Yang <yangyicong@huawei.com>
Cc: <mathieu.poirier@linaro.org>, <suzuki.poulose@arm.com>,
	<corbet@lwn.net>, <linux-kernel@vger.kernel.org>,
	<linux-doc@vger.kernel.org>, <alexander.shishkin@linux.intel.com>,
	<helgaas@kernel.org>, <linux-pci@vger.kernel.org>,
	<prime.zeng@huawei.com>, <linuxarm@huawei.com>
Subject: Re: [PATCH v3 1/4] hwtracing: hisi_ptt: Factor out filter allocation and release operation
Date: Tue, 6 Jun 2023 10:47:09 +0100	[thread overview]
Message-ID: <20230606104709.00000047@Huawei.com> (raw)
In-Reply-To: <20230523093228.48149-2-yangyicong@huawei.com>

On Tue, 23 May 2023 17:32:25 +0800
Yicong Yang <yangyicong@huawei.com> wrote:

> From: Yicong Yang <yangyicong@hisilicon.com>
> 
> 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 <yangyicong@hisilicon.com>

Straight forward refactor. LGTM

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  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)


  reply	other threads:[~2023-06-06  9:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-23  9:32 [PATCH v3 0/4] Improve PTT filter interface Yicong Yang
2023-05-23  9:32 ` [PATCH v3 1/4] hwtracing: hisi_ptt: Factor out filter allocation and release operation Yicong Yang
2023-06-06  9:47   ` Jonathan Cameron [this message]
2023-05-23  9:32 ` [PATCH v3 2/4] hwtracing: hisi_ptt: Add support for dynamically updating the filter list Yicong Yang
2023-06-06  9:56   ` Jonathan Cameron
2023-06-06 11:35     ` Yicong Yang
2023-05-23  9:32 ` [PATCH v3 3/4] hwtracing: hisi_ptt: Export available filters through sysfs Yicong Yang
2023-06-06 10:15   ` Jonathan Cameron
2023-06-06 11:42     ` Yicong Yang
2023-05-23  9:32 ` [PATCH v3 4/4] hwtracing: hisi_ptt: Advertise PERF_PMU_CAP_NO_EXCLUDE for PTT PMU Yicong Yang
2023-06-06 10:17   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230606104709.00000047@Huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=corbet@lwn.net \
    --cc=helgaas@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=mathieu.poirier@linaro.org \
    --cc=prime.zeng@huawei.com \
    --cc=suzuki.poulose@arm.com \
    --cc=yangyicong@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).