Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1635876 > unrolled thread
| Started by | Mathias Rav <mathiasrav@gmail.com> |
|---|---|
| First post | 2017-05-04 18:20 +0200 |
| Last post | 2017-05-04 18:20 +0200 |
| Articles | 2 — 1 participant |
Back to article view | Back to linux.kernel
[PATCH 0/2] staging: lustre: lprocfs: Fix coding style issues Mathias Rav <mathiasrav@gmail.com> - 2017-05-04 18:20 +0200
[PATCH 1/2] staging: lustre: lprocfs: Use kstrtouint_from_user Mathias Rav <mathiasrav@gmail.com> - 2017-05-04 18:20 +0200
| From | Mathias Rav <mathiasrav@gmail.com> |
|---|---|
| Date | 2017-05-04 18:20 +0200 |
| Subject | [PATCH 0/2] staging: lustre: lprocfs: Fix coding style issues |
| Message-ID | <tDrDZ-5WC-25@gated-at.bofh.it> |
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(-)
[toc] | [next] | [standalone]
| From | Mathias Rav <mathiasrav@gmail.com> |
|---|---|
| Date | 2017-05-04 18:20 +0200 |
| Subject | [PATCH 1/2] staging: lustre: lprocfs: Use kstrtouint_from_user |
| Message-ID | <tDrDZ-5WC-27@gated-at.bofh.it> |
| In reply to | #1635876 |
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.
Signed-off-by: Mathias Rav <mathiasrav@gmail.com>
---
.../lustre/lustre/obdclass/lprocfs_status.c | 22 +---------------------
1 file changed, 1 insertion(+), 21 deletions(-)
diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
index 1ec6e3767d81..338ce34d6514 100644
--- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
+++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
@@ -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);
--
2.12.2
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web