diff mbox series

wil6210: fix debugfs_simple_attr.cocci warnings

Message ID 1538737646-118337-1-git-send-email-yuehaibing@huawei.com (mailing list archive)
State Accepted
Commit f9dca154a4e4d185bad15a431f0ff095cd931df6
Delegated to: Kalle Valo
Headers show
Series wil6210: fix debugfs_simple_attr.cocci warnings | expand

Commit Message

Yue Haibing Oct. 5, 2018, 11:07 a.m. UTC
Use DEFINE_DEBUGFS_ATTRIBUTE rather than DEFINE_SIMPLE_ATTRIBUTE
for debugfs files.

Semantic patch information:
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

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 drivers/net/wireless/ath/wil6210/debugfs.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

Comments

Kalle Valo Oct. 5, 2018, 11:04 a.m. UTC | #1
YueHaibing <yuehaibing@huawei.com> writes:

> Use DEFINE_DEBUGFS_ATTRIBUTE rather than DEFINE_SIMPLE_ATTRIBUTE
> for debugfs files.
>
> Semantic patch information:
> 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

Just out of curiosity, what kind of overhead are we talking about here?
Yue Haibing Oct. 5, 2018, 11:51 a.m. UTC | #2
On 2018/10/5 19:04, Kalle Valo wrote:
> YueHaibing <yuehaibing@huawei.com> writes:
> 
>> Use DEFINE_DEBUGFS_ATTRIBUTE rather than DEFINE_SIMPLE_ATTRIBUTE
>> for debugfs files.
>>
>> Semantic patch information:
>> 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
> 
> Just out of curiosity, what kind of overhead are we talking about here?

commit 5103068eaca2 ("debugfs, coccinelle: check for obsolete DEFINE_SIMPLE_ATTRIBUTE() usage")
said this:

    In order to protect against file removal races, debugfs files created via
    debugfs_create_file() now get wrapped by a struct file_operations at their
    opening.

    If the original struct file_operations are known to be safe against removal
    races by themselves already, the proxy creation may be bypassed by creating
    the files through debugfs_create_file_unsafe().

    In order to help debugfs users who use the common
      DEFINE_SIMPLE_ATTRIBUTE() + debugfs_create_file()
    idiom to transition to removal safe struct file_operations, the helper
    macro DEFINE_DEBUGFS_ATTRIBUTE() has been introduced.


>
Julia Lawall Oct. 5, 2018, 2:29 p.m. UTC | #3
On Fri, 5 Oct 2018, Kalle Valo wrote:

> YueHaibing <yuehaibing@huawei.com> writes:
>
> > Use DEFINE_DEBUGFS_ATTRIBUTE rather than DEFINE_SIMPLE_ATTRIBUTE
> > for debugfs files.
> >
> > Semantic patch information:
> > 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
>
> Just out of curiosity, what kind of overhead are we talking about here?

The log message on the commit introducing the semantic patch says the
following:

    In order to protect against file removal races, debugfs files created via
    debugfs_create_file() now get wrapped by a struct file_operations at their
    opening.

    If the original struct file_operations are known to be safe against removal
    races by themselves already, the proxy creation may be bypassed by creating
    the files through debugfs_create_file_unsafe().

    In order to help debugfs users who use the common
      DEFINE_SIMPLE_ATTRIBUTE() + debugfs_create_file()
    idiom to transition to removal safe struct file_operations, the helper
    macro DEFINE_DEBUGFS_ATTRIBUTE() has been introduced.

    Thus, the preferred strategy is to use
      DEFINE_DEBUGFS_ATTRIBUTE() + debugfs_create_file_unsafe()
    now.

julia

>
> --
> Kalle Valo
>
Kalle Valo Oct. 6, 2018, 12:11 p.m. UTC | #4
Julia Lawall <julia.lawall@lip6.fr> writes:

