Whamcloud - gitweb
LU-5435 libcfs: copy out ioctl inline buffer
[fs/lustre-release.git] / lustre / obdclass / linux / linux-module.c
index 04ec8c5..8b114d2 100644 (file)
 int proc_version;
 
 /* buffer MUST be at least the size of obd_ioctl_hdr */
-int obd_ioctl_getdata(char **buf, int *len, void *arg)
+int obd_ioctl_getdata(char **buf, int *len, void __user *arg)
 {
-        struct obd_ioctl_hdr hdr;
-        struct obd_ioctl_data *data;
-        int err;
-        int offset = 0;
-        ENTRY;
+       struct obd_ioctl_hdr hdr;
+       struct obd_ioctl_data *data;
+       int offset = 0;
+       ENTRY;
 
-       err = copy_from_user(&hdr, (void *)arg, sizeof(hdr));
-        if ( err )
-                RETURN(err);
+       if (copy_from_user(&hdr, arg, sizeof(hdr)))
+               RETURN(-EFAULT);
 
         if (hdr.ioc_version != OBD_IOCTL_VERSION) {
                 CERROR("Version mismatch kernel (%x) vs application (%x)\n",
@@ -120,11 +118,10 @@ int obd_ioctl_getdata(char **buf, int *len, void *arg)
         *len = hdr.ioc_len;
         data = (struct obd_ioctl_data *)*buf;
 
-       err = copy_from_user(*buf, (void *)arg, hdr.ioc_len);
-        if ( err ) {
-                OBD_FREE_LARGE(*buf, hdr.ioc_len);
-                RETURN(err);
-        }
+       if (copy_from_user(*buf, arg, hdr.ioc_len)) {
+               OBD_FREE_LARGE(*buf, hdr.ioc_len);
+               RETURN(-EFAULT);
+       }
 
         if (obd_ioctl_is_invalid(data)) {
                 CERROR("ioctl not correctly formatted\n");
@@ -147,23 +144,20 @@ int obd_ioctl_getdata(char **buf, int *len, void *arg)
                 offset += cfs_size_round(data->ioc_inllen3);
         }
 
-        if (data->ioc_inllen4) {
-                data->ioc_inlbuf4 = &data->ioc_bulk[0] + offset;
-        }
+       if (data->ioc_inllen4)
+               data->ioc_inlbuf4 = &data->ioc_bulk[0] + offset;
 
-        EXIT;
-        return 0;
+       RETURN(0);
 }
 EXPORT_SYMBOL(obd_ioctl_getdata);
 
-int obd_ioctl_popdata(void *arg, void *data, int len)
+int obd_ioctl_popdata(void __user *arg, void *data, int len)
 {
        int err;
+       ENTRY;
 
-       err = copy_to_user(arg, data, len);
-       if (err)
-               err = -EFAULT;
-       return err;
+       err = copy_to_user(arg, data, len) ? -EFAULT : 0;
+       RETURN(err);
 }
 EXPORT_SYMBOL(obd_ioctl_popdata);
 
@@ -412,17 +406,35 @@ struct file_operations obd_device_list_fops = {
 
 int class_procfs_init(void)
 {
+       struct proc_dir_entry *entry;
        int rc;
        ENTRY;
 
        obd_sysctl_init();
-       proc_lustre_root = lprocfs_seq_register("fs/lustre", NULL,
-                                               lprocfs_base, NULL);
+
+       entry = lprocfs_seq_register("fs/lustre", NULL, lprocfs_base, NULL);
+       if (IS_ERR(entry)) {
+               rc = PTR_ERR(entry);
+               CERROR("cannot create '/proc/fs/lustre': rc = %d\n", rc);
+               RETURN(rc);
+       }
+
+       proc_lustre_root = entry;
+
        rc = lprocfs_seq_create(proc_lustre_root, "devices", 0444,
                                &obd_device_list_fops, NULL);
-       if (rc)
-               CERROR("error adding /proc/fs/lustre/devices file\n");
-       RETURN(0);
+       if (rc < 0) {
+               CERROR("cannot create '/proc/fs/lustre/devices': rc = %d\n",
+                      rc);
+               GOTO(out_proc, rc);
+       }
+
+       RETURN(rc);
+
+out_proc:
+       lprocfs_remove(&proc_lustre_root);
+
+       RETURN(rc);
 }
 
 int class_procfs_clean(void)