mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yicong Yang <yangyicong@huawei.com>
To: <suzuki.poulose@arm.com>, <jonathan.cameron@huawei.com>,
	<linux-kernel@vger.kernel.org>
Cc: <shenyang39@huawei.com>, <moubingquan@huawei.com>,
	<prime.zeng@hisilicon.com>, <yangyicong@hisilicon.com>,
	<linuxarm@huawei.com>
Subject: [PATCH] hwtracing: hisi_ptt: Initialize the filter sysfs attribute when allocation
Date: Fri, 21 Feb 2025 18:54:49 +0800	[thread overview]
Message-ID: <20250221105449.64892-1-yangyicong@huawei.com> (raw)

From: Yicong Yang <yangyicong@hisilicon.com>

The filter sysfs attribute is initialized when creating to the sysfs.
This is unnecessary and could be done when allocation without
distinguishing the filter type.

After the changes above, we don't need a wrapper for initializing and
registering the filter's sysfs attributes. Remove them and call the
sysfs creating/removing functions in place.

Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
---
 drivers/hwtracing/ptt/hisi_ptt.c | 92 ++++++++++----------------------
 1 file changed, 29 insertions(+), 63 deletions(-)

diff --git a/drivers/hwtracing/ptt/hisi_ptt.c b/drivers/hwtracing/ptt/hisi_ptt.c
index 3090479a2979..83cf84cc6df9 100644
--- a/drivers/hwtracing/ptt/hisi_ptt.c
+++ b/drivers/hwtracing/ptt/hisi_ptt.c
@@ -368,6 +368,19 @@ static void hisi_ptt_del_free_filter(struct hisi_ptt *hisi_ptt,
 	kfree(filter);
 }
 