> On Fri, 5 Oct 2018, Kalle Valo wrote:
>
>> YueHaibing <yuehaibing@huawei.com> writes:
>>
>> > Use DEFINE_DEBUGFS_ATTRIBUTE rather than DEFINE_SIMPLE_ATTRIBUTE
>> > for debugfs files.
>> >
>> > Semantic patch information:
>> > 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
>>
>> Just out of curiosity, what kind of overhead are we talking about here?
>
> The log message on the commit introducing the semantic patch says the
> following:
>
>     In order to protect against file removal races, debugfs files created via
>     debugfs_create_file() now get wrapped by a struct file_operations at their
>     opening.
>
>     If the original struct file_operations are known to be safe against removal
>     races by themselves already, the proxy creation may be bypassed by creating
>     the files through debugfs_create_file_unsafe().
>
>     In order to help debugfs users who use the common
>       DEFINE_SIMPLE_ATTRIBUTE() + debugfs_create_file()
>     idiom to transition to removal safe struct file_operations, the helper
>     macro DEFINE_DEBUGFS_ATTRIBUTE() has been introduced.
>
>     Thus, the preferred strategy is to use
>       DEFINE_DEBUGFS_ATTRIBUTE() + debugfs_create_file_unsafe()
>     now.

I admit that I didn't have time to investigate this is detail but I'm
still not understanding where is that "significant overhead" coming from
and how big of overhead are we talking about? I guess it has something
to do with full_proxy_open() vs open_proxy_open()?

Not that I'm against this patch, just curious when I see someone
claiming "significant overhead" which is not obvious for me.
Julia Lawall Oct. 6, 2018, 12:22 p.m. UTC | #5
On Sat, 6 Oct 2018, Kalle Valo wrote:

> Julia Lawall <julia.lawall@lip6.fr> writes:
>
> > On Fri, 5 Oct 2018, Kalle Valo wrote:
> >
> >> YueHaibing <yuehaibing@huawei.com> writes:
> >>
> >> > Use DEFINE_DEBUGFS_ATTRIBUTE rather than DEFINE_SIMPLE_ATTRIBUTE
> >> > for debugfs files.
> >> >
> >> > Semantic patch information:
> >> > 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
> >>
> >> Just out of curiosity, what kind of overhead are we talking about here?
> >
> > The log message on the commit introducing the semantic patch says the
> > following:
> >
> >     In order to protect against file removal races, debugfs files created via
> >     debugfs_create_file() now get wrapped by a struct file_operations at their
> >     opening.
> >
> >     If the original struct file_operations are known to be safe against removal
> >     races by themselves already, the proxy creation may be bypassed by creating
> >     the files through debugfs_create_file_unsafe().
> >
> >     In order to help debugfs users who use the common
> >       DEFINE_SIMPLE_ATTRIBUTE() + debugfs_create_file()
> >     idiom to transition to removal safe struct file_operations, the helper
> >     macro DEFINE_DEBUGFS_ATTRIBUTE() has been introduced.
> >
> >     Thus, the preferred strategy is to use
> >       DEFINE_DEBUGFS_ATTRIBUTE() + debugfs_create_file_unsafe()
> >     now.
>
> I admit that I didn't have time to investigate this is detail but I'm
> still not understanding where is that "significant overhead" coming from
> and how big of overhead are we talking about? I guess it has something
> to do with full_proxy_open() vs open_proxy_open()?
>
> Not that I'm against this patch, just curious when I see someone
> claiming "significant overhead" which is not obvious for me.

The message with the semantic patch doesn't really talk about significant
overhead.  Maybe YueHaibing can discuss with the person who proposed the
semantic patch what the actual issue is, and when the proposed change is
actually applicable.

julia


>
> --
> Kalle Valo
>
Kalle Valo Oct. 6, 2018, 12:54 p.m. UTC | #6
Julia Lawall <julia.lawall@lip6.fr> writes:

