]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
staging: lustre: Use kstrtouint_from_user in ldlm_rw_uint
authorMathias Rav <mathiasrav@gmail.com>
Fri, 19 May 2017 02:49:21 +0000 (22:49 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 3 Jun 2017 08:32:41 +0000 (17:32 +0900)
Clean up the helper functions used to implement "dump_granted_max" in
debugfs.

Replace the lprocfs_rd_uint() and lprocfs_wr_uint() generic callbacks
with a simpler, more direct implementation of ldlm_rw_uint_fops.

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.

Signed-off-by: Mathias Rav <mathiasrav@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c

index 633f65b078ebbe6f1c4674d7ed5e0884a6f977cc..1c8b0ea10c326da27d6b850584a65cd71025f74f 100644 (file)
@@ -78,7 +78,25 @@ lprocfs_wr_dump_ns(struct file *file, const char __user *buffer,
 
 LPROC_SEQ_FOPS_WR_ONLY(ldlm, dump_ns);
 
-LPROC_SEQ_FOPS_RW_TYPE(ldlm_rw, uint);
+static int ldlm_rw_uint_seq_show(struct seq_file *m, void *v)
+{
+       seq_printf(m, "%u\n", *(unsigned int *)m->private);
+       return 0;
+}
+
+static ssize_t
+ldlm_rw_uint_seq_write(struct file *file, const char __user *buffer,
+                      size_t count, loff_t *off)
+{
+       struct seq_file *seq = file->private_data;
+
+       if (count == 0)
+               return 0;
+       return kstrtouint_from_user(buffer, count, 0,
+                                   (unsigned int *)seq->private);
+}
+
+LPROC_SEQ_FOPS(ldlm_rw_uint);
 
 static struct lprocfs_vars ldlm_debugfs_list[] = {
        { "dump_namespaces", &ldlm_dump_ns_fops, NULL, 0222 },
index 1ec6e3767d81215993f4a0de73cd11e83e71b3b3..b42c4092bf220f19e01314c7103c020b5e73ba55 100644 (file)
@@ -389,40 +389,6 @@ out:
 EXPORT_SYMBOL_GPL(ldebugfs_register);
 
 /* Generic callbacks */
-int lprocfs_rd_uint(struct seq_file *m, void *data)
-{
-       seq_printf(m, "%u\n", *(unsigned int *)data);
-       return 0;
-}
-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;
-}
-EXPORT_SYMBOL(lprocfs_wr_uint);
-
 static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
                         char *buf)
 {