2018-07-21 06:49:10

by Julia Lawall

[permalink] [raw]
Subject: [PATCH] NTB: fix debugfs_simple_attr.cocci warnings

From: kbuild test robot <[email protected]>

Use DEFINE_DEBUGFS_ATTRIBUTE rather than DEFINE_SIMPLE_ATTRIBUTE
for debugfs files.

Rationale: DEFINE_SIMPLE_ATTRIBUTE + debugfs_create_file()
imposes some significant overhead as compared to
DEFINE_DEBUGFS_ATTRIBUTE + debugfs_create_file_unsafe().

Generated by: scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci

Fixes: c75153197d20 ("NTB: Introduce NTB MSI Test Client")
Signed-off-by: kbuild test robot <[email protected]>
Signed-off-by: Julia Lawall <[email protected]>
---

I don't know much about this issue, beyondwhat is explained by the
semantic patch. Please check if the changes can be relevant.

ntb_msi_test.c | 61 ++++++++++++++++++++++++++++-----------------------------
1 file changed, 31 insertions(+), 30 deletions(-)

--- a/drivers/ntb/test/ntb_msi_test.c
+++ b/drivers/ntb/test/ntb_msi_test.c
@@ -170,8 +170,8 @@ static int ntb_msit_dbgfs_trigger(void *
&peer->msi_desc[idx]);
}

