[CRIU] [PATCH] bfd: Use ERR_PTR and such instead of BREADERR

Andrew Vagin avagin at parallels.com
Wed Oct 1 01:45:04 PDT 2014


Acked-by: Andrew Vagin <avagin at parallels.com>

On Wed, Oct 01, 2014 at 11:21:48AM +0400, Cyrill Gorcunov wrote:
> No need to invent new error codes here, simply
> use ERR_PTR/IS_ERR_OR_NULL and such.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  bfd.c         |  3 ++-
>  include/bfd.h |  4 +++-
>  proc_parse.c  | 12 +++++++-----
>  3 files changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/bfd.c b/bfd.c
> index a45eb97297a3..d7fa16c68c39 100644
> --- a/bfd.c
> +++ b/bfd.c
> @@ -5,6 +5,7 @@
>  #include <sys/mman.h>
>  #include <fcntl.h>
>  #include <sys/uio.h>
> +#include <errno.h>
>  
>  #include "bug.h"
>  #include "log.h"
> @@ -200,7 +201,7 @@ again:
>  
>  	/* no full line in the buffer -- refill one */
>  	if (brefill(f) < 0)
> -		return BREADERR;
> +		return ERR_PTR(-EIO);
>  
>  	refilled = true;
>  
> diff --git a/include/bfd.h b/include/bfd.h
> index 080045594012..f40ae5f90c12 100644
> --- a/include/bfd.h
> +++ b/include/bfd.h
> @@ -1,5 +1,8 @@
>  #ifndef __CR_BFD_H__
>  #define __CR_BFD_H__
> +
> +#include "err.h"
> +
>  struct bfd_buf;
>  struct xbuf {
>  	char *mem;		/* buffer */
> @@ -23,7 +26,6 @@ static inline void bfd_setraw(struct bfd *b)
>  	b->b.mem = NULL;
>  }
>  
> -#define BREADERR	((char *)-1)
>  int bfdopen(struct bfd *f);
>  void bclose(struct bfd *f);
>  char *breadline(struct bfd *f);
> diff --git a/proc_parse.c b/proc_parse.c
> index d63d67755249..3a2747fa468a 100644
> --- a/proc_parse.c
> +++ b/proc_parse.c
> @@ -1106,19 +1106,19 @@ static int parse_timerfd(struct bfd *f, char *str, TimerfdEntry *tfy)
>  		goto parse_err;
>  
>  	str = breadline(f);
> -	if (str == NULL || str == BREADERR)
> +	if (IS_ERR_OR_NULL(str))
>  		goto nodata;
>  	if (sscanf(str, "ticks: %llu", (unsigned long long *)&tfy->ticks) != 1)
>  		goto parse_err;
>  
>  	str = breadline(f);
> -	if (str == NULL || str == BREADERR)
> +	if (IS_ERR_OR_NULL(str))
>  		goto nodata;
>  	if (sscanf(str, "settime flags: 0%o", &tfy->settime_flags) != 1)
>  		goto parse_err;
>  
>  	str = breadline(f);
> -	if (str == NULL || str == BREADERR)
> +	if (IS_ERR_OR_NULL(str))
>  		goto nodata;
>  	if (sscanf(str, "it_value: (%llu, %llu)",
>  		   (unsigned long long *)&tfy->vsec,
> @@ -1126,7 +1126,7 @@ static int parse_timerfd(struct bfd *f, char *str, TimerfdEntry *tfy)
>  		goto parse_err;
>  
>  	str = breadline(f);
> -	if (str == NULL || str == BREADERR)
> +	if (IS_ERR_OR_NULL(str))
>  		goto nodata;
>  	if (sscanf(str, "it_interval: (%llu, %llu)",
>  		   (unsigned long long *)&tfy->isec,
> @@ -1166,8 +1166,10 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type,
>  		str = breadline(&f);
>  		if (!str)
>  			break;
> -		if (str == BREADERR)
> +		if (IS_ERR(str))
>  			goto out;
> +		else
> +			BUG();
>  
>  		if (fdinfo_field(str, "pos") ||
>  		    fdinfo_field(str, "flags") ||
> -- 
> 1.9.3
> 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu


More information about the CRIU mailing list