debugfs helpers cleanups
Subsystems (2)
cover debugfs helpers cleanups
commit ff9fb72bc077 ("debugfs: return error values, not NULL") changed the return values of various debugfs functions in fs/debugfs/inode.c but did not update the documentation or behaviour of affected functions in fs/debugfs/file.c . These patches attempt to remedy this.
Ronald Tschalär (2):
debugfs: update documented return values of debugfs helpers
debugfs: make return value of all debugfs helpers consistent
Documentation/filesystems/debugfs.txt | 16 +++--- fs/debugfs/file.c | 79 ++++++++++++--------------- 2 files changed, 45 insertions(+), 50 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/2 debugfs: update documented return values of debugfs helpers
Since commit ff9fb72bc077 ("debugfs: return error values, not NULL") these helper functions do not return NULL anymore (with the exception of debugfs_create_u32_array()).
--- Documentation/filesystems/debugfs.txt | 16 +++--- fs/debugfs/file.c | 77 ++++++++++++--------------- 2 files changed, 44 insertions(+), 49 deletions(-)
Documentation/filesystems/debugfs.txt +9 -7
@@ -31,10 +31,10 @@ This call, if successful, will make a directory called name underneath the indicated parent directory. If parent is NULL, the directory will be created in the debugfs root. On success, the return value is a struct dentry pointer which can be used to create files in the directory (and to -clean it up at the end). A NULL return value indicates that something went -wrong. If ERR_PTR(-ENODEV) is returned, that is an indication that the -kernel has been built without debugfs support and none of the functions -described below will work. +clean it up at the end). An ERR_PTR(-ERROR) return value indicates that +something went wrong. If ERR_PTR(-ENODEV) is returned, that is an +indication that the kernel has been built without debugfs support and none +of the functions described below will work. The most general way to create a file within a debugfs directory is with:
@@ -48,8 +48,9 @@ should hold the file, data will be stored in the i_private field of the resulting inode structure, and fops is a set of file operations which implement the file's behavior. At a minimum, the read() and/or write() operations should be provided; others can be included as needed. Again, -the return value will be a dentry pointer to the created file, NULL for -error, or ERR_PTR(-ENODEV) if debugfs support is missing. +the return value will be a dentry pointer to the created file, +ERR_PTR(-ERROR) on error, or ERR_PTR(-ENODEV) if debugfs support is +missing. Create a file with an initial size, the following function can be used instead:
@@ -214,7 +215,8 @@ can be removed with: void debugfs_remove(struct dentry *dentry); -The dentry value can be NULL, in which case nothing will be removed. +The dentry value can be NULL or an error value, in which case nothing will +be removed. Once upon a time, debugfs users were required to remember the dentry pointer for every debugfs file they created so that all files could be
fs/debugfs/file.c +35 -42
139 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 2/2 debugfs: make return value of all debugfs helpers consistent
In reply to Ronald TschalärSince commit ff9fb72bc077 ("debugfs: return error values, not NULL") almost all the debugfs helpers have stopped returning NULL. The lone holdeout was debugfs_create_u32_array(). So fix that.
--- fs/debugfs/file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/debugfs/file.c +3 -3
@@ -999,8 +999,8 @@ static const struct file_operations u32_array_fops = {* Once array is created its size can not be changed. * * The function returns a pointer to dentry on success. If an error occurs, -* %ERR_PTR(-ERROR) or NULL will be returned. If debugfs is not enabled in -* the kernel, the value %ERR_PTR(-ENODEV) will be returned. +* %ERR_PTR(-ERROR) will be returned. If debugfs is not enabled in the kernel, +* the value %ERR_PTR(-ENODEV) will be returned. */ struct dentry *debugfs_create_u32_array(const char *name, umode_t mode, struct dentry *parent,
@@ -1009,7 +1009,7 @@ struct dentry *debugfs_create_u32_array(const char *name, umode_t mode,struct array_data *data =kmalloc (sizeof (*data),GFP_KERNEL );if (data ==NULL ) -return NULL ; +return ERR_PTR (-ENOMEM ); data->array = array; data->elements = elements;
Signature · 1 line
2.20.1
Greg Kroah-Hartman
maintainerRe: [PATCH 2/2] debugfs: make return value of all debugfs helpers consistent
Quoted 25 lines · Ronald Tschalär
Since commit
ff9fb72bc077("debugfs: return error values, not NULL") almost all the debugfs helpers have stopped returning NULL. The lone holdeout wasdebugfs_create_u32_array(). So fix that.Signed-off-by Ronald Tschalär <[email protected]>--- fs/debugfs/file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)fs/debugfs/file.c +2
-2@@ -999,8 +999,8 @@ static const struct file_operations u32_array_fops = {* Once array is created its size can not be changed. * * The function returns a pointer to dentry on success. If an error occurs, -* %ERR_PTR(-ERROR) or NULL will be returned. If debugfs is not enabled in -* the kernel, the value %ERR_PTR(-ENODEV) will be returned. +* %ERR_PTR(-ERROR) will be returned. If debugfs is not enabled in the kernel, +* the value %ERR_PTR(-ENODEV) will be returned. */ struct dentry *debugfs_create_u32_array(const char *name, umode_t mode, struct dentry *parent,
fs/debugfs/file.c struct dentry *debugfs_create_u32_array(const char *name, umode_t mode, · line 1015
Quoted 8 lines
fs/debugfs/file.c +1
-1@@ -1009,7 +1009,7 @@ struct dentry *debugfs_create_u32_array(const char *name, umode_t mode,struct array_data *data =kmalloc (sizeof (*data),GFP_KERNEL );if (data ==NULL ) -return NULL ; +return ERR_PTR (-ENOMEM ); data->array = array; data->elements = elements;
There is only one caller of this function in the kernel now, and it does not even care about the return value at all, so we should just remove the return value entirely as that's the easiest and best thing to do here. I was going to start doing this slowly over time, but as you are touching the function now, might as well do it here :)
thanks,
greg k-h
Re: [PATCH 2/2] debugfs: make return value of all debugfs helpers consistent
Hi Greg,
Quoted 32 lines · Greg Kroah-Hartman
Quoted 31 lines · Ronald Tschalär
Since commit
ff9fb72bc077("debugfs: return error values, not NULL") almost all the debugfs helpers have stopped returning NULL. The lone holdeout wasdebugfs_create_u32_array(). So fix that.Signed-off-by Ronald Tschalär <[email protected]>--- fs/debugfs/file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)fs/debugfs/file.c +3
-3@@ -999,8 +999,8 @@ static const struct file_operations u32_array_fops = {* Once array is created its size can not be changed. * * The function returns a pointer to dentry on success. If an error occurs, -* %ERR_PTR(-ERROR) or NULL will be returned. If debugfs is not enabled in -* the kernel, the value %ERR_PTR(-ENODEV) will be returned. +* %ERR_PTR(-ERROR) will be returned. If debugfs is not enabled in the kernel, +* the value %ERR_PTR(-ENODEV) will be returned. */ struct dentry *debugfs_create_u32_array(const char *name, umode_t mode, struct dentry *parent,@@ -1009,7 +1009,7 @@ struct dentry *debugfs_create_u32_array(const char *name, umode_t mode,struct array_data *data =kmalloc (sizeof (*data),GFP_KERNEL );if (data ==NULL ) -return NULL ; +return ERR_PTR (-ENOMEM );
Quoted 7 lines
fs/debugfs/file.c struct dentry *debugfs_create_u32_array(const char *name, umode_t mode, · line 1015
Quoted 2 lines
fs/debugfs/file.c +0
-0data->array = array; data->elements = elements;There is only one caller of this function in the kernel now, and it does not even care about the return value at all, so we should just remove the return value entirely as that's the easiest and best thing to do here.
Interesting argument: since this is a helper/library function, and therefore potentially used in the future by others, it seems to me that consistency with the other functions and providing error feedback would be important.
Quoted 2 lines
I was going to start doing this slowly over time, but as you are touching the function now, might as well do it here :)
Are you saying the plan is to make all these helpers return void?
Cheers,
Ronald
Greg Kroah-Hartman
maintainerRe: [PATCH 2/2] debugfs: make return value of all debugfs helpers consistent
Quoted 44 lines · and then you die
Hi Greg,
Quoted 32 lines · Greg Kroah-Hartman
Quoted 31 lines · Ronald Tschalär
Since commit
ff9fb72bc077("debugfs: return error values, not NULL") almost all the debugfs helpers have stopped returning NULL. The lone holdeout wasdebugfs_create_u32_array(). So fix that.Signed-off-by Ronald Tschalär <[email protected]>--- fs/debugfs/file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)fs/debugfs/file.c +3
-3@@ -999,8 +999,8 @@ static const struct file_operations u32_array_fops = {* Once array is created its size can not be changed. * * The function returns a pointer to dentry on success. If an error occurs, -* %ERR_PTR(-ERROR) or NULL will be returned. If debugfs is not enabled in -* the kernel, the value %ERR_PTR(-ENODEV) will be returned. +* %ERR_PTR(-ERROR) will be returned. If debugfs is not enabled in the kernel, +* the value %ERR_PTR(-ENODEV) will be returned. */ struct dentry *debugfs_create_u32_array(const char *name, umode_t mode, struct dentry *parent,@@ -1009,7 +1009,7 @@ struct dentry *debugfs_create_u32_array(const char *name, umode_t mode,struct array_data *data =kmalloc (sizeof (*data),GFP_KERNEL );if (data ==NULL ) -return NULL ; +return ERR_PTR (-ENOMEM );Quoted 7 lines
fs/debugfs/file.c struct dentry *debugfs_create_u32_array(const char *name, umode_t mode, · line 1015
Quoted 2 lines
fs/debugfs/file.c +0
-0data->array = array; data->elements = elements;There is only one caller of this function in the kernel now, and it does not even care about the return value at all, so we should just remove the return value entirely as that's the easiest and best thing to do here.
Quoted 4 lines
Interesting argument: since this is a helper/library function, and therefore potentially used in the future by others, it seems to me that consistency with the other functions and providing error feedback would be important.
Not if you never actually use the return value for anything :)
Quoted 4 lines
Quoted 2 lines
I was going to start doing this slowly over time, but as you are touching the function now, might as well do it here :)
Are you saying the plan is to make all these helpers return void?
Yes, no caller should do anything "different" based on a return value of a debugfs call. Note, sometimes you do want to save off dentries for some files that you later remove, but that's it.
thanks,
greg k-h
Greg Kroah-Hartman
maintainerPATCH 1/1 debugfs: make debugfs_create_u32_array() return void
The single user of debugfs_create_u32_array() does not care about the return value of it, so make it return void as there is no need to do anything with the return value.
--- Documentation/filesystems/debugfs.txt | 2 +- fs/debugfs/file.c | 13 ++++--------- include/linux/debugfs.h | 12 +++++------- 3 files changed, 10 insertions(+), 17 deletions(-)
Documentation/filesystems/debugfs.txt +1 -1
@@ -168,7 +168,7 @@ byte offsets over a base for the register block. If you want to dump an u32 array in debugfs, you can create file with: - struct dentry *debugfs_create_u32_array(const char *name, umode_t mode, + void debugfs_create_u32_array(const char *name, umode_t mode, struct dentry *parent, u32 *array, u32 elements);
fs/debugfs/file.c +4 -9
@@ -1004,24 +1004,19 @@ static const struct file_operations u32_array_fops = {* @array as data. If the @mode variable is so set it can be read from. * Writing is not supported. Seek within the file is also not supported. * Once array is created its size can not be changed. -* -* The function returns a pointer to dentry on success. If debugfs is not -* enabled in the kernel, the value -%ENODEV will be returned. */ -struct dentry *debugfs_create_u32_array (const char *name,umode_t mode, -struct dentry *parent, -u32 *array,u32 elements) +void debugfs_create_u32_array (const char *name,umode_t mode, +struct dentry *parent,u32 *array,u32 elements) {struct array_data *data =kmalloc (sizeof (*data),GFP_KERNEL );if (data ==NULL ) -return NULL ; +return ; data->array = array; data->elements = elements; -return debugfs_create_file_unsafe (name, mode, parent, data, - &u32_array_fops); +debugfs_create_file_unsafe (name, mode, parent, data, &u32_array_fops); }EXPORT_SYMBOL_GPL (debugfs_create_u32_array);
include/linux/debugfs.h +5 -7
@@ -133,9 +133,8 @@ struct dentry *debugfs_create_regset32(const char *name, umode_t mode,void debugfs_print_regs32 (struct seq_file *s,const struct debugfs_reg32 *regs,int nregs,void __iomem *base,char *prefix); -struct dentry *debugfs_create_u32_array (const char *name,umode_t mode, -struct dentry *parent, -u32 *array,u32 elements); +void debugfs_create_u32_array (const char *name,umode_t mode, +struct dentry *parent,u32 *array,u32 elements); struct dentry *debugfs_create_devm_seqfile(struct device *dev, const char *name, struct dentry *parent,
@@ -353,11 +352,10 @@ static inline bool debugfs_initialized(void)return false; } -static inline struct dentry *debugfs_create_u32_array (const char *name,umode_t mode, -struct dentry *parent, -u32 *array,u32 elements) +static inline void debugfs_create_u32_array (const char *name,umode_t mode, +struct dentry *parent,u32 *array, +u32 elements) { -return ERR_PTR (-ENODEV ); } static inline struct dentry *debugfs_create_devm_seqfile(struct device *dev,
Signature · 1 line
2.21.0