-DEFINE_SIMPLE_ATTRIBUTE(ntb_msit_trigger_fops, NULL,
- ntb_msit_dbgfs_trigger, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(ntb_msit_trigger_fops, NULL, ntb_msit_dbgfs_trigger,
+ "%llu\n");

static int ntb_msit_dbgfs_port_get(void *data, u64 *port)
{
@@ -182,8 +182,8 @@ static int ntb_msit_dbgfs_port_get(void
return 0;
}

-DEFINE_SIMPLE_ATTRIBUTE(ntb_msit_port_fops, ntb_msit_dbgfs_port_get,
- NULL, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(ntb_msit_port_fops, ntb_msit_dbgfs_port_get, NULL,
+ "%llu\n");

static int ntb_msit_dbgfs_count_get(void *data, u64 *count)
{
@@ -194,8 +194,8 @@ static int ntb_msit_dbgfs_count_get(void
return 0;
}

-DEFINE_SIMPLE_ATTRIBUTE(ntb_msit_count_fops, ntb_msit_dbgfs_count_get,
- NULL, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(ntb_msit_count_fops, ntb_msit_dbgfs_count_get, NULL,
+ "%llu\n");

static int ntb_msit_dbgfs_ready_get(void *data, u64 *ready)
{
@@ -213,8 +213,8 @@ static int ntb_msit_dbgfs_ready_set(void
return wait_for_completion_interruptible(&peer->init_comp);
}

-DEFINE_SIMPLE_ATTRIBUTE(ntb_msit_ready_fops, ntb_msit_dbgfs_ready_get,
- ntb_msit_dbgfs_ready_set, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(ntb_msit_ready_fops, ntb_msit_dbgfs_ready_get,
+ ntb_msit_dbgfs_ready_set, "%llu\n");

static int ntb_msit_dbgfs_occurrences_get(void *data, u64 *occurrences)
{
@@ -225,9 +225,8 @@ static int ntb_msit_dbgfs_occurrences_ge
return 0;
}

-DEFINE_SIMPLE_ATTRIBUTE(ntb_msit_occurrences_fops,
- ntb_msit_dbgfs_occurrences_get,
- NULL, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(ntb_msit_occurrences_fops,
+ ntb_msit_dbgfs_occurrences_get, NULL, "%llu\n");

static int ntb_msit_dbgfs_local_port_get(void *data, u64 *port)
{
@@ -238,9 +237,8 @@ static int ntb_msit_dbgfs_local_port_get
return 0;
}

-DEFINE_SIMPLE_ATTRIBUTE(ntb_msit_local_port_fops,
- ntb_msit_dbgfs_local_port_get,
- NULL, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(ntb_msit_local_port_fops,
+ ntb_msit_dbgfs_local_port_get, NULL, "%llu\n");

static void ntb_msit_create_dbgfs(struct ntb_msit_ctx *nm)
{
@@ -251,8 +249,8 @@ static void ntb_msit_create_dbgfs(struct

nm->dbgfs_dir = debugfs_create_dir(pci_name(pdev),
ntb_msit_dbgfs_topdir);
- debugfs_create_file("port", 0400, nm->dbgfs_dir, nm,
- &ntb_msit_local_port_fops);
+ debugfs_create_file_unsafe("port", 0400, nm->dbgfs_dir, nm,
+ &ntb_msit_local_port_fops);

for (i = 0; i < ntb_peer_port_count(nm->ntb); i++) {
nm->peers[i].pidx = i;
@@ -262,24 +260,27 @@ static void ntb_msit_create_dbgfs(struct
snprintf(buf, sizeof(buf), "peer%d", i);
peer_dir = debugfs_create_dir(buf, nm->dbgfs_dir);

- debugfs_create_file("trigger", 0200, peer_dir,
- &nm->peers[i], &ntb_msit_trigger_fops);
-
- debugfs_create_file("port", 0400, peer_dir,
- &nm->peers[i], &ntb_msit_port_fops);
-
- debugfs_create_file("count", 0400, peer_dir,
- &nm->peers[i], &ntb_msit_count_fops);
-
- debugfs_create_file("ready", 0600, peer_dir,
- &nm->peers[i], &ntb_msit_ready_fops);
+ debugfs_create_file_unsafe("trigger", 0200, peer_dir,
+ &nm->peers[i],
+ &ntb_msit_trigger_fops);
+
+ debugfs_create_file_unsafe("port", 0400, peer_dir,
+ &nm->peers[i], &ntb_msit_port_fops);
+
+ debugfs_create_file_unsafe("count", 0400, peer_dir,
+ &nm->peers[i],
+ &ntb_msit_count_fops);
+
+ debugfs_create_file_unsafe("ready", 0600, peer_dir,
+ &nm->peers[i],
+ &ntb_msit_ready_fops);
}

for (i = 0; i < num_irqs; i++) {
snprintf(buf, sizeof(buf), "irq%d_occurrences", i);
- debugfs_create_file(buf, 0400, nm->dbgfs_dir,
- &nm->isr_ctx[i],
- &ntb_msit_occurrences_fops);
+ debugfs_create_file_unsafe(buf, 0400, nm->dbgfs_dir,
+ &nm->isr_ctx[i],
+ &ntb_msit_occurrences_fops);
}
}



2018-07-23 17:59:31

by Logan Gunthorpe

[permalink] [raw]
Subject: Re: [PATCH] NTB: fix debugfs_simple_attr.cocci warnings



On 21/07/18 12:47 AM, Julia Lawall wrote:
> From: kbuild test robot <[email protected]>
>
> Use DEFINE_DEBUGFS_ATTRIBUTE rather than DEFINE_SIMPLE_ATTRIBUTE
> for debugfs files.
>
> Rationale: DEFINE_SIMPLE_ATTRIBUTE + debugfs_create_file()
> imposes some significant overhead as compared to
> DEFINE_DEBUGFS_ATTRIBUTE + debugfs_create_file_unsafe().
>
> Generated by: scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci
>
> Fixes: c75153197d20 ("NTB: Introduce NTB MSI Test Client")
> Signed-off-by: kbuild test robot <[email protected]>
> Signed-off-by: Julia Lawall <[email protected]>
> ---
>
> I don't know much about this issue, beyondwhat is explained by the
> semantic patch. Please check if the changes can be relevant.

Oops, this work wasn't meant for public consumption yet. Everyone
pretend you didn't see that ;). I must have pushed it to my repo that
kbuild tests by accident.

Though, I'm glad to have learned about the more efficient use of debugfs
attributes.

Logan