mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drivers: staging: lustre: replace variable length array by dynamic allocation
@ 2017-05-23 19:32 Raphaël Beamonte
  2017-05-23 19:38 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Raphaël Beamonte @ 2017-05-23 19:32 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: Raphaël Beamonte, Andreas Dilger, James Simmons,
	Greg Kroah-Hartman, John L. Hammond, Hongchao Zhang,
	Aditya Pandit, Sebastien Buisson, Fan Yong, lustre-devel, devel,
	linux-kernel

Fixes the following sparse warnings:

drivers/staging/lustre/lustre/llite/xattr.c:89:62: warning: Variable
length array is used.
drivers/staging/lustre/lustre/llite/xattr.c:366:62: warning: Variable
length array is used.

Signed-off-by: Raphaël Beamonte <raphael.beamonte@gmail.com>
---
 drivers/staging/lustre/lustre/llite/xattr.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/lustre/lustre/llite/xattr.c b/drivers/staging/lustre/lustre/llite/xattr.c
index 6187bffec8c4..ccfc728d8ec0 100644
--- a/drivers/staging/lustre/lustre/llite/xattr.c
+++ b/drivers/staging/lustre/lustre/llite/xattr.c
@@ -86,7 +86,7 @@ ll_xattr_set_common(const struct xattr_handler *handler,
 		    const char *name, const void *value, size_t size,
 		    int flags)
 {
-	char fullname[strlen(handler->prefix) + strlen(name) + 1];
+	char *fullname;
 	struct ll_sb_info *sbi = ll_i2sbi(inode);
 	struct ptlrpc_request *req = NULL;
 	const char *pv = value;
@@ -140,10 +140,18 @@ ll_xattr_set_common(const struct xattr_handler *handler,
 			return -EPERM;
 	}
 
+	fullname = kmalloc(strlen(handler->prefix) + strlen(name) + 1,
+			   GFP_KERNEL);
+	if (!fullname)
+		return -ENOMEM;
+
 	sprintf(fullname, "%s%s\n", handler->prefix, name);
 	rc = md_setxattr(sbi->ll_md_exp, ll_inode2fid(inode),
 			 valid, fullname, pv, size, 0, flags,
 			 ll_i2suppgid(inode), &req);
+
+	kfree(fullname);
+
 	if (rc) {
 		if (rc == -EOPNOTSUPP && handler->flags == XATTR_USER_T) {
 			LCONSOLE_INFO("Disabling user_xattr feature because it is not supported on the server\n");
@@ -363,7 +371,7 @@ static int ll_xattr_get_common(const struct xattr_handler *handler,
 			       struct dentry *dentry, struct inode *inode,
 			       const char *name, void *buffer, size_t size)
 {
-	char fullname[strlen(handler->prefix) + strlen(name) + 1];
+	char *fullname;
 	struct ll_sb_info *sbi = ll_i2sbi(inode);
 #ifdef CONFIG_FS_POSIX_ACL
 	struct ll_inode_info *lli = ll_i2info(inode);
@@ -410,9 +418,17 @@ static int ll_xattr_get_common(const struct xattr_handler *handler,
 	if (handler->flags == XATTR_ACL_DEFAULT_T && !S_ISDIR(inode->i_mode))
 		return -ENODATA;
 #endif
+	fullname = kmalloc(strlen(handler->prefix) + strlen(name) + 1,
+			   GFP_KERNEL);
+	if (!fullname)
+		return -ENOMEM;
+
 	sprintf(fullname, "%s%s\n", handler->prefix, name);
-	return ll_xattr_list(inode, fullname, handler->flags, buffer, size,
-			     OBD_MD_FLXATTR);
+	rc = ll_xattr_list(inode, fullname, handler->flags, buffer, size,
+			   OBD_MD_FLXATTR);
+
+	kfree(fullname);
+	return rc;
 }
 
 static ssize_t ll_getxattr_lov(struct inode *inode, void *buf, size_t buf_size)
-- 
2.11.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-05-27 18:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-23 19:32 [PATCH] drivers: staging: lustre: replace variable length array by dynamic allocation Raphaël Beamonte
2017-05-23 19:38 ` Greg Kroah-Hartman
2017-05-27 18:23   ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome