From: Guru Das Srinagesh <gurooodas@gmail.com>
To: oleg.drokin@intel.com, andreas.dilger@intel.com,
jsimmons@infradead.org, gregkh@linuxfoundation.org
Cc: john.hammond@intel.com, lustre-devel@lists.lustre.org,
devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: [PATCH] staging: lustre: llite: Fix variable length array warning
Date: Thu, 4 May 2017 23:41:26 -0700 [thread overview]
Message-ID: <1493966486-6143-1-git-send-email-gurooodas@gmail.com> (raw)
Fix sparse warning "warning: Variable length array is used." by using
kmalloc_array to allocate the required amount of memory instead and
kfree to deallocate memory after use.
Signed-off-by: Guru Das Srinagesh <gurooodas@gmail.com>
---
drivers/staging/lustre/lustre/llite/xattr.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/lustre/lustre/llite/xattr.c b/drivers/staging/lustre/lustre/llite/xattr.c
index 6187bff..832ec6e 100644
--- a/drivers/staging/lustre/lustre/llite/xattr.c
+++ b/drivers/staging/lustre/lustre/llite/xattr.c
@@ -86,7 +86,8 @@ 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];
+ int fullname_len = strlen(handler->prefix) + strlen(name) + 1;
+ char *fullname = kmalloc_array(fullname_len, sizeof(char), GFP_KERNEL);
struct ll_sb_info *sbi = ll_i2sbi(inode);
struct ptlrpc_request *req = NULL;
const char *pv = value;
@@ -153,6 +154,9 @@ ll_xattr_set_common(const struct xattr_handler *handler,
}
ptlrpc_req_finished(req);
+
+ kfree(fullname);
+
return 0;
}
@@ -363,7 +367,8 @@ 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];
+ int fullname_len = strlen(handler->prefix) + strlen(name) + 1;
+ char *fullname = kmalloc_array(fullname_len, sizeof(char), GFP_KERNEL);
struct ll_sb_info *sbi = ll_i2sbi(inode);
#ifdef CONFIG_FS_POSIX_ACL
struct ll_inode_info *lli = ll_i2info(inode);
@@ -411,8 +416,12 @@ static int ll_xattr_get_common(const struct xattr_handler *handler,
return -ENODATA;
#endif
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.7.4
next reply other threads:[~2017-05-05 6:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-05 6:41 Guru Das Srinagesh [this message]
2017-05-05 8:52 ` Joe Perches
2017-05-06 20:16 ` Guru Das Srinagesh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1493966486-6143-1-git-send-email-gurooodas@gmail.com \
--to=gurooodas@gmail.com \
--cc=andreas.dilger@intel.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=john.hammond@intel.com \
--cc=jsimmons@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lustre-devel@lists.lustre.org \
--cc=oleg.drokin@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®