All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] staging: lustre: llite: Fix variable length array warning
@ 2017-05-07  9:23 ` Guru Das Srinagesh
  0 siblings, 0 replies; 6+ messages in thread
From: Guru Das Srinagesh @ 2017-05-07  9:23 UTC (permalink / raw)
  To: oleg.drokin, joe, andreas.dilger, jsimmons, gregkh
  Cc: lustre-devel, devel, linux-kernel

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>
---
 v2:
   - Added missing check for NULL return value of kmalloc_array()

 drivers/staging/lustre/lustre/llite/xattr.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/lustre/lustre/llite/xattr.c b/drivers/staging/lustre/lustre/llite/xattr.c
index 6187bff..880eee9 100644
--- a/drivers/staging/lustre/lustre/llite/xattr.c
+++ b/drivers/staging/lustre/lustre/llite/xattr.c
@@ -86,13 +86,17 @@ 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;
 	__u64 valid;
 	int rc;
 
+	if (fullname == NULL)
+		return -ENOMEM;
+
 	if (flags == XATTR_REPLACE) {
 		ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_REMOVEXATTR, 1);
 		valid = OBD_MD_FLXATTRRM;
@@ -153,6 +157,9 @@ ll_xattr_set_common(const struct xattr_handler *handler,
 	}
 
 	ptlrpc_req_finished(req);
+
+	kfree(fullname);
+
 	return 0;
 }
 
@@ -363,13 +370,17 @@ 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);
 #endif
 	int rc;
 
+	if (fullname == NULL)
+		return -ENOMEM;
+
 	CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
 	       PFID(ll_inode2fid(inode)), inode);
 
@@ -411,8 +422,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

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

* [lustre-devel] [PATCH v2] staging: lustre: llite: Fix variable length array warning
@ 2017-05-07  9:23 ` Guru Das Srinagesh
  0 siblings, 0 replies; 6+ messages in thread
From: Guru Das Srinagesh @ 2017-05-07  9:23 UTC (permalink / raw)
  To: oleg.drokin, joe, andreas.dilger, jsimmons, gregkh
  Cc: lustre-devel, devel, linux-kernel

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>
---
 v2:
   - Added missing check for NULL return value of kmalloc_array()

 drivers/staging/lustre/lustre/llite/xattr.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/lustre/lustre/llite/xattr.c b/drivers/staging/lustre/lustre/llite/xattr.c
index 6187bff..880eee9 100644
--- a/drivers/staging/lustre/lustre/llite/xattr.c
+++ b/drivers/staging/lustre/lustre/llite/xattr.c
@@ -86,13 +86,17 @@ 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;
 	__u64 valid;
 	int rc;
 
+	if (fullname == NULL)
+		return -ENOMEM;
+
 	if (flags == XATTR_REPLACE) {
 		ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_REMOVEXATTR, 1);
 		valid = OBD_MD_FLXATTRRM;
@@ -153,6 +157,9 @@ ll_xattr_set_common(const struct xattr_handler *handler,
 	}
 
 	ptlrpc_req_finished(req);
+
+	kfree(fullname);
+
 	return 0;
 }
 
@@ -363,13 +370,17 @@ 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);
 #endif
 	int rc;
 
+	if (fullname == NULL)
+		return -ENOMEM;
+
 	CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
 	       PFID(ll_inode2fid(inode)), inode);
 
@@ -411,8 +422,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

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

* Re: [PATCH v2] staging: lustre: llite: Fix variable length array warning
  2017-05-07  9:23 ` [lustre-devel] " Guru Das Srinagesh
@ 2017-05-07 23:24   ` Joe Perches
  -1 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2017-05-07 23:24 UTC (permalink / raw)
  To: Guru Das Srinagesh, oleg.drokin, andreas.dilger, jsimmons, gregkh
  Cc: lustre-devel, devel, linux-kernel

On Sun, 2017-05-07 at 02:23 -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,13 +86,17 @@ 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);

Are you sure about using GFP_KERNEL and that sleeping is
allowed for this function allocation?

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

* [lustre-devel] [PATCH v2] staging: lustre: llite: Fix variable length array warning
@ 2017-05-07 23:24   ` Joe Perches
  0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2017-05-07 23:24 UTC (permalink / raw)
  To: Guru Das Srinagesh, oleg.drokin, andreas.dilger, jsimmons, gregkh
  Cc: lustre-devel, devel, linux-kernel

On Sun, 2017-05-07 at 02:23 -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,13 +86,17 @@ 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);

Are you sure about using GFP_KERNEL and that sleeping is
allowed for this function allocation?

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

* Re: [PATCH v2] staging: lustre: llite: Fix variable length array warning
  2017-05-07 23:24   ` [lustre-devel] " Joe Perches
@ 2017-05-07 23:59     ` Guru Das Srinagesh
  -1 siblings, 0 replies; 6+ messages in thread
From: Guru Das Srinagesh @ 2017-05-07 23:59 UTC (permalink / raw)
  To: Joe Perches
  Cc: oleg.drokin, andreas.dilger, jsimmons, gregkh, lustre-devel,
	devel, linux-kernel

On Sun, May 07, 2017 at 04:24:51PM -0700, Joe Perches wrote:
> On Sun, 2017-05-07 at 02:23 -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,13 +86,17 @@ 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);
> 
> Are you sure about using GFP_KERNEL and that sleeping is
> allowed for this function allocation?
> 
I'm not sure about that. Would GFP_ATOMIC be a better flag to use?

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

* [lustre-devel] [PATCH v2] staging: lustre: llite: Fix variable length array warning
@ 2017-05-07 23:59     ` Guru Das Srinagesh
  0 siblings, 0 replies; 6+ messages in thread
From: Guru Das Srinagesh @ 2017-05-07 23:59 UTC (permalink / raw)
  To: Joe Perches
  Cc: oleg.drokin, andreas.dilger, jsimmons, gregkh, lustre-devel,
	devel, linux-kernel

On Sun, May 07, 2017 at 04:24:51PM -0700, Joe Perches wrote:
> On Sun, 2017-05-07 at 02:23 -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,13 +86,17 @@ 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);
> 
> Are you sure about using GFP_KERNEL and that sleeping is
> allowed for this function allocation?
> 
I'm not sure about that. Would GFP_ATOMIC be a better flag to use?

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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-07  9:23 [PATCH v2] staging: lustre: llite: Fix variable length array warning Guru Das Srinagesh
2017-05-07  9:23 ` [lustre-devel] " Guru Das Srinagesh
2017-05-07 23:24 ` Joe Perches
2017-05-07 23:24   ` [lustre-devel] " Joe Perches
2017-05-07 23:59   ` Guru Das Srinagesh
2017-05-07 23:59     ` [lustre-devel] " Guru Das Srinagesh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.