+static ssize_t hisi_ptt_filter_show(struct device *dev, struct device_attribute *attr,
+				    char *buf)
+{
+	struct hisi_ptt_filter_desc *filter;
+	unsigned long filter_val;
+
+	filter = container_of(attr, struct hisi_ptt_filter_desc, attr);
+	filter_val = hisi_ptt_get_filter_val(filter->devid, filter->is_port) |
+		     (filter->is_port ? HISI_PTT_PMU_FILTER_IS_PORT : 0);
+
+	return sysfs_emit(buf, "0x%05lx\n", filter_val);
+}
+
 static struct hisi_ptt_filter_desc *
 hisi_ptt_alloc_add_filter(struct hisi_ptt *hisi_ptt, u16 devid, bool is_port)
 {
@@ -396,6 +409,11 @@ hisi_ptt_alloc_add_filter(struct hisi_ptt *hisi_ptt, u16 devid, bool is_port)
 	filter->is_port = is_port;
 	filter->devid = devid;
 
+	sysfs_attr_init(&filter->attr.attr);
+	filter->attr.attr.name = filter->name;
+	filter->attr.attr.mode = 0400; /* DEVICE_ATTR_ADMIN_RO */
+	filter->attr.show = hisi_ptt_filter_show;
+
 	if (filter->is_port) {
 		list_add_tail(&filter->list, &hisi_ptt->port_filters);
 
@@ -408,74 +426,18 @@ hisi_ptt_alloc_add_filter(struct hisi_ptt *hisi_ptt, u16 devid, bool is_port)
 	return filter;
 }
 
-static ssize_t hisi_ptt_filter_show(struct device *dev, struct device_attribute *attr,
-				    char *buf)
-{
-	struct hisi_ptt_filter_desc *filter;
-	unsigned long filter_val;
-
-	filter = container_of(attr, struct hisi_ptt_filter_desc, attr);
-	filter_val = hisi_ptt_get_filter_val(filter->devid, filter->is_port) |
-		     (filter->is_port ? HISI_PTT_PMU_FILTER_IS_PORT : 0);
-
-	return sysfs_emit(buf, "0x%05lx\n", filter_val);
-}
-
-static int hisi_ptt_create_rp_filter_attr(struct hisi_ptt *hisi_ptt,
-					  struct hisi_ptt_filter_desc *filter)
-{
-	struct kobject *kobj = &hisi_ptt->hisi_ptt_pmu.dev->kobj;
-
-	sysfs_attr_init(&filter->attr.attr);
-	filter->attr.attr.name = filter->name;
-	filter->attr.attr.mode = 0400; /* DEVICE_ATTR_ADMIN_RO */
-	filter->attr.show = hisi_ptt_filter_show;
-
-	return sysfs_add_file_to_group(kobj, &filter->attr.attr,
-				       HISI_PTT_RP_FILTERS_GRP_NAME);
-}
-
-static void hisi_ptt_remove_rp_filter_attr(struct hisi_ptt *hisi_ptt,
-					  struct hisi_ptt_filter_desc *filter)
-{
-	struct kobject *kobj = &hisi_ptt->hisi_ptt_pmu.dev->kobj;
-
-	sysfs_remove_file_from_group(kobj, &filter->attr.attr,
-				     HISI_PTT_RP_FILTERS_GRP_NAME);
-}
-
-static int hisi_ptt_create_req_filter_attr(struct hisi_ptt *hisi_ptt,
-					   struct hisi_ptt_filter_desc *filter)
-{
-	struct kobject *kobj = &hisi_ptt->hisi_ptt_pmu.dev->kobj;
-
-	sysfs_attr_init(&filter->attr.attr);
-	filter->attr.attr.name = filter->name;
-	filter->attr.attr.mode = 0400; /* DEVICE_ATTR_ADMIN_RO */
-	filter->attr.show = hisi_ptt_filter_show;
-
-	return sysfs_add_file_to_group(kobj, &filter->attr.attr,
-				       HISI_PTT_REQ_FILTERS_GRP_NAME);
-}
-
-static void hisi_ptt_remove_req_filter_attr(struct hisi_ptt *hisi_ptt,
-					   struct hisi_ptt_filter_desc *filter)
-{
-	struct kobject *kobj = &hisi_ptt->hisi_ptt_pmu.dev->kobj;
-
-	sysfs_remove_file_from_group(kobj, &filter->attr.attr,
-				     HISI_PTT_REQ_FILTERS_GRP_NAME);
-}
-
 static int hisi_ptt_create_filter_attr(struct hisi_ptt *hisi_ptt,
 				       struct hisi_ptt_filter_desc *filter)
 {
+	struct kobject *kobj = &hisi_ptt->hisi_ptt_pmu.dev->kobj;
 	int ret;
 
 	if (filter->is_port)
-		ret = hisi_ptt_create_rp_filter_attr(hisi_ptt, filter);
+		ret = sysfs_add_file_to_group(kobj, &filter->attr.attr,
+					      HISI_PTT_RP_FILTERS_GRP_NAME);
 	else
-		ret = hisi_ptt_create_req_filter_attr(hisi_ptt, filter);
+		ret = sysfs_add_file_to_group(kobj, &filter->attr.attr,
+					      HISI_PTT_REQ_FILTERS_GRP_NAME);
 
 	if (ret)
 		pci_err(hisi_ptt->pdev, "failed to create sysfs attribute for filter %s\n",
@@ -487,10 +449,14 @@ static int hisi_ptt_create_filter_attr(struct hisi_ptt *hisi_ptt,
 static void hisi_ptt_remove_filter_attr(struct hisi_ptt *hisi_ptt,
 					struct hisi_ptt_filter_desc *filter)
 {
+	struct kobject *kobj = &hisi_ptt->hisi_ptt_pmu.dev->kobj;
+
 	if (filter->is_port)
-		hisi_ptt_remove_rp_filter_attr(hisi_ptt, filter);
+		sysfs_remove_file_from_group(kobj, &filter->attr.attr,
+					     HISI_PTT_RP_FILTERS_GRP_NAME);
 	else
-		hisi_ptt_remove_req_filter_attr(hisi_ptt, filter);
+		sysfs_remove_file_from_group(kobj, &filter->attr.attr,
+					     HISI_PTT_REQ_FILTERS_GRP_NAME);
 }
 
 static void hisi_ptt_remove_all_filter_attributes(void *data)
-- 
2.24.0


                 reply	other threads:[~2025-02-21 10:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20250221105449.64892-1-yangyicong@huawei.com \
    --to=yangyicong@huawei.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=moubingquan@huawei.com \
    --cc=prime.zeng@hisilicon.com \
    --cc=shenyang39@huawei.com \
    --cc=suzuki.poulose@arm.com \
    --cc=yangyicong@hisilicon.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

all inboxes | Powered by JetHome®