Whamcloud - gitweb
LU-9679 lustre: avoid cast of file->private_data
[fs/lustre-release.git] / lustre / osc / lproc_osc.c
index 2d15ebb..387ec7d 100644 (file)
@@ -210,9 +210,11 @@ static ssize_t osc_cached_mb_seq_write(struct file *file,
                                       const char __user *buffer,
                                       size_t count, loff_t *off)
 {
-       struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
+       struct seq_file *m = file->private_data;
+       struct obd_device *dev = m->private;
        struct client_obd *cli = &dev->u.cli;
-       __s64 pages_number;
+       u64 pages_number;
+       const char *tmp;
        long rc;
        char kernbuf[128];
 
@@ -223,17 +225,13 @@ static ssize_t osc_cached_mb_seq_write(struct file *file,
                return -EFAULT;
        kernbuf[count] = 0;
 
-       buffer += lprocfs_find_named_value(kernbuf, "used_mb:", &count) -
-                 kernbuf;
-       rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
-       if (rc)
+       tmp = lprocfs_find_named_value(kernbuf, "used_mb:", &count);
+       rc = sysfs_memparse(tmp, count, &pages_number, "MiB");
+       if (rc < 0)
                return rc;
 
        pages_number >>= PAGE_SHIFT;
 
-       if (pages_number < 0)
-               return -ERANGE;
-
        rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
        if (rc > 0) {
                struct lu_env *env;
@@ -283,19 +281,26 @@ static ssize_t osc_cur_grant_bytes_seq_write(struct file *file,
                                             const char __user *buffer,
                                             size_t count, loff_t *off)
 {
-       struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
+       struct seq_file *m = file->private_data;
+       struct obd_device *obd = m->private;
        struct client_obd *cli = &obd->u.cli;
-       s64 val;
+       char kernbuf[22] = "";
+       u64 val;
        int rc;
 
        if (obd == NULL)
                return 0;
 
-       rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
-       if (rc)
+       if (count >= sizeof(kernbuf))
+               return -EINVAL;
+
+       if (copy_from_user(kernbuf, buffer, count))
+               return -EFAULT;
+       kernbuf[count] = 0;
+
+       rc = sysfs_memparse(kernbuf, count, &val, "MiB");
+       if (rc < 0)
                return rc;
-       if (val < 0)
-               return val;
 
        /* this is only for shrinking grant */
        spin_lock(&cli->cl_loi_list_lock);
@@ -421,7 +426,8 @@ static ssize_t osc_checksum_type_seq_write(struct file *file,
                                           const char __user *buffer,
                                           size_t count, loff_t *off)
 {
-       struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
+       struct seq_file *m = file->private_data;
+       struct obd_device *obd = m->private;
        int i;
        DECLARE_CKSUM_NAME;
        char kernbuf[10];
@@ -702,9 +708,9 @@ static ssize_t grant_shrink_show(struct kobject *kobj, struct attribute *attr,
 
        LPROCFS_CLIMP_CHECK(obd);
        imp = obd->u.cli.cl_import;
-       len = snprintf(buf, PAGE_SIZE, "%d\n",
-                      !imp->imp_grant_shrink_disabled &&
-                      OCD_HAS_FLAG(&imp->imp_connect_data, GRANT_SHRINK));
+       len = scnprintf(buf, PAGE_SIZE, "%d\n",
+                       !imp->imp_grant_shrink_disabled &&
+                       OCD_HAS_FLAG(&imp->imp_connect_data, GRANT_SHRINK));
        LPROCFS_CLIMP_EXIT(obd);
 
        return len;