staging: lustre: llite: Fix variable length array warning
PATCH 1/1 staging: lustre: llite: Fix variable length array warning
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.
--- drivers/staging/lustre/lustre/llite/xattr.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/staging/lustre/lustre/llite/xattr.c +13 -4
@@ -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)
Signature · 1 line
2.7.4
Quoted 3 lines · Guru Das Srinagesh
Fix sparse warning "warning: Variable length array is used." by using
kmalloc_arrayto allocate the required amount of memory instead and kfree to deallocate memory after use.
[]
drivers/staging/lustre/lustre/llite/xattr.c
Quoted 1 line
drivers/staging/lustre/lustre/llite/xattr.c +0
-0
[]
drivers/staging/lustre/lustre/llite/xattr.c ll_xattr_set_common(const struct xattr_handler *handler, · line 90
Quoted 7 lines
drivers/staging/lustre/lustre/llite/xattr.c +2
-1@@ -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?
Quoted 7 lines · Joe Perches
Quoted 3 lines · Guru Das Srinagesh
Fix sparse warning "warning: Variable length array is used." by using
kmalloc_arrayto allocate the required amount of memory instead and kfree to deallocate memory after use.[]
drivers/staging/lustre/lustre/llite/xattr.c
Quoted 1 line
drivers/staging/lustre/lustre/llite/xattr.c +0
-0[]
Quoted 10 lines
drivers/staging/lustre/lustre/llite/xattr.c ll_xattr_set_common(const struct xattr_handler *handler, · line 90
Quoted 7 lines
drivers/staging/lustre/lustre/llite/xattr.c +2
-1@@ -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.