Whamcloud - gitweb
LU-175 don't allocate kernbuf on the stack
authorBrian J. Murrell <brian@whamcloud.com>
Tue, 5 Apr 2011 05:16:51 +0000 (01:16 -0400)
committerOleg Drokin <green@whamcloud.com>
Fri, 22 Apr 2011 17:53:24 +0000 (10:53 -0700)
On i686, allocating a kernbuf of 1K on the stack causes a compiler
error:
lustre/mdt/mdt_lproc.c:255: error: the frame size of 1040 bytes is
                                   larger than 1024 bytes

Signed-off-by: Brian J. Murrell <brian@whamcloud.com>
Change-Id: I91e4fc39fa6bdc6b6d7937263520b1dfce8c4746
Reviewed-on: http://review.whamcloud.com/401
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: Hudson
Reviewed-by: Lai Siyao <laisiyao@whamcloud.com>
Reviewed-by: Johann Lombardi <johann@whamcloud.com>
lustre/mdt/mdt_lproc.c

index c2929c6..8fa813d 100644 (file)
@@ -225,17 +225,18 @@ static int lprocfs_wr_identity_upcall(struct file *file, const char *buffer,
         struct obd_device *obd = data;
         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
         struct upcall_cache *hash = mdt->mdt_identity_cache;
-        char kernbuf[UC_CACHE_UPCALL_MAXPATH] = { '\0' };
+        int rc;
+        char *kernbuf;
 
         if (count >= UC_CACHE_UPCALL_MAXPATH) {
                 CERROR("%s: identity upcall too long\n", obd->obd_name);
                 return -EINVAL;
         }
-
-        if (cfs_copy_from_user(kernbuf, buffer,
-                               min_t(unsigned long, count,
-                                     UC_CACHE_UPCALL_MAXPATH - 1)))
-                return -EFAULT;
+        OBD_ALLOC(kernbuf, count + 1);
+        if (kernbuf == NULL)
+                GOTO(failed, rc = -ENOMEM);
+        if (cfs_copy_from_user(kernbuf, buffer, count))
+                GOTO(failed, rc = -EFAULT);
 
         /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
         cfs_write_lock(&hash->uc_upcall_rwlock);
@@ -251,7 +252,13 @@ static int lprocfs_wr_identity_upcall(struct file *file, const char *buffer,
                       "cause unexpected \"EACCESS\"\n", obd->obd_name);
 
         CWARN("%s: identity upcall set to %s\n", obd->obd_name, hash->uc_upcall);
-        return count;
+        OBD_FREE(kernbuf, count + 1);
+        RETURN(count);
+
+ failed:
+        if (kernbuf)
+                OBD_FREE(kernbuf, count + 1);
+        RETURN(rc);
 }
 
 static int lprocfs_wr_identity_flush(struct file *file, const char *buffer,