Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1636197 > unrolled thread
| Started by | Guru Das Srinagesh <gurooodas@gmail.com> |
|---|---|
| First post | 2017-05-05 08:50 +0200 |
| Last post | 2017-05-06 22:20 +0200 |
| Articles | 3 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH] staging: lustre: llite: Fix variable length array warning Guru Das Srinagesh <gurooodas@gmail.com> - 2017-05-05 08:50 +0200
Re: [PATCH] staging: lustre: llite: Fix variable length array warning Joe Perches <joe@perches.com> - 2017-05-05 11:00 +0200
Re: [PATCH] staging: lustre: llite: Fix variable length array warning Guru Das Srinagesh <gurooodas@gmail.com> - 2017-05-06 22:20 +0200
| From | Guru Das Srinagesh <gurooodas@gmail.com> |
|---|---|
| Date | 2017-05-05 08:50 +0200 |
| Subject | [PATCH] staging: lustre: llite: Fix variable length array warning |
| Message-ID | <tDFdU-6v3-9@gated-at.bofh.it> |
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
[toc] | [next] | [standalone]
| From | Joe Perches <joe@perches.com> |
|---|---|
| Date | 2017-05-05 11:00 +0200 |
| Subject | Re: [PATCH] staging: lustre: llite: Fix variable length array warning |
| Message-ID | <tDHfH-7Oz-1@gated-at.bofh.it> |
| In reply to | #1636197 |
On Thu, 2017-05-04 at 23:41 -0700, Guru Das Srinagesh wrote:
> 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.
[]
> diff --git 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);
What happens when this allocation fails?
[toc] | [prev] | [next] | [standalone]
| From | Guru Das Srinagesh <gurooodas@gmail.com> |
|---|---|
| Date | 2017-05-06 22:20 +0200 |
| Message-ID | <tEelj-4b5-3@gated-at.bofh.it> |
| In reply to | #1636253 |
On Fri, May 05, 2017 at 01:52:36AM -0700, Joe Perches wrote:
> On Thu, 2017-05-04 at 23:41 -0700, Guru Das Srinagesh wrote:
> > 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.
> []
> > diff --git 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);
>
> What happens when this allocation fails?
>
Thanks for rightly pointing out the omission of kmalloc_array failure case
handling code. I could check for fullname being NULL and then return -ENOMEM
right there in both functions. I'll go ahead and send a v2 of this patch, with
this modification incorporated, unless there are any more comments or concerns.
Could you please let me know? Thank you.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web