staging: vc04_services: no need to check debugfs return values
Subsystems (2)
Greg Kroah-Hartman
maintainerPATCH 1/6 staging: vc04_services: no need to check debugfs return values
When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this.
Clean up the vchiq_arm code by not caring about the value of debugfs calls. This ends up removing a number of lines of code that are not needed.
--- .../interface/vchiq_arm/vchiq_arm.c | 13 +--- .../interface/vchiq_arm/vchiq_debugfs.c | 72 +++---------------- .../interface/vchiq_arm/vchiq_debugfs.h | 4 +- 3 files changed, 15 insertions(+), 74 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +2 -11
@@ -2018,7 +2018,6 @@ vchiq_open(struct inode *inode, struct file *file)vchiq_log_info (vchiq_arm_log_level,"vchiq_open" );switch (dev) {case VCHIQ_MINOR : { -int ret;VCHIQ_STATE_T *state =vchiq_get_state ();VCHIQ_INSTANCE_T instance;
@@ -2035,11 +2034,7 @@ vchiq_open(struct inode *inode, struct file *file) instance->state = state; instance->pid = current->tgid; - ret =vchiq_debugfs_add_instance (instance); -if (ret !=0 ) { -kfree (instance); -return ret; - } +vchiq_debugfs_add_instance (instance);sema_init (&instance->insert_event,0 );sema_init (&instance->remove_event,0 );
@@ -3630,9 +3625,7 @@ static int vchiq_probe(struct platform_device *pdev) goto failed_device_create;/* create debugfs entries */ - err =vchiq_debugfs_init (); -if (err !=0 ) - goto failed_debugfs_init; +vchiq_debugfs_init (); vchiq_log_info(vchiq_arm_log_level, "vchiq: initialised - version %d (min %d), device %d.%d",
@@ -3645,8 +3638,6 @@ static int vchiq_probe(struct platform_device *pdev)return 0 ; -failed_debugfs_init: -device_destroy (vchiq_class, vchiq_devid); failed_device_create:class_destroy (vchiq_class); failed_class_create:
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_debugfs.c +11 -61
132 lines not on this page · raw message
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_debugfs.h +2 -2
@@ -40,11 +40,11 @@ typedef struct vchiq_debugfs_node_struct {struct dentry *dentry; }VCHIQ_DEBUGFS_NODE_T ; -int vchiq_debugfs_init (void ); +void vchiq_debugfs_init (void );void vchiq_debugfs_deinit (void ); -int vchiq_debugfs_add_instance (VCHIQ_INSTANCE_T instance); +void vchiq_debugfs_add_instance (VCHIQ_INSTANCE_T instance);void vchiq_debugfs_remove_instance (VCHIQ_INSTANCE_T instance);
Signature · 1 line
2.17.1
Greg Kroah-Hartman
maintainerPATCH 2/6 staging: vc04_services: remove odd vchiq_debugfs_top() wrapper
vchiq_debugfs_top() is only a wrapper around a pointer to a dentry, so just use the dentry directly instead, making it a static variable instead of part of a static structure.
This also removes the pointless BUG_ON() when checking that dentry as no one should ever care if debugfs is working or not, and the kernel should really not panic over something as trivial as that.
--- .../interface/vchiq_arm/vchiq_debugfs.c | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_debugfs.c +8 -16
@@ -53,9 +53,6 @@/* Top-level debug info */ struct vchiq_debugfs_info { -/* Global 'vchiq' debugfs entry used by all instances */ -struct dentry *vchiq_cfg_dir; -/* one entry per client process */ struct dentry *clients;
@@ -65,6 +62,9 @@ struct vchiq_debugfs_info {static struct vchiq_debugfs_info debugfs_info; +/* Global 'vchiq' debugfs entry used by all instances */ +struct dentry *vchiq_dbg_dir; +/* Log category debugfs entries */ struct vchiq_debugfs_log_entry {const char *name;
@@ -82,7 +82,6 @@ static struct vchiq_debugfs_log_entry vchiq_debugfs_log_entries[] = {static int n_log_entries =ARRAY_SIZE (vchiq_debugfs_log_entries);static struct dentry *vchiq_clients_top (void ); -static struct dentry *vchiq_debugfs_top (void );static int debugfs_log_show (struct seq_file *f,void *offset) {
@@ -163,7 +162,7 @@ static void vchiq_debugfs_create_log_entries(struct dentry *top)struct dentry *dir;size_t i; - dir =debugfs_create_dir ("log" ,vchiq_debugfs_top ()); + dir =debugfs_create_dir ("log" , vchiq_dbg_dir); debugfs_info.log_categories = dir;for (i =0 ; i < n_log_entries; i++) {
@@ -286,17 +285,16 @@ void vchiq_debugfs_remove_instance(VCHIQ_INSTANCE_T instance)void vchiq_debugfs_init (void ) { - debugfs_info.vchiq_cfg_dir =debugfs_create_dir ("vchiq" ,NULL ); - debugfs_info.clients =debugfs_create_dir ("clients" , -vchiq_debugfs_top ()); + vchiq_dbg_dir =debugfs_create_dir ("vchiq" ,NULL ); + debugfs_info.clients =debugfs_create_dir ("clients" , vchiq_dbg_dir); -vchiq_debugfs_create_log_entries (vchiq_debugfs_top ()); +vchiq_debugfs_create_log_entries (vchiq_dbg_dir); }/* remove all the debugfs entries */ void vchiq_debugfs_deinit (void ) { -debugfs_remove_recursive (vchiq_debugfs_top ()); +debugfs_remove_recursive (vchiq_dbg_dir); }static struct dentry *vchiq_clients_top (void )
@@ -304,12 +302,6 @@ static struct dentry *vchiq_clients_top(void) return debugfs_info.clients; } -static struct dentry *vchiq_debugfs_top (void ) -{ -BUG_ON (debugfs_info.vchiq_cfg_dir ==NULL ); -return debugfs_info.vchiq_cfg_dir; -} -#else /* CONFIG_DEBUG_FS */ void vchiq_debugfs_init (void )
Signature · 1 line
2.17.1
Greg Kroah-Hartman
maintainerPATCH 3/6 staging: vc04_services: move client dbg directory into static variable
In reply to Greg Kroah-HartmanThis does not need to be part of a wrapper function, or in a structure, just properly reference it directly as a single variable.
The whole variable will be going away soon anyway, this is just a step toward that direction.
--- .../interface/vchiq_arm/vchiq_debugfs.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_debugfs.c +4 -14
@@ -53,17 +53,15 @@/* Top-level debug info */ struct vchiq_debugfs_info { -/* one entry per client process */ -struct dentry *clients; -/* log categories */ struct dentry *log_categories; };static struct vchiq_debugfs_info debugfs_info; -/* Global 'vchiq' debugfs entry used by all instances */ +/* Global 'vchiq' debugfs and clients entry used by all instances */ struct dentry *vchiq_dbg_dir; +struct dentry *vchiq_dbg_clients;/* Log category debugfs entries */ struct vchiq_debugfs_log_entry {
@@ -81,8 +79,6 @@ static struct vchiq_debugfs_log_entry vchiq_debugfs_log_entries[] = { };static int n_log_entries =ARRAY_SIZE (vchiq_debugfs_log_entries); -static struct dentry *vchiq_clients_top (void ); -static int debugfs_log_show (struct seq_file *f,void *offset) {int *levp = f->private;
@@ -262,12 +258,11 @@ void vchiq_debugfs_add_instance(VCHIQ_INSTANCE_T instance) {char pidstr[16 ];struct dentry *top; -struct dentry *clients =vchiq_clients_top ();snprintf (pidstr,sizeof (pidstr),"%d" ,vchiq_instance_get_pid (instance)); - top =debugfs_create_dir (pidstr, clients); + top =debugfs_create_dir (pidstr, vchiq_dbg_clients);debugfs_create_file ("use_count" ,0444 , top, instance, &debugfs_usecount_fops);
@@ -286,7 +281,7 @@ void vchiq_debugfs_remove_instance(VCHIQ_INSTANCE_T instance)void vchiq_debugfs_init (void ) { vchiq_dbg_dir =debugfs_create_dir ("vchiq" ,NULL ); - debugfs_info.clients =debugfs_create_dir ("clients" , vchiq_dbg_dir); + vchiq_dbg_clients =debugfs_create_dir ("clients" , vchiq_dbg_dir);vchiq_debugfs_create_log_entries (vchiq_dbg_dir); }
@@ -297,11 +292,6 @@ void vchiq_debugfs_deinit(void) debugfs_remove_recursive(vchiq_dbg_dir); } -static struct dentry *vchiq_clients_top (void ) -{ -return debugfs_info.clients; -} -#else /* CONFIG_DEBUG_FS */ void vchiq_debugfs_init (void )
Signature · 1 line
2.17.1
Greg Kroah-Hartman
maintainerPATCH 4/6 staging: vc04_services: remove struct vchiq_debugfs_info
In reply to Greg Kroah-HartmanThis structure, and the one static variable that was declared with it, were not being used for anything. The log_categories field was being set, but never used again. So just remove it entirely as it is not needed at all.
--- .../interface/vchiq_arm/vchiq_debugfs.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_debugfs.c +1 -13
@@ -51,14 +51,6 @@#define VCHIQ_LOG_INFO_STR "info"#define VCHIQ_LOG_TRACE_STR "trace" -/* Top-level debug info */ -struct vchiq_debugfs_info { -/* log categories */ -struct dentry *log_categories; -}; - -static struct vchiq_debugfs_info debugfs_info; -/* Global 'vchiq' debugfs and clients entry used by all instances */ struct dentry *vchiq_dbg_dir;struct dentry *vchiq_dbg_clients;
@@ -159,16 +151,12 @@ static void vchiq_debugfs_create_log_entries(struct dentry *top)size_t i; dir =debugfs_create_dir ("log" , vchiq_dbg_dir); - debugfs_info.log_categories = dir;for (i =0 ; i < n_log_entries; i++) {void *levp = (void *)vchiq_debugfs_log_entries[i].plevel; dir =debugfs_create_file (vchiq_debugfs_log_entries[i].name, -0644 , - debugfs_info.log_categories, - levp, - &debugfs_log_fops); +0644 , dir, levp, &debugfs_log_fops); vchiq_debugfs_log_entries[i].dir = dir; } }
Signature · 1 line
2.17.1
Greg Kroah-Hartman
maintainerPATCH 5/6 staging: vc04_services: vchiq_debugfs_log_entry can be a void *
In reply to Greg Kroah-HartmanThere's no need to set this to be int * when it is only used as a void *. This lets us remove the unneeded cast, and unneeded temporary variable the one place it is referenced in the code.
--- .../vc04_services/interface/vchiq_arm/vchiq_debugfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_debugfs.c +4 -4
@@ -58,7 +58,7 @@ struct dentry *vchiq_dbg_clients;/* Log category debugfs entries */ struct vchiq_debugfs_log_entry {const char *name; -int *plevel; +void *plevel;struct dentry *dir; };
@@ -153,10 +153,10 @@ static void vchiq_debugfs_create_log_entries(struct dentry *top) dir =debugfs_create_dir ("log" , vchiq_dbg_dir);for (i =0 ; i < n_log_entries; i++) { -void *levp = (void *)vchiq_debugfs_log_entries[i].plevel; - dir =debugfs_create_file (vchiq_debugfs_log_entries[i].name, -0644 , dir, levp, &debugfs_log_fops); +0644 , dir, + vchiq_debugfs_log_entries[i].plevel, + &debugfs_log_fops); vchiq_debugfs_log_entries[i].dir = dir; } }
Signature · 1 line
2.17.1
Greg Kroah-Hartman
maintainerPATCH 6/6 staging: vc04_services: no need to save the log debufs dentries
In reply to Greg Kroah-HartmanThe log entry dentries are only set, never referenced, so no need to keep them around. Remove the pointer from struct vchiq_debugfs_log_entry as it is not needed anymore and get rid of the separate vchiq_debugfs_create_log_entries() function as it is only used in one place.
--- .../interface/vchiq_arm/vchiq_debugfs.c | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_debugfs.c +10 -19
@@ -59,7 +59,6 @@ struct dentry *vchiq_dbg_clients;struct vchiq_debugfs_log_entry {const char *name;void *plevel; -struct dentry *dir; };static struct vchiq_debugfs_log_entry vchiq_debugfs_log_entries[] = {
@@ -144,23 +143,6 @@ static const struct file_operations debugfs_log_fops = { .release = single_release, }; -/* create an entry under <debugfs>/vchiq/log for each log category */ -static void vchiq_debugfs_create_log_entries (struct dentry *top) -{ -struct dentry *dir; -size_t i; - - dir =debugfs_create_dir ("log" , vchiq_dbg_dir); - -for (i =0 ; i < n_log_entries; i++) { - dir =debugfs_create_file (vchiq_debugfs_log_entries[i].name, -0644 , dir, - vchiq_debugfs_log_entries[i].plevel, - &debugfs_log_fops); - vchiq_debugfs_log_entries[i].dir = dir; - } -} -static int debugfs_usecount_show (struct seq_file *f,void *offset) {VCHIQ_INSTANCE_T instance = f->private;
@@ -268,10 +250,19 @@ void vchiq_debugfs_remove_instance(VCHIQ_INSTANCE_T instance)void vchiq_debugfs_init (void ) { +struct dentry *dir; +int i; + vchiq_dbg_dir =debugfs_create_dir ("vchiq" ,NULL ); vchiq_dbg_clients =debugfs_create_dir ("clients" , vchiq_dbg_dir); -vchiq_debugfs_create_log_entries (vchiq_dbg_dir); +/* create an entry under <debugfs>/vchiq/log for each log category */ + dir =debugfs_create_dir ("log" , vchiq_dbg_dir); + +for (i =0 ; i < n_log_entries; i++) +debugfs_create_file (vchiq_debugfs_log_entries[i].name,0644 , + dir, vchiq_debugfs_log_entries[i].plevel, + &debugfs_log_fops); }/* remove all the debugfs entries */
Signature · 1 line
2.17.1
PATCH 1/6 staging: vc04_services: no need to check debugfs return values
In reply to Greg Kroah-HartmanQuoted 7 lines · Greg Kroah-Hartman
When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this.
Clean up the
vchiq_armcode by not caring about the value of debugfs calls. This ends up removing a number of lines of code that are not needed.
This series is:
Thanks for the cleanups!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180601/d86564ed/attachment.sig>