[02/16] mem/page-pipe: create_page_pipe -- Drop redundant zero assignment

Submitted by Cyrill Gorcunov on July 5, 2019, 3:37 p.m.

Details

Message ID 20190705153811.22652-3-gorcunov@gmail.com
State Accepted
Series "mem: Cleanup and fixups"
Headers show

Commit Message

Cyrill Gorcunov July 5, 2019, 3:37 p.m.
We allocate with xzalloc, no need for additional zero assignemtns.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
 criu/page-pipe.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/page-pipe.c b/criu/page-pipe.c
index 33741db4224f..32be2f9812e2 100644
--- a/criu/page-pipe.c
+++ b/criu/page-pipe.c
@@ -187,26 +187,18 @@  struct page_pipe *create_page_pipe(unsigned int nr_segs, struct iovec *iovs, uns
 	if (!pp)
 		return NULL;
 
+	INIT_LIST_HEAD(&pp->free_bufs);
+	INIT_LIST_HEAD(&pp->bufs);
+	pp->nr_iovs = nr_segs;
 	pp->flags = flags;
 
 	if (!iovs) {
 		iovs = xmalloc(sizeof(*iovs) * nr_segs);
 		if (!iovs)
 			goto err_free_pp;
-
 		pp->flags |= PP_OWN_IOVS;
 	}
-
-	pp->nr_pipes = 0;
-	INIT_LIST_HEAD(&pp->bufs);
-	INIT_LIST_HEAD(&pp->free_bufs);
-	pp->nr_iovs = nr_segs;
 	pp->iovs = iovs;
-	pp->free_iov = 0;
-
-	pp->nr_holes = 0;
-	pp->free_hole = 0;
-	pp->holes = NULL;
 
 	if (page_pipe_grow(pp, 0))
 		goto err_free_iovs;

Comments

Mike Rapoport July 8, 2019, 12:31 p.m.
On Fri, Jul 05, 2019 at 06:37:57PM +0300, Cyrill Gorcunov wrote:
> We allocate with xzalloc, no need for additional zero assignemtns.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
> ---
>  criu/page-pipe.c | 14 +++-----------
>  1 file changed, 3 insertions(+), 11 deletions(-)
> 
> diff --git a/criu/page-pipe.c b/criu/page-pipe.c
> index 33741db4224f..32be2f9812e2 100644
> --- a/criu/page-pipe.c
> +++ b/criu/page-pipe.c
> @@ -187,26 +187,18 @@ struct page_pipe *create_page_pipe(unsigned int nr_segs, struct iovec *iovs, uns
>  	if (!pp)
>  		return NULL;
>  
> +	INIT_LIST_HEAD(&pp->free_bufs);
> +	INIT_LIST_HEAD(&pp->bufs);
> +	pp->nr_iovs = nr_segs;

Why move these before iovs allocation?
I'd rather only kill zero assignments and keep the rest. Would make the
diffstat smaller ;-)

>  	pp->flags = flags;
>  
>  	if (!iovs) {
>  		iovs = xmalloc(sizeof(*iovs) * nr_segs);
>  		if (!iovs)
>  			goto err_free_pp;
> -
>  		pp->flags |= PP_OWN_IOVS;
>  	}
> -
> -	pp->nr_pipes = 0;
> -	INIT_LIST_HEAD(&pp->bufs);
> -	INIT_LIST_HEAD(&pp->free_bufs);
> -	pp->nr_iovs = nr_segs;
>  	pp->iovs = iovs;
> -	pp->free_iov = 0;
> -
> -	pp->nr_holes = 0;
> -	pp->free_hole = 0;
> -	pp->holes = NULL;
>  
>  	if (page_pipe_grow(pp, 0))
>  		goto err_free_iovs;
> -- 
> 2.20.1
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
>
Cyrill Gorcunov July 8, 2019, 12:54 p.m.
On Mon, Jul 08, 2019 at 03:31:39PM +0300, Mike Rapoport wrote:
> On Fri, Jul 05, 2019 at 06:37:57PM +0300, Cyrill Gorcunov wrote:
> > We allocate with xzalloc, no need for additional zero assignemtns.
> > 
> > Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
> > ---
> >  criu/page-pipe.c | 14 +++-----------
> >  1 file changed, 3 insertions(+), 11 deletions(-)
> > 
> > diff --git a/criu/page-pipe.c b/criu/page-pipe.c
> > index 33741db4224f..32be2f9812e2 100644
> > --- a/criu/page-pipe.c
> > +++ b/criu/page-pipe.c
> > @@ -187,26 +187,18 @@ struct page_pipe *create_page_pipe(unsigned int nr_segs, struct iovec *iovs, uns
> >  	if (!pp)
> >  		return NULL;
> >  
> > +	INIT_LIST_HEAD(&pp->free_bufs);
> > +	INIT_LIST_HEAD(&pp->bufs);
> > +	pp->nr_iovs = nr_segs;
> 
> Why move these before iovs allocation?
> I'd rather only kill zero assignments and keep the rest. Would make the
> diffstat smaller ;-)

Just a habbit. Prefer to have everything init'ed first then proceed :)