selftests/fpu: fix debugfs_simple_attr.cocci warnings
PATCH 1/1 selftests/fpu: fix debugfs_simple_attr.cocci warnings
From: kernel test robot <[email protected]>
lib/test_fpu.c:66:0-23: WARNING: test_fpu_fops should be defined with DEFINE_DEBUGFS_ATTRIBUTE
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
---
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: b6f96e75ae121ead54da3f58c545d68184079f90 commit: 4185b3b92792eaec5869266e594338343421ffb0 selftests/fpu: Add an FPU selftest
:::::: branch date: 2 hours ago
:::::: commit date: 4 months ago
I don't know much about this issue, but I'm passing the warning along. The original commit of the semantic patch contains some more information:
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.
test_fpu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
lib/test_fpu.c +3 -3
@@ -63,7 +63,7 @@ static int test_fpu_get(void *data, u64return status; } -DEFINE_SIMPLE_ATTRIBUTE (test_fpu_fops, test_fpu_get,NULL ,"%lld\n" ); +DEFINE_DEBUGFS_ATTRIBUTE (test_fpu_fops, test_fpu_get,NULL ,"%lld\n" );static struct dentry *selftest_dir;static int __init test_fpu_init (void )
@@ -72,8 +72,8 @@ static int __init test_fpu_init(void)if (!selftest_dir)return -ENOMEM ; -debugfs_create_file ("test_fpu" ,0444 , selftest_dir,NULL , - &test_fpu_fops); +debugfs_create_file_unsafe ("test_fpu" ,0444 , selftest_dir,NULL , + &test_fpu_fops);return 0 ; }
[tip: x86/misc] selftests/fpu: Fix debugfs_simple_attr.cocci warning
The following commit has been merged into the x86/misc branch of tip:
The following commit has been merged into the x86/misc branch of tip:
Commit-ID: 443121b3ebb9025fd99ff11851d3537cb756d456 Gitweb: https://git.kernel.org/tip/443121b3ebb9025fd99ff11851d3537cb756d456 Author: kernel test robot <[email protected]> AuthorDate: Sun, 25 Oct 2020 11:20:04 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Mon, 18 Jan 2021 11:03:26 +01:00
selftests/fpu: Fix debugfs_simple_attr.cocci warning
lib/test_fpu.c:66:0-23: WARNING: test_fpu_fops should be defined with DEFINE_DEBUGFS_ATTRIBUTE
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().
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.
Generated by: scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci
--- lib/test_fpu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
lib/test_fpu.c +3 -3
@@ -63,7 +63,7 @@ static int test_fpu_get(void *data, u64 *val)return status; } -DEFINE_SIMPLE_ATTRIBUTE (test_fpu_fops, test_fpu_get,NULL ,"%lld\n" ); +DEFINE_DEBUGFS_ATTRIBUTE (test_fpu_fops, test_fpu_get,NULL ,"%lld\n" );static struct dentry *selftest_dir;static int __init test_fpu_init (void )
@@ -72,8 +72,8 @@ static int __init test_fpu_init(void)if (!selftest_dir)return -ENOMEM ; -debugfs_create_file ("test_fpu" ,0444 , selftest_dir,NULL , - &test_fpu_fops); +debugfs_create_file_unsafe ("test_fpu" ,0444 , selftest_dir,NULL , + &test_fpu_fops);return 0 ; }