staging: lustre: lprocfs: Fix coding style issues
cover staging: lustre: lprocfs: Fix coding style issues
This patchset fixes two style issues in lprocfs_status.c related to simple_strtoul and seq_printf (reported by checkpatch).
There's a slight change in lustre debugfs write semantics: Using kstrtox causes EINVAL when the written number is followed by other (garbage) characters, whereas previously the garbage would be ignored and such a write would succeed.
Mathias Rav (2):
staging: lustre: lprocfs: Use kstrtouint_from_user
staging: lustre: lprocfs: Use seq_puts
.../lustre/lustre/obdclass/lprocfs_status.c | 42 ++++++--------------- 1 file changed, 11 insertions(+), 31 deletions(-)
PATCH 1/2 staging: lustre: lprocfs: Use kstrtouint_from_user
Prefer kstrtouint_from_user to copy_from_user+simple_strtoul.
The helper function lprocfs_wr_uint() is only used to implement "dump_granted_max" in debugfs.
Note the slight change in semantics: The previous implementation using simple_strtoul allows garbage after the number, whereas kstrtox only allows a trailing line break. The previous implementation allowed a write of zero bytes whereas kstrtox will return -EINVAL. Since this only affects a single debugfs endpoint, this should be a permissible slight change of semantics in exchange for 18 fewer lines of code.
--- .../lustre/lustre/obdclass/lprocfs_status.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-)
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +1 -21
@@ -399,27 +399,7 @@ EXPORT_SYMBOL(lprocfs_rd_uint);int lprocfs_wr_uint (struct file *file,const char __user *buffer,unsigned long count,void *data) { -unsigned *p = data; -char dummy[MAX_STRING_SIZE +1 ], *end; -unsigned long tmp; - -if (count >=sizeof (dummy)) -return -EINVAL ; - -if (count ==0 ) -return 0 ; - -if (copy_from_user (dummy, buffer, count)) -return -EFAULT ; - - dummy[count] ='\0' ; - - tmp =simple_strtoul (dummy, &end,0 ); -if (dummy == end) -return -EINVAL ; - - *p = (unsigned int )tmp; -return count; +return kstrtouint_from_user (buffer, count,0 , (unsigned int *)data); }EXPORT_SYMBOL (lprocfs_wr_uint);
Signature · 1 line
2.12.2
PATCH 2/2 staging: lustre: lprocfs: Use seq_puts
Replace all occurrences of seq_printf with no formatting directives in lprocfs_status.c with seq_puts.
Reported by checkpatch.pl: "WARNING: Prefer seq_puts to seq_printf".
--- .../staging/lustre/lustre/obdclass/lprocfs_status.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +10 -10
@@ -716,7 +716,7 @@ static int obd_import_flags2str(struct obd_import *imp, struct seq_file *m)bool first = true;if (imp->imp_obd->obd_no_recov) { -seq_printf (m,"no_recov" ); +seq_puts (m,"no_recov" ); first = false; }
@@ -782,15 +782,15 @@ int lprocfs_rd_import(struct seq_file *m, void *data) imp->imp_connect_data.ocd_instance);obd_connect_seq_flags2str (m, imp->imp_connect_data.ocd_connect_flags,", " ); -seq_printf (m," ]\n" ); +seq_puts (m," ]\n" );obd_connect_data_seqprint (m, ocd); -seq_printf (m," import_flags: [ " ); +seq_puts (m," import_flags: [ " );obd_import_flags2str (imp, m); -seq_printf (m, -" ]\n" -" connection:\n" -" failover_nids: [ " ); +seq_puts (m, +" ]\n" +" connection:\n" +" failover_nids: [ " );spin_lock (&imp->imp_lock); j =0 ;list_for_each_entry (conn, &imp->imp_conn_list, oic_item) {
@@ -923,7 +923,7 @@ int lprocfs_rd_state(struct seq_file *m, void *data)seq_printf (m,"current_state: %s\n" ,ptlrpc_import_state_name (imp->imp_state)); -seq_printf (m,"state_history:\n" ); +seq_puts (m,"state_history:\n" ); k = imp->imp_state_hist_idx;for (j =0 ; j <IMP_STATE_HIST_LEN ; j++) { struct import_state_hist *ish =
@@ -945,7 +945,7 @@ int lprocfs_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at)for (i =0 ; i <AT_BINS ; i++)seq_printf (m,"%3u " , at->at_hist[i]); -seq_printf (m,"\n" ); +seq_puts (m,"\n" );return 0 ; }EXPORT_SYMBOL (lprocfs_at_hist_helper);
@@ -1013,7 +1013,7 @@ int lprocfs_rd_connect_flags(struct seq_file *m, void *data) flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;seq_printf (m,"flags=%#llx\n" , flags);obd_connect_seq_flags2str (m, flags,"\n" ); -seq_printf (m,"\n" ); +seq_puts (m,"\n" );up_read (&obd->u.cli.cl_sem);return 0 ; }
Signature · 1 line
2.12.2
Greg Kroah-Hartman
maintainerRe: [PATCH 1/2] staging: lustre: lprocfs: Use kstrtouint_from_user
In reply to Mathias RavQuoted 37 lines · Mathias Rav
Prefer
kstrtouint_from_userto copy_from_user+simple_strtoul.The helper function
lprocfs_wr_uint()is only used to implement "dump_granted_max" in debugfs.Note the slight change in semantics: The previous implementation using
simple_strtoulallows garbage after the number, whereas kstrtox only allows a trailing line break. The previous implementation allowed a write of zero bytes whereas kstrtox will return-EINVAL. Since this only affects a single debugfs endpoint, this should be a permissible slight change of semantics in exchange for 18 fewer lines of code.Signed-off-by Mathias Rav <[email protected]>--- .../lustre/lustre/obdclass/lprocfs_status.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-)drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +0
-12@@ -399,27 +399,7 @@ EXPORT_SYMBOL(lprocfs_rd_uint);int lprocfs_wr_uint (struct file *file,const char __user *buffer,unsigned long count,void *data) { -unsigned *p = data; -char dummy[MAX_STRING_SIZE +1 ], *end; -unsigned long tmp; - -if (count >=sizeof (dummy)) -return -EINVAL ; - -if (count ==0 ) -return 0 ; - -if (copy_from_user (dummy, buffer, count)) -return -EFAULT ;
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c EXPORT_SYMBOL(lprocfs_rd_uint); · line 402
Quoted 10 lines
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +1
-9- - dummy[count] ='\0' ; - - tmp =simple_strtoul (dummy, &end,0 ); -if (dummy == end) -return -EINVAL ; - - *p = (unsigned int )tmp; -return count; +return kstrtouint_from_user (buffer, count,0 , (unsigned int *)data);
Why not just delete this whole function and have the callers make this call instead? No need for unneeded wrapper functions of core kernel calls.
thanks,
greg k-h
Re: [PATCH 1/2] staging: lustre: lprocfs: Use kstrtouint_from_user
Quoted 45 lines · Greg Kroah-Hartman
Quoted 43 lines · Mathias Rav
Prefer
kstrtouint_from_userto copy_from_user+simple_strtoul.The helper function
lprocfs_wr_uint()is only used to implement "dump_granted_max" in debugfs.Note the slight change in semantics: The previous implementation using
simple_strtoulallows garbage after the number, whereas kstrtox only allows a trailing line break. The previous implementation allowed a write of zero bytes whereas kstrtox will return-EINVAL. Since this only affects a single debugfs endpoint, this should be a permissible slight change of semantics in exchange for 18 fewer lines of code.Signed-off-by Mathias Rav <[email protected]>---
.../lustre/lustre/obdclass/lprocfs_status.c| 22 +---------------------1 file changed, 1 insertion(+), 21 deletions(-)drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +0
-18@@ -399,27 +399,7 @@ EXPORT_SYMBOL(lprocfs_rd_uint);int lprocfs_wr_uint (struct file *file,const char __user *buffer,unsigned long count,void *data) { -unsigned *p = data; -char dummy[MAX_STRING_SIZE +1 ], *end; -unsigned long tmp; - -if (count >=sizeof (dummy)) -return -EINVAL ; - -if (count ==0 ) -return 0 ; - -if (copy_from_user (dummy, buffer, count)) -return -EFAULT ; - - dummy[count] ='\0' ; - - tmp =simple_strtoul (dummy, &end,0 ); -if (dummy == end) -return -EINVAL ;
Quoted 8 lines
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c EXPORT_SYMBOL(lprocfs_rd_uint); · line 402
Quoted 4 lines
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +1
-3- - *p = (unsigned int )tmp; -return count; +return kstrtouint_from_user (buffer, count,0 , (unsigned int *)data);Why not just delete this whole function and have the callers make this call instead? No need for unneeded wrapper functions of core kernel calls.
Even better, it looks like this function has no callers on the client and could just be deleted entirely.
Cheers, Andreas
--
Andreas Dilger
Lustre Principal Architect
Intel Corporation
Re: [PATCH 1/2] staging: lustre: lprocfs: Use kstrtouint_from_user
Quoted 55 lines · Andreas
Quoted 45 lines · Greg Kroah-Hartman
Quoted 43 lines · Mathias Rav
Prefer
kstrtouint_from_userto copy_from_user+simple_strtoul.The helper function
lprocfs_wr_uint()is only used to implement "dump_granted_max" in debugfs.Note the slight change in semantics: The previous implementation using
simple_strtoulallows garbage after the number, whereas kstrtox only allows a trailing line break. The previous implementation allowed a write of zero bytes whereas kstrtox will return-EINVAL. Since this only affects a single debugfs endpoint, this should be a permissible slight change of semantics in exchange for 18 fewer lines of code.Signed-off-by Mathias Rav <[email protected]>---
.../lustre/lustre/obdclass/lprocfs_status.c| 22 +---------------------1 file changed, 1 insertion(+), 21 deletions(-)drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +0
-18@@ -399,27 +399,7 @@ EXPORT_SYMBOL(lprocfs_rd_uint);int lprocfs_wr_uint (struct file *file,const char __user *buffer,unsigned long count,void *data) { -unsigned *p = data; -char dummy[MAX_STRING_SIZE +1 ], *end; -unsigned long tmp; - -if (count >=sizeof (dummy)) -return -EINVAL ; - -if (count ==0 ) -return 0 ; - -if (copy_from_user (dummy, buffer, count)) -return -EFAULT ; - - dummy[count] ='\0' ; - - tmp =simple_strtoul (dummy, &end,0 ); -if (dummy == end) -return -EINVAL ;Quoted 8 lines
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c EXPORT_SYMBOL(lprocfs_rd_uint); · line 402
Quoted 4 lines
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +1
-3- - *p = (unsigned int )tmp; -return count; +return kstrtouint_from_user (buffer, count,0 , (unsigned int *)data);Why not just delete this whole function and have the callers make this call instead? No need for unneeded wrapper functions of core kernel calls.
Quoted 2 lines
Even better, it looks like this function has no callers on the client and could just be deleted entirely.
No, the functions lprocfs_{rd,wr}_uint are used once through a macro:ldlm/ldlm_resource.c calls LPROC_SEQ_FOPS_RW_TYPE(ldlm_rw, uint) to define ldlm_rw_uint_seq_{show,write}, which then calls lprocfs_{rd,wr}_uint which in turn call seq_printf/kstrtouint_from_user.
It seems like much indirection for almost no gain besides hiding access to ((seq_file *) file->private_data)->private in a macro.
If you agree, I will prepare a patch that switches ldlm_resource to using the LPROC_SEQ_FOPS macro directly, which allows us to remove two trivial wrappers.
/Mathias
Re: [PATCH 1/2] staging: lustre: lprocfs: Use kstrtouint_from_user
Quoted 67 lines · Mathias Rav
Quoted 55 lines · Andreas
Quoted 45 lines · Greg Kroah-Hartman
Quoted 43 lines · Mathias Rav
Prefer
kstrtouint_from_userto copy_from_user+simple_strtoul.The helper function
lprocfs_wr_uint()is only used to implement "dump_granted_max" in debugfs.Note the slight change in semantics: The previous implementation using
simple_strtoulallows garbage after the number, whereas kstrtox only allows a trailing line break. The previous implementation allowed a write of zero bytes whereas kstrtox will return-EINVAL. Since this only affects a single debugfs endpoint, this should be a permissible slight change of semantics in exchange for 18 fewer lines of code.Signed-off-by Mathias Rav <[email protected]>---
.../lustre/lustre/obdclass/lprocfs_status.c| 22 +---------------------1 file changed, 1 insertion(+), 21 deletions(-)drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +0
-18@@ -399,27 +399,7 @@ EXPORT_SYMBOL(lprocfs_rd_uint);int lprocfs_wr_uint (struct file *file,const char __user *buffer,unsigned long count,void *data) { -unsigned *p = data; -char dummy[MAX_STRING_SIZE +1 ], *end; -unsigned long tmp; - -if (count >=sizeof (dummy)) -return -EINVAL ; - -if (count ==0 ) -return 0 ; - -if (copy_from_user (dummy, buffer, count)) -return -EFAULT ; - - dummy[count] ='\0' ; - - tmp =simple_strtoul (dummy, &end,0 ); -if (dummy == end) -return -EINVAL ;Quoted 8 lines
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c EXPORT_SYMBOL(lprocfs_rd_uint); · line 402
Quoted 4 lines
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +1
-3- - *p = (unsigned int )tmp; -return count; +return kstrtouint_from_user (buffer, count,0 , (unsigned int *)data);Why not just delete this whole function and have the callers make this call instead? No need for unneeded wrapper functions of core kernel calls.
Quoted 2 lines
Even better, it looks like this function has no callers on the client and could just be deleted entirely.
No, the functions lprocfs_{rd,wr}_uint are used once through a macro:
ldlm/ldlm_resource.ccallsLPROC_SEQ_FOPS_RW_TYPE(ldlm_rw, uint)to define ldlm_rw_uint_seq_{show,write}, which then calls lprocfs_{rd,wr}_uint which in turn call seq_printf/kstrtouint_from_user.
Quoted 6 lines
It seems like much indirection for almost no gain besides hiding access to ((
seq_file*) file->private_data)->private in a macro.If you agree, I will prepare a patch that switches
ldlm_resourceto using theLPROC_SEQ_FOPSmacro directly, which allows us to remove two trivial wrappers.
Please do.
Cheers, Andreas
--
Andreas Dilger
Lustre Principal Architect
Intel Corporation