linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xattr: NULL initialize name in simple_xattr_alloc
@ 2020-03-09 18:37 Daniel Xu
  2020-03-09 19:30 ` Joe Perches
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Xu @ 2020-03-09 18:37 UTC (permalink / raw)
  To: viro, linux-fsdevel, linux-kernel; +Cc: Daniel Xu, joe, kernel-team

It's preferable to initialize structs to a deterministic state.

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
---
 fs/xattr.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/xattr.c b/fs/xattr.c
index 90dd78f0eb27..92b324c265d2 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -821,6 +821,7 @@ struct simple_xattr *simple_xattr_alloc(const void *value, size_t size)
 	if (!new_xattr)
 		return NULL;
 
+	new_xattr->name = NULL;
 	new_xattr->size = size;
 	memcpy(new_xattr->value, value, size);
 	return new_xattr;
-- 
2.21.1


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

* Re: [PATCH] xattr: NULL initialize name in simple_xattr_alloc
  2020-03-09 18:37 [PATCH] xattr: NULL initialize name in simple_xattr_alloc Daniel Xu
@ 2020-03-09 19:30 ` Joe Perches
  2020-03-09 22:31   ` Al Viro
  0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2020-03-09 19:30 UTC (permalink / raw)
  To: Daniel Xu, viro, linux-fsdevel, linux-kernel; +Cc: kernel-team

On Mon, 2020-03-09 at 11:37 -0700, Daniel Xu wrote:
> It's preferable to initialize structs to a deterministic state.

Thanks Daniel.

> Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
> ---
>  fs/xattr.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/fs/xattr.c b/fs/xattr.c
> index 90dd78f0eb27..92b324c265d2 100644
> --- a/fs/xattr.c
> +++ b/fs/xattr.c
> @@ -821,6 +821,7 @@ struct simple_xattr *simple_xattr_alloc(const void *value, size_t size)
>  	if (!new_xattr)
>  		return NULL;
>  
> +	new_xattr->name = NULL;
>  	new_xattr->size = size;
>  	memcpy(new_xattr->value, value, size);
>  	return new_xattr;


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

* Re: [PATCH] xattr: NULL initialize name in simple_xattr_alloc
  2020-03-09 19:30 ` Joe Perches
@ 2020-03-09 22:31   ` Al Viro
  0 siblings, 0 replies; 3+ messages in thread
From: Al Viro @ 2020-03-09 22:31 UTC (permalink / raw)
  To: Joe Perches; +Cc: Daniel Xu, linux-fsdevel, linux-kernel, kernel-team

On Mon, Mar 09, 2020 at 12:30:07PM -0700, Joe Perches wrote:
> On Mon, 2020-03-09 at 11:37 -0700, Daniel Xu wrote:
> > It's preferable to initialize structs to a deterministic state.
> 
> Thanks Daniel.

Not much point, TBH - there are only two callers, both assigning
that field very shortly.  If you want to do it, do it right -
make that
	simple_xattr_alloc(name, value, len)
with kfree(name) done on failure.  And make the callers allocate
the name first.  Simpler cleanup rules on failure exits that
way...

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

end of thread, other threads:[~2020-03-09 22:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-09 18:37 [PATCH] xattr: NULL initialize name in simple_xattr_alloc Daniel Xu
2020-03-09 19:30 ` Joe Perches
2020-03-09 22:31   ` Al Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).