> On Sat, 6 Oct 2018, Kalle Valo wrote:
>
>> Julia Lawall <julia.lawall@lip6.fr> writes:
>>
>> > On Fri, 5 Oct 2018, Kalle Valo wrote:
>> >
>> >> YueHaibing <yuehaibing@huawei.com> writes:
>> >>
>> >> > Use DEFINE_DEBUGFS_ATTRIBUTE rather than DEFINE_SIMPLE_ATTRIBUTE
>> >> > for debugfs files.
>> >> >
>> >> > Semantic patch information:
>> >> > 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
>> >>
>> >> Just out of curiosity, what kind of overhead are we talking about here?
>> >
>> > The log message on the commit introducing the semantic patch says the
>> > following:
>> >
>> >     In order to protect against file removal races, debugfs files created via
>> >     debugfs_create_file() now get wrapped by a struct file_operations at their
>> >     opening.
>> >
>> >     If the original struct file_operations are known to be safe against removal
>> >     races by themselves already, the proxy creation may be bypassed by creating
>> >     the files through debugfs_create_file_unsafe().
>> >
>> >     In order to help debugfs users who use the common
>> >       DEFINE_SIMPLE_ATTRIBUTE() + debugfs_create_file()
>> >     idiom to transition to removal safe struct file_operations, the helper
>> >     macro DEFINE_DEBUGFS_ATTRIBUTE() has been introduced.
>> >
>> >     Thus, the preferred strategy is to use
>> >       DEFINE_DEBUGFS_ATTRIBUTE() + debugfs_create_file_unsafe()
>> >     now.
>>
>> I admit that I didn't have time to investigate this is detail but I'm
>> still not understanding where is that "significant overhead" coming from
>> and how big of overhead are we talking about? I guess it has something
>> to do with full_proxy_open() vs open_proxy_open()?
>>
>> Not that I'm against this patch, just curious when I see someone
>> claiming "significant overhead" which is not obvious for me.
>
> The message with the semantic patch doesn't really talk about significant
> overhead.  Maybe YueHaibing can discuss with the person who proposed the
> semantic patch what the actual issue is, and when the proposed change is
> actually applicable.

Actually commit 5103068eaca2 mentions "significant overhead":

--- /dev/null
+++ b/scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci
@@ -0,0 +1,67 @@
+/// 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().

But I'll anyway apply this patch as I don't see anything wrong with it.
I was just trying to learn where this overhead is :)
Kalle Valo Oct. 13, 2018, 5:29 p.m. UTC | #7
YueHaibing <yuehaibing@huawei.com> wrote:

> Use DEFINE_DEBUGFS_ATTRIBUTE rather than DEFINE_SIMPLE_ATTRIBUTE
> for debugfs files.
> 
> Semantic patch information:
> 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
> 
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> Signed-off-by: Kalle Valo <kvalo@codeaurora.org>

Patch applied to ath-next branch of ath.git, thanks.

f9dca154a4e4 wil6210: fix debugfs_simple_attr.cocci warnings
diff mbox series

Patch

diff --git a/drivers/net/wireless/ath/wil6210/debugfs.c b/drivers/net/wireless/ath/wil6210/debugfs.c
index 66ffae2..aa50813 100644
--- a/drivers/net/wireless/ath/wil6210/debugfs.c
+++ b/drivers/net/wireless/ath/wil6210/debugfs.c
@@ -416,8 +416,8 @@  static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
 	return 0;
 }
 
-DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
-			wil_debugfs_iomem_x32_set, "0x%08llx\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
+			 wil_debugfs_iomem_x32_set, "0x%08llx\n");
 
 static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
 						   umode_t mode,
@@ -432,7 +432,8 @@  static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
 	data->wil = wil;
 	data->offset = value;
 
-	file = debugfs_create_file(name, mode, parent, data, &fops_iomem_x32);
+	file = debugfs_create_file_unsafe(name, mode, parent, data,
+					  &fops_iomem_x32);
 	if (!IS_ERR_OR_NULL(file))
 		wil->dbg_data.iomem_data_count++;
 
@@ -451,14 +452,15 @@  static int wil_debugfs_ulong_get(void *data, u64 *val)
 	return 0;
 }
 
-DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
-			wil_debugfs_ulong_set, "0x%llx\n");
+DEFINE_DEBUGFS_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
+			 wil_debugfs_ulong_set, "0x%llx\n");
 
 static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
 					       struct dentry *parent,
 					       ulong *value)
 {
-	return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
+	return debugfs_create_file_unsafe(name, mode, parent, value,
+					  &wil_fops_ulong);
 }
 
